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 9 def initialize(document, style_path = ENV['RONN_STYLE'].to_s.split(':')) 10 @document = document 11 @style_path = style_path + [Template.template_path] 12 end
Public Instance Methods
custom_title?()
click to toggle source
# File lib/ronn/template.rb 46 def custom_title? 47 !name_and_section? && tagline 48 end
date()
click to toggle source
# File lib/ronn/template.rb 70 def date 71 @document.date.strftime('%B %Y') 72 end
generator()
click to toggle source
# File lib/ronn/template.rb 58 def generator 59 "Ronn-NG/v#{Ronn.version} (http://github.com/apjanke/ronn-ng/tree/#{Ronn.revision})" 60 end
inline_stylesheet(path, media = 'all')
click to toggle source
TEMPLATE CSS LOADING
# File lib/ronn/template.rb 145 def inline_stylesheet(path, media = 'all') 146 data = File.read(path) 147 data.gsub!(%r{/\*.+?\*/}m, '') # comments 148 data.gsub!(/([;{,]) *\n/m, '\1') # end-of-line whitespace 149 data.gsub!(/\n{2,}/m, "\n") # collapse lines 150 data.gsub!(/[; ]+\}/, '}') # superfluous trailing semi-colons 151 data.gsub!(/([{;,+])[ ]+/, '\1') # whitespace around things 152 data.gsub!(/[ \t]+/m, ' ') # coalescing whitespace elsewhere 153 data.gsub!(/^/, ' ') # indent 154 data.strip! 155 [ 156 "<style type='text/css' media='#{media}'>", 157 "/* style: #{File.basename(path, '.css')} */", 158 data, 159 '</style>' 160 ].join("\n ") 161 end
manual()
click to toggle source
# File lib/ronn/template.rb 62 def manual 63 @document.manual 64 end
missing_styles()
click to toggle source
Array of style names for which no file could be found.
# File lib/ronn/template.rb 135 def missing_styles 136 style_files 137 .zip(files) 138 .select { |_style, file| file.nil? } 139 .map { |style, _file| style } 140 end
name()
click to toggle source
Basic document attributes
# File lib/ronn/template.rb 21 def name 22 @document.name 23 end
name_and_section?()
click to toggle source
# File lib/ronn/template.rb 34 def name_and_section? 35 name && section 36 end
organization()
click to toggle source
# File lib/ronn/template.rb 66 def organization 67 @document.organization 68 end
page_name()
click to toggle source
# File lib/ronn/template.rb 50 def page_name 51 if section 52 "#{name}(#{section})" 53 else 54 name 55 end 56 end
remote_stylesheet(name, media = 'all')
click to toggle source
# File lib/ronn/template.rb 163 def remote_stylesheet(name, media = 'all') 164 path = File.expand_path("../template/#{name}.css", __FILE__) 165 "<link rel='stylesheet' type='text/css' media='#{media}' href='#{path}'>" 166 end
render(template = 'default')
click to toggle source
Calls superclass method
# File lib/ronn/template.rb 14 def render(template = 'default') 15 super template[0, 1] == '/' ? File.read(template) : partial(template) 16 end
section()
click to toggle source
# File lib/ronn/template.rb 25 def section 26 @document.section 27 end
section_heads()
click to toggle source
Section TOCs
# File lib/ronn/template.rb 81 def section_heads 82 @document.section_heads.map do |id, text| 83 { 84 id: id, 85 text: text 86 } 87 end 88 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 124 def style_files 125 styles.map do |name| 126 next name if name.include?('/') 127 style_path 128 .reject { |p| p.strip.empty? } 129 .map { |p| File.join(p, "#{name}.css") } 130 .detect { |file| File.exist?(file) } 131 end 132 end
styles()
click to toggle source
Array of style module names as given on the command line.
# File lib/ronn/template.rb 94 def styles 95 @document.styles 96 end
stylesheet(_path, media = 'all')
click to toggle source
# File lib/ronn/template.rb 168 def stylesheet(_path, media = 'all') 169 inline_stylesheet(name, media) 170 end
stylesheets()
click to toggle source
Array of stylesheet info hashes.
# File lib/ronn/template.rb 99 def stylesheets 100 styles.zip(style_files).map do |name, path| 101 base = File.basename(path, '.css') 102 raise "style not found: #{style.inspect}" if path.nil? 103 { 104 name: name, 105 path: path, 106 base: File.basename(path, '.css'), 107 media: base =~ /(print|screen)$/ ? $1 : 'all' 108 } 109 end 110 end
tagline()
click to toggle source
# File lib/ronn/template.rb 29 def tagline 30 @document.tagline 31 end
Also aliased as: tagline?
title()
click to toggle source
# File lib/ronn/template.rb 38 def title 39 if !name_and_section? && tagline 40 tagline 41 else 42 [page_name, tagline].compact.join(' - ') 43 end 44 end
wrap_class_name()
click to toggle source
# File lib/ronn/template.rb 74 def wrap_class_name 75 'mp' 76 end