#!/usr/bin/env ruby #[c] #[c]This is a very rudimentary tool to convert Code Browser files to HTML. You can download the Ruby source file at "squi.rb":squi.rb, and #[c]two auxiliary files "template.rhtml":template.rhtml and "default2.css":default2.css. #[c] #[c]Uses RedCloth for plain-text markup (it's a Textile implementation in Ruby) and ERb. #[c] #[c]To use, download squi.rb and then enter @cp squi.rb /usr/local/bin/squi@ (or whichever path you want) and @chmod a+x /usr/local/bin/squi@ (both steps as root). You should also download the example #[c]template.rhtml and look at it. A file named template.rhtml _must_ be present in the current directory for squi.rb to run. #[c] #[c]For some example output, you can run @squi squi.rb@. The output is exactly the same as the HTML page you're viewing right now. #[c] #[c]Squi is named after my friend Squirrel. Squirrel is not her real name, of course, but we sometimes call her that. #[c] #[of]extensions:$extensions (Supported Filetypes) #[c] #[c]Hash: extension => comment identifier #[c] #[c]I put @'SOME_NONSENSE_STRING'@ for extensions that I'm not going to support comments in yet. #[c] $extensions = { 'cbi' => '#', 'rb' => '#', 'rhtml' => 'SOME_NONSENSE_STRING', 'css' => 'SOME_NONSENSE_STRING', } #[cf] #[of]:class Node class Node attr_accessor :sections, :children, :filename, :parent, :name, :type def initialize(name = "", filename = nil, parent = nil) @name = name if filename == nil or filename == '' if parent == nil @filename = 'index' # This is the root element else @filename = name.scan(/./).select {|c| c =~ /[A-Za-z0-9._]/}.join end else @filename = filename.scan(/./).select {|c| c =~ /[A-Za-z0-9._]/}.join end unless parent == nil or parent.parent == nil @filename = parent.filename + '-' + @filename end @parent = parent @children = [] @sections = [] @type = :folder end def append_child(node) @children << node end def append(type, content = nil, linkto = nil) if @sections.empty? or @sections[-1].type != type or @sections[-1].one_liner_type? s = Section.new type, content, linkto @sections << s else @sections[-1].append content end end end #[cf] #[of]:class Section class Section attr_accessor :type, :content, :linkto def initialize(type, content = nil, linkto = nil) @type = type @content = content @linkto = linkto end def append(content) @content += content end def one_liner_type? type == :folder or type == :link end end #[cf] #[c] require 'rubygems' require 'redcloth' require 'erb' require 'cgi' def node_tree(filename, name, identifier = nil, parent = nil) state = :comment, new_state = nil current_node = Node.new name, identifier, parent comment_identifier = $extensions[filename[/\..*?$/][1..-1]] File.open filename, "r" do |f| f.each_line do |li| case li when /^#{comment_identifier}\[c\](.*)/ current_node.append :comment, $1 + "\n" when /^#{comment_identifier}\[of\](.*?):(.*)/ child_node = Node.new $2, $1, current_node current_node.append :folder, child_node.name, child_node.filename + '.html' current_node.append_child child_node current_node = child_node when /^#{comment_identifier}\[cf\](.*)/ current_node = current_node.parent when /^#{comment_identifier}\[l\](.*?):(.*?):(.*)/ child_node = node_tree $3, $2, $1, current_node child_node.type = :link current_node.append_child child_node current_node.append :link, child_node.name, child_node.filename + '.html' else current_node.append :code, li end end end current_node end root = node_tree ARGV[0], ARGV[0] # Write the stuff to files def write_node(node, root_node, template) File.open node.filename + '.html', 'w' do |f| root_node = root_node current_node = node f.puts template.result(binding) end node.children.each{|n| write_node(n, root_node, template)} end template = "" File.open "template.rhtml", "r" do |f| template = f.read end write_node root, root, ERB.new(template) #[c] #[l]:template.rhtml:template.rhtml #[l]:default2.css:default2.css