Class: Smeagol::Views::Base
- Inherits:
-
Mustache
- Object
- Mustache
- Smeagol::Views::Base
- Defined in:
- lib/smeagol/views/base.rb
Overview
Base class for all views.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
The Gollum::Page or Gollum::File that this view represents.
-
#version ⇒ Object
readonly
The tagged version that is being viewed.
-
#wiki ⇒ Object
readonly
The Gollum::Wiki that this view represents.
Instance Method Summary collapse
-
#base_path ⇒ Object
The string base path to prefix internal links.
-
#custom_layout ⇒ Object
Value of layout metadata setting.
-
#custom_layout? ⇒ Boolean
Does the metadata specify a custom layout?.
-
#default_layout ⇒ String
Default template.
- #filename ⇒ Object
-
#initialize(master, file, version = 'master') ⇒ Object
constructor
Initializes a new mustache view template data object.
-
#layout ⇒ Object
Get the layout template for the view.
-
#mathjax ⇒ Object
Support mathjax?.
-
#menu_html ⇒ Object
The HTML menu generated from the settings.yml file.
-
#metadata ⇒ Hash
Embedded metadata.
-
#name ⇒ Object
Page name.
- #post? ⇒ Boolean
-
#posts ⇒ Object
List of posts.
-
#ribbon_html ⇒ Object
The HTML for the GitHub ribbon, if enabled.
-
#ribbon_url(name, pos) ⇒ Object
Generates the correct ribbon url.
- #settings ⇒ Object
- #setup_template_path ⇒ Object
-
#source_url ⇒ Object
The URL of the project source code.
-
#standard_layout ⇒ Object
The Mustache template to use for rendering.
-
#tagline ⇒ Object
The tagline for the wiki.
-
#tracking_id ⇒ Object
The Google Analytics tracking id from the settings file.
-
#wiki_title ⇒ Object
The title of the wiki.
Constructor Details
#initialize(master, file, version = 'master') ⇒ Object
Initializes a new mustache view template data object.
20 21 22 23 24 25 26 27 |
# File 'lib/smeagol/views/base.rb', line 20 def initialize(master, file, version='master') @master = master @file = file @wiki = file.wiki @version = version || 'master' setup_template_path end |
Instance Attribute Details
#file ⇒ Object (readonly)
The Gollum::Page or Gollum::File that this view represents.
47 48 49 |
# File 'lib/smeagol/views/base.rb', line 47 def file @file end |
#version ⇒ Object (readonly)
The tagged version that is being viewed.
33 34 35 |
# File 'lib/smeagol/views/base.rb', line 33 def version @version end |
#wiki ⇒ Object (readonly)
The Gollum::Wiki that this view represents.
30 31 32 |
# File 'lib/smeagol/views/base.rb', line 30 def wiki @wiki end |
Instance Method Details
#base_path ⇒ Object
The string base path to prefix internal links.
112 113 114 |
# File 'lib/smeagol/views/base.rb', line 112 def base_path wiki.base_path end |
#custom_layout ⇒ Object
Value of layout metadata setting.
180 181 182 |
# File 'lib/smeagol/views/base.rb', line 180 def custom_layout ['layout'] end |
#custom_layout? ⇒ Boolean
Does the metadata specify a custom layout?
175 176 177 |
# File 'lib/smeagol/views/base.rb', line 175 def custom_layout? .key?('layout') end |
#default_layout ⇒ String
Default template.
215 216 217 218 219 |
# File 'lib/smeagol/views/base.rb', line 215 def default_layout @default_layout ||= ( IO.read(LIBDIR + "/templates/layouts/page.mustache") ) end |
#filename ⇒ Object
50 51 52 |
# File 'lib/smeagol/views/base.rb', line 50 def filename file.filename end |
#layout ⇒ Object
Get the layout template for the view.
169 170 171 172 |
# File 'lib/smeagol/views/base.rb', line 169 def layout return nil if custom_layout? && !custom_layout custom_layout || standard_layout || default_layout end |
#mathjax ⇒ Object
Support mathjax?
227 228 229 |
# File 'lib/smeagol/views/base.rb', line 227 def mathjax settings.mathjax end |
#menu_html ⇒ Object
The HTML menu generated from the settings.yml file.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/smeagol/views/base.rb', line 81 def = wiki.settings. if !.nil? html = "<ul>\n" .each do |item| title, href = item['title'], item['href'] if version != 'master' && item['href'].index('/') == 0 prefix = version.start_with?('v') ? "/#{version}" : "/v#{version}" else prefix = "" end html << "<li class=\"minibutton\"><a href=\"#{prefix}#{href}\">#{title}</a></li>\n" end html << "</ul>\n" end end |
#metadata ⇒ Hash
Can use file.metadata in future version of Gollum.
Embedded metadata.
241 242 243 244 245 246 247 248 249 |
# File 'lib/smeagol/views/base.rb', line 241 def @metadata ||= ( if md = /\<\!\-\-\-(.*?)\-{2,3}\>\s*\Z/m.match(content) YAML.load(md[1]) else {} end ) end |
#name ⇒ Object
Page name.
55 56 57 |
# File 'lib/smeagol/views/base.rb', line 55 def name file.name end |
#post? ⇒ Boolean
222 223 224 |
# File 'lib/smeagol/views/base.rb', line 222 def post? false end |
#posts ⇒ Object
List of posts.
117 118 119 120 121 122 123 124 |
# File 'lib/smeagol/views/base.rb', line 117 def posts @posts ||= @master.posts #@posts ||= ( # filter(@wiki.pages){ |p| p.post? }.map do |page| # Smeagol::Views::Post.new(page, @version) # end #) end |
#ribbon_html ⇒ Object
The HTML for the GitHub ribbon, if enabled. This can be set in the settings file as ‘ribbon`.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/smeagol/views/base.rb', line 100 def ribbon_html if !source_url.nil? && !wiki.settings.ribbon.nil? name, pos = *wiki.settings.ribbon.split(' ') pos ||= 'right' html = "<a href=\"#{source_url}\">" html << "<img style=\"position:absolute; top:0; #{pos}:0; border:0;\" src=\"#{ribbon_url(name, pos)}\" alt=\"Fork me on GitHub\"/>" html << "</a>" end end |
#ribbon_url(name, pos) ⇒ Object
Generates the correct ribbon url
145 146 147 148 149 150 151 152 |
# File 'lib/smeagol/views/base.rb', line 145 def ribbon_url(name, pos) hexcolors = {'red' => 'aa0000', 'green' => '007200', 'darkblue' => '121621', 'orange' => 'ff7600', 'gray' => '6d6d6d', 'white' => 'ffffff'} if hexcolor = hexcolors[name] "http://s3.amazonaws.com/github/ribbons/forkme_#{pos}_#{name}_#{hexcolor}.png" else name end end |
#settings ⇒ Object
232 233 234 |
# File 'lib/smeagol/views/base.rb', line 232 def settings @master.settings end |
#setup_template_path ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/smeagol/views/base.rb', line 36 def setup_template_path # See FAQ for Views::Base class dir = ::File.join(wiki.path, settings.partials) if ::File.directory?(dir) self.class.template_path = dir else self.class.template_path = ::File.join(LIBDIR, 'templates', 'partials') end end |
#source_url ⇒ Object
The URL of the project source code. This is set in the settings file.
71 72 73 |
# File 'lib/smeagol/views/base.rb', line 71 def source_url settings.source_url end |
#standard_layout ⇒ Object
The Mustache template to use for rendering.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/smeagol/views/base.rb', line 188 def standard_layout name = ['layout'] || 'page.mustache' dir = ::File.(::File.join(wiki.path, ::File.dirname(file.path))) root = ::File.(wiki.path) home = ::File.('~') layout = nil loop do f = ::File.join(dir, '_layouts', name) break (layout = IO.read(f)) if ::File.exist?(f) break nil if dir == root break nil if dir == home # just in case break nil if dir == '/' dir = ::File.dirname(dir) end return layout #names.each do |name| # file = "#{@wiki.path}/#{settings.layout_dir}/#{name}.mustache" # if ::File.exists?(file) # return IO.read(file) # end #end #nil end |
#tagline ⇒ Object
The tagline for the wiki. This is set in the settings file.
65 66 67 |
# File 'lib/smeagol/views/base.rb', line 65 def tagline settings.tagline end |
#tracking_id ⇒ Object
The Google Analytics tracking id from the settings file.
76 77 78 |
# File 'lib/smeagol/views/base.rb', line 76 def tracking_id settings.tracking_id end |
#wiki_title ⇒ Object
The title of the wiki. This is set in the settings file.
60 61 62 |
# File 'lib/smeagol/views/base.rb', line 60 def wiki_title settings.title end |