class PseudoHiki::PageComposer
Constants
- HEADING_WITH_ID_PAT
- PlainFormat
Public Class Methods
new(options)
click to toggle source
# File lib/pseudohiki/converter.rb, line 175 def initialize(options) @options = options @composer = select_composer.new(options) end
Public Instance Methods
choose_template(main, body, current_binding)
click to toggle source
# File lib/pseudohiki/converter.rb, line 209 def choose_template(main, body, current_binding) if @options[:template] html = ERB.new(@options.read_template_file).result(current_binding) else html = @options.create_html_template_with_current_options embed_css = @options[:embed_css] html.embed_style(File.read(File.expand_path(embed_css))) if embed_css html.push main || body html.add_skip_link if html.kind_of?(HtmlTemplate) and main end html end
compose_html(input_lines)
click to toggle source
# File lib/pseudohiki/converter.rb, line 198 def compose_html(input_lines) h1 = split_main_heading(input_lines) css = @options[:css] tree = BlockParser.parse(input_lines) toc = create_table_of_contents(tree) body = @composer.compose_body(tree) title = @options.title main = @composer.create_main(toc, body, h1) choose_template(main, body, binding) end
create_table_of_contents(tree)
click to toggle source
# File lib/pseudohiki/converter.rb, line 185 def create_table_of_contents(tree) return "" unless @options[:toc] @composer.create_table_of_contents(tree) end
select_composer()
click to toggle source
# File lib/pseudohiki/converter.rb, line 180 def select_composer return GfmComposer if @options[:html_version].version == "gfm" @options.html_template ? HtmlComposer : PlainComposer end
split_main_heading(input_lines)
click to toggle source
# File lib/pseudohiki/converter.rb, line 190 def split_main_heading(input_lines) return "" unless @options[:split_main_heading] h1_pos = input_lines.find_index {|line| /^![^!]/o.match? line } return "" unless h1_pos tree = BlockParser.parse([input_lines.delete_at(h1_pos)]) @options.formatter.format(tree) end