Allow for overriding only specific Mustache templates/partials. (#1719)
* Allow for overriding only specific templates/partials. Resolves #1450.
This commit is contained in:
+6
-1
@@ -22,6 +22,7 @@ require 'gollum/views/has_page'
|
||||
require 'gollum/views/has_user_icons'
|
||||
require 'gollum/views/pagination'
|
||||
require 'gollum/views/rss.rb'
|
||||
require 'gollum/views/template_cascade'
|
||||
|
||||
require File.expand_path '../helpers', __FILE__
|
||||
|
||||
@@ -110,7 +111,11 @@ module Precious
|
||||
@wiki_title = settings.wiki_options.fetch(:title, 'Gollum Wiki')
|
||||
|
||||
forbid unless @allow_editing || request.request_method == 'GET'
|
||||
Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir]
|
||||
|
||||
if settings.wiki_options[:template_dir]
|
||||
Precious::Views::Layout.extend Precious::Views::TemplateCascade
|
||||
Precious::Views::Layout.template_priority_path = settings.wiki_options[:template_dir]
|
||||
end
|
||||
|
||||
@base_url = url('/', false).chomp('/').force_encoding('utf-8')
|
||||
@page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
module Precious
|
||||
module Views
|
||||
module TemplateCascade
|
||||
def template_priority_path
|
||||
@@template_priority_path
|
||||
end
|
||||
|
||||
def template_priority_path=(path)
|
||||
@@template_priority_path = File.expand_path(path)
|
||||
@template = nil
|
||||
end
|
||||
|
||||
def first_path_available(name)
|
||||
priority = File.join(template_priority_path, "#{name}.#{template_extension}")
|
||||
default = File.join(template_path, "#{name}.#{template_extension}")
|
||||
File.exists?(priority) ? priority : default
|
||||
end
|
||||
|
||||
# Method should track lib/mustache/settings.rb from Mustache project.
|
||||
def template_file
|
||||
@template_file || first_path_available(template_name)
|
||||
end
|
||||
|
||||
# Method should track lib/mustache.rb from Mustache project.
|
||||
def partial(name)
|
||||
path = first_path_available(name)
|
||||
begin
|
||||
File.read(path)
|
||||
rescue
|
||||
raise if raise_on_context_miss?
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user