squi.rbThis application is distributed under the GPL. Send all comments or suggestions to jonathantan86@hotmail.com.
This is version 0.11 (Mar 14, 2006). |
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
|