class M2H::Render::Document

Attributes

html_body[RW]

Public Class Methods

new(html_body) click to toggle source
# File lib/m2h/render.rb, line 9
def initialize(html_body)
  @erb_template = File.open(File.dirname(__FILE__) + "/_layout.erb").read
  @html         = generate_html(html_body)
  @header       = false
end

Public Instance Methods

bind!() click to toggle source
# File lib/m2h/render.rb, line 30
def bind!
  return ERB.new(@erb_template).result(binding)
end
generate_html(html_body) click to toggle source
# File lib/m2h/render.rb, line 15
def generate_html(html_body)
  @title      = $1 if /h1>(.+)\<\/h1./ =~ html_body
  @pages      = html_body.split(/\/{4,}/) # page_break
  @page_count = @pages.size
  html = @pages.map.with_index { |page, i|
    unless (i + 1) == @page_count
      "<div class='page_number'>#{i+1}/#{@page_count}</div>\n" + page + "\n<div class='break'/>\n"
    else
      "<div class='page_number'>#{i+1}/#{@page_count}</div>\n" + page
    end
  }.join
  html.gsub!(/page_number'>/, "page_number'>#{@title}&nbsp;")
  return html
end
set_cover() click to toggle source
# File lib/m2h/render.rb, line 46
def set_cover
  cover = "\n<div class='cover'><h1>#{@title}</h1></div>\n"
  cover += "<div class='break'/>\n"
  @cover = cover
end
set_header() click to toggle source
# File lib/m2h/render.rb, line 34
def set_header
  @header = true
end
set_serif() click to toggle source
# File lib/m2h/render.rb, line 42
def set_serif
  @serif = "serif, "
end
set_toc() click to toggle source
# File lib/m2h/render.rb, line 52
def set_toc
  @toc = true
end
write(path, enc) click to toggle source
# File lib/m2h/render.rb, line 38
def write(path, enc)
  File.open(path, enc).write(self.bind!)
end