class Ronn::Template
A Mustache Template for HTML formatting.
Attributes
style_path[RW]
Public Class Methods
new(document, style_path = ENV['RONN_STYLE'].to_s.split(':'))
click to toggle source
# File lib/ronn/template.rb, line 9 def initialize(document, style_path = ENV['RONN_STYLE'].to_s.split(':')) @document = document @style_path = style_path + [Template.template_path] end
Public Instance Methods
custom_title?()
click to toggle source
# File lib/ronn/template.rb, line 46 def custom_title? !name_and_section? && tagline end
date()
click to toggle source
# File lib/ronn/template.rb, line 70 def date @document.date.strftime('%B %Y') end
generator()
click to toggle source
# File lib/ronn/template.rb, line 58 def generator "Ronn-NG/v#{Ronn.version} (http://github.com/apjanke/ronn-ng/tree/#{Ronn.revision})" end
inline_stylesheet(path, media = 'all')
click to toggle source
TEMPLATE CSS LOADING
# File lib/ronn/template.rb, line 145 def inline_stylesheet(path, media = 'all') data = File.read(path) data.gsub!(%r{/\*.+?\*/}m, '') # comments data.gsub!(/([;{,]) *\n/m, '\1') # end-of-line whitespace data.gsub!(/\n{2,}/m, "\n") # collapse lines data.gsub!(/[; ]+\}/, '}') # superfluous trailing semi-colons data.gsub!(/([{;,+])[ ]+/, '\1') # whitespace around things data.gsub!(/[ \t]+/m, ' ') # coalescing whitespace elsewhere data.gsub!(/^/, ' ') # indent data.strip! [ "<style type='text/css' media='#{media}'>", "/* style: #{File.basename(path, '.css')} */", data, '</style>' ].join("\n ") end
manual()
click to toggle source
# File lib/ronn/template.rb, line 62 def manual @document.manual end
missing_styles()
click to toggle source
Array of style names for which no file could be found.
# File lib/ronn/template.rb, line 135 def missing_styles style_files .zip(files) .select { |_style, file| file.nil? } .map { |style, _file| style } end
name()
click to toggle source
Basic document attributes
# File lib/ronn/template.rb, line 21 def name @document.name end
name_and_section?()
click to toggle source
# File lib/ronn/template.rb, line 34 def name_and_section? name && section end
organization()
click to toggle source
# File lib/ronn/template.rb, line 66 def organization @document.organization end
page_name()
click to toggle source
# File lib/ronn/template.rb, line 50 def page_name if section "#{name}(#{section})" else name end end
remote_stylesheet(name, media = 'all')
click to toggle source
# File lib/ronn/template.rb, line 163 def remote_stylesheet(name, media = 'all') path = File.expand_path("../template/#{name}.css", __FILE__) "<link rel='stylesheet' type='text/css' media='#{media}' href='#{path}'>" end
render(template = 'default')
click to toggle source
Calls superclass method
# File lib/ronn/template.rb, line 14 def render(template = 'default') super template[0, 1] == '/' ? File.read(template) : partial(template) end
section()
click to toggle source
# File lib/ronn/template.rb, line 25 def section @document.section end
section_heads()
click to toggle source
Section TOCs
# File lib/ronn/template.rb, line 81 def section_heads @document.section_heads.map do |id, text| { id: id, text: text } end end
style_files()
click to toggle source
Array of expanded stylesheet file names. If a file cannot be found, the resulting array will include nil elements in positions corresponding to the stylesheets array.
# File lib/ronn/template.rb, line 124 def style_files styles.map do |name| next name if name.include?('/') style_path .reject { |p| p.strip.empty? } .map { |p| File.join(p, "#{name}.css") } .detect { |file| File.exist?(file) } end end
styles()
click to toggle source
Array of style module names as given on the command line.
# File lib/ronn/template.rb, line 94 def styles @document.styles end
stylesheet(_path, media = 'all')
click to toggle source
# File lib/ronn/template.rb, line 168 def stylesheet(_path, media = 'all') inline_stylesheet(name, media) end
stylesheets()
click to toggle source
Array of stylesheet info hashes.
# File lib/ronn/template.rb, line 99 def stylesheets styles.zip(style_files).map do |name, path| base = File.basename(path, '.css') raise "style not found: #{style.inspect}" if path.nil? { name: name, path: path, base: File.basename(path, '.css'), media: base =~ /(print|screen)$/ ? $1 : 'all' } end end
tagline()
click to toggle source
# File lib/ronn/template.rb, line 29 def tagline @document.tagline end
Also aliased as: tagline?
title()
click to toggle source
# File lib/ronn/template.rb, line 38 def title if !name_and_section? && tagline tagline else [page_name, tagline].compact.join(' - ') end end
wrap_class_name()
click to toggle source
# File lib/ronn/template.rb, line 74 def wrap_class_name 'mp' end