class Eggshell::Bundles::Basics::SectionBlocks
Constants
- TOC_TEMPLATE
Public Instance Methods
collect(line, buffer, indents = '', indent_level = 0, line_count = -1)
click to toggle source
# File lib/eggshell/bundles/basics-old.rb, line 405 def collect(line, buffer, indents = '', indent_level = 0, line_count = -1) if line == '' || !line buffer << @proc.fmt_line(@toc_template[:start]) if @toc_template[:start] @header_list.each do |entry| if entry == 'section' buffer << @proc.fmt_line(@toc_template[:section]) if @toc_template[:section] elsif entry == 'section_end' buffer << @proc.fmt_line(@toc_template[:section_end]) if @toc_template[:section_end] elsif entry.is_a?(Hash) tpl = @toc_template[entry[:tag]] || @toc_template[:default] buffer << @proc.fmt_line( tpl.gsub('$id', entry[:id]).gsub('$title', entry[:title]).gsub('$level', entry[:level].to_s) ) end end buffer << @proc.fmt_line(@toc_template[:end]) if @toc_template[:end] return DONE else key, val = line.split(':', 2) @toc_template[key.to_sym] = val return COLLECT end end
set_processor(proc)
click to toggle source
# File lib/eggshell/bundles/basics-old.rb, line 350 def set_processor(proc) @proc = proc @proc.register_block(self, *%w(h1 h2 h3 h4 h5 h6 hr section end-section toc)) @header_list = [] @header_idx = {} end
start(name, line, buffer, indents = '', indent_level = 0, line_count = -1)
click to toggle source
# File lib/eggshell/bundles/basics-old.rb, line 357 def start(name, line, buffer, indents = '', indent_level = 0, line_count = -1) set_block_params(name) bp = @block_params[name] if name[0] == 'h' if name == 'hr' buffer << "<hr />" else lvl = name[1].to_i attrs = bp['attributes'] || {} attrs['class'] = bp['class'] || '' attrs['style'] = bp['style'] || '' id = bp['id'] || line.downcase.strip.gsub(/[^a-z0-9_-]+/, '-') lid = id i = 1 while @header_idx[lid] != nil lid = "#{id}-#{i}" i += 1 end id = lid attrs['id'] = id title = @proc.fmt_line(line) buffer << "#{create_tag(name, attrs)}#{title}</#{name}>" @header_list << {:level => lvl, :id => lid, :title => title, :tag => name} @header_idx[lid] = @header_list.length - 1 end return DONE elsif name == 'section' attrs = bp['attributes'] || {} attrs['class'] = bp['class'] || '' attrs['style'] = bp['style'] || '' attrs['id'] = bp['id'] || '' buffer << create_tag('section', attrs) @header_list << name return DONE elsif name == 'end-section' buffer << '</section>' @header_list << name return DONE elsif name == 'toc' @toc_template = TOC_TEMPLATE.clone return COLLECT end end