class Smeagol::Views::Base
Base
class for all views.
FAQ: Why aren't layouts versioned, i.e. pulled from the git repo
like pages and posts? B/c we might want to look at content history, but that doesn't mean we want to look at it via an old layout.
Attributes
The Gollum::Page
or Gollum::File
that this view represents.
The tagged version that is being viewed.
The Gollum::Wiki
that this view represents.
Public Class Methods
Initializes a new mustache view template data object.
master - Master controller, which creates all the views. page - The individual wiki page that this view represents. version - The tagged version of the page.
Returns a new page object.
# 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
Public Instance Methods
Public: The string base path to prefix internal links.
# File lib/smeagol/views/base.rb, line 112 def base_path wiki.base_path end
Value of layout metadata setting.
# File lib/smeagol/views/base.rb, line 180 def custom_layout metadata['layout'] end
Does the metadata specify a custom layout?
# File lib/smeagol/views/base.rb, line 175 def custom_layout? metadata.key?('layout') end
Default template.
Returns [String] The template included with the Smeagol
package.
# File lib/smeagol/views/base.rb, line 215 def default_layout @default_layout ||= ( IO.read(LIBDIR + "/templates/layouts/page.mustache") ) end
# File lib/smeagol/views/base.rb, line 50 def filename file.filename end
Get the layout template for the view.
# File lib/smeagol/views/base.rb, line 169 def layout return nil if custom_layout? && !custom_layout custom_layout || standard_layout || default_layout end
Support mathjax?
# File lib/smeagol/views/base.rb, line 227 def mathjax settings.mathjax end
Embedded metadata.
TODO: Can use file.metadata in future version of Gollum
.
Returns [Hash] of metadata.
# File lib/smeagol/views/base.rb, line 241 def metadata @metadata ||= ( if md = /\<\!\-\-\-(.*?)\-{2,3}\>\s*\Z/m.match(content) YAML.load(md[1]) else {} end ) end
Page
name.
# File lib/smeagol/views/base.rb, line 55 def name file.name end
# File lib/smeagol/views/base.rb, line 222 def post? false end
List of posts.
# 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
Public: The HTML for the GitHub ribbon, if enabled. This can be set in the settings file as `ribbon`.
# 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
Generates the correct ribbon url
# 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
# File lib/smeagol/views/base.rb, line 232 def settings @master.settings end
# 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
Public: The URL of the project source code. This is set in the settings file.
# File lib/smeagol/views/base.rb, line 71 def source_url settings.source_url end
The Mustache template to use for rendering.
Returns the content of the specified template file in the wiki repository if it exists. Otherwise, it returns `nil`.
# File lib/smeagol/views/base.rb, line 188 def standard_layout name = metadata['layout'] || 'page.mustache' dir = ::File.expand_path(::File.join(wiki.path, ::File.dirname(file.path))) root = ::File.expand_path(wiki.path) home = ::File.expand_path('~') 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
Public: The tagline for the wiki. This is set in the settings file.
# File lib/smeagol/views/base.rb, line 65 def tagline settings.tagline end
Public: The Google Analytics tracking id from the settings file.
# File lib/smeagol/views/base.rb, line 76 def tracking_id settings.tracking_id end
Public: The title of the wiki. This is set in the settings file.
# File lib/smeagol/views/base.rb, line 60 def wiki_title settings.title end