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