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
Calls superclass method
   # 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

Public Instance Methods

custom_title?() click to toggle source
   # File lib/ronn/template.rb
47 def custom_title?
48   !name_and_section? && tagline
49 end
date() click to toggle source
   # File lib/ronn/template.rb
71 def date
72   @document.date.strftime('%B %Y')
73 end
generator() click to toggle 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
inline_stylesheet(path, media = 'all') click to toggle source

TEMPLATE CSS LOADING

    # 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
manual() click to toggle source
   # File lib/ronn/template.rb
63 def manual
64   @document.manual
65 end
missing_styles() click to toggle source

Array of style names for which no file could be found.

    # 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
name() click to toggle source

Basic document attributes

   # File lib/ronn/template.rb
22 def name
23   @document.name
24 end
name_and_section?() click to toggle source
   # File lib/ronn/template.rb
35 def name_and_section?
36   name && section
37 end
organization() click to toggle source
   # File lib/ronn/template.rb
67 def organization
68   @document.organization
69 end
page_name() click to toggle source
   # File lib/ronn/template.rb
51 def page_name
52   if section
53     "#{name}(#{section})"
54   else
55     name
56   end
57 end
remote_stylesheet(name, media = 'all') click to toggle 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
render(template = 'default') click to toggle source
Calls superclass method
   # File lib/ronn/template.rb
15 def render(template = 'default')
16   super(template[0, 1] == '/' ? File.read(template) : partial(template))
17 end
section() click to toggle source
   # File lib/ronn/template.rb
26 def section
27   @document.section
28 end
section_heads() click to toggle source

Section TOCs

   # 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
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
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
styles() click to toggle source

Array of style module names as given on the command line.

   # File lib/ronn/template.rb
95 def styles
96   @document.styles
97 end
stylesheet(_path, media = 'all') click to toggle source
    # File lib/ronn/template.rb
169 def stylesheet(_path, media = 'all')
170   inline_stylesheet(name, media)
171 end
stylesheet_tags() click to toggle source

All embedded stylesheets.

    # File lib/ronn/template.rb
114 def stylesheet_tags
115   stylesheets
116     .map { |style| inline_stylesheet(style[:path], style[:media]) }
117     .join("\n  ")
118 end
stylesheets() click to toggle source

Array of stylesheet info hashes.

    # 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
tagline() click to toggle source
   # File lib/ronn/template.rb
30 def tagline
31   @document.tagline
32 end
Also aliased as: tagline?
tagline?()
Alias for: tagline
title() click to toggle 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
wrap_class_name() click to toggle source
   # File lib/ronn/template.rb
75 def wrap_class_name
76   'mp'
77 end