squi.rb

squi.rb

This application is distributed under the GPL.

Send all comments or suggestions to jonathantan86@hotmail.com.

This is version 0.11 (Mar 14, 2006).
Older versions: 0.1

 #!/usr/bin/env ruby

This is a very rudimentary tool to convert Code Browser files to HTML. You can download the Ruby source file at squi.rb, and two auxiliary files template.rhtml and default2.css.

Uses RedCloth for plain-text markup (it’s a Textile implementation in Ruby) and ERb.

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 template.rhtml and look at it. A file named template.rhtml must be present in the current directory for squi.rb to run.

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.

Squi is named after my friend Squirrel. Squirrel is not her real name, of course, but we sometimes call her that.

 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)