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