module NoraMark module Html class Context attr_accessor :title, :head_inserters, :lang, :stylesheets, :enable_pgroup, :render_parameter, :namespaces, :metas def initialize(param = {}) @default_param = param @head_inserters = [] @lang = param[:lang] || 'en' @title = param[:title] || 'NoraMark generated document' @stylesheets = param[:stylesheets] || [] @enable_pgroup = param[:enable_pgroup] || true self.paragraph_style= param[:paragraph_style] @pages = Pages.new(param[:sequence_format]) @metas = param[:metas] || [] @namespaces = {} @render_parameter = {} head_inserter do ret = "" @stylesheets.each do |s| if s.is_a? String ret << "\n" elsif s.is_a? Array ret << "\n" else raise "Can't use #{s} as a stylesheet" end end ret << @metas.map do |meta| "" end.join("\n") ret end end def file_basename=(name) @pages.file_basename = name end def chop_last_space @pages.last.sub!(/[[:space:]]+\Z/, '') end def paragraph_style=(style) return if style.nil? raise "paragrapy_style accepts only :default or :use_paragraph_group but is #{style}" if style != :default && style != :use_paragraph_group @paragraph_style = style end def paragraph_style if @paragraph_style @paragraph_style elsif @lang.split('-')[0] == 'ja' :use_paragraph_group else :default end end def head_inserter(&block) head_inserters << block end def start_html(title = nil) @title = title if !title.nil? if @pages.size >0 && !@pages.last.frozen? end_html end page = "\n" page << "\n" page << "
\n" page << "