* Filter _Template content. Resolves #1603 and #1640. * Introduces a Gollum::TemplateFilter class with methods to easily add _Template Filters. * Adds support for relative _Template pages with fallback to _Template in root.
This commit is contained in:
+1
-1
@@ -152,7 +152,7 @@ MSG
|
||||
opts.on('--template-dir [PATH]', 'Specify custom mustache template directory.') do |path|
|
||||
wiki_options[:template_dir] = path
|
||||
end
|
||||
opts.on('--template-page', 'Use _Template in root as a template for new pages.') do
|
||||
opts.on('--template-page', 'Use _Template.{ext} as a template for new pages.') do
|
||||
wiki_options[:template_page] = true
|
||||
end
|
||||
opts.on('--lenient-tag-lookup', 'Internal links resolve case-insensitively, will treat spaces as hyphens, and will match the first page found with a certain filename, anywhere in the repository. Provides compatibility with Gollum 4.x.') do
|
||||
|
||||
@@ -33,4 +33,20 @@ module Gollum
|
||||
super(message || "Cannot write #{@dir}/#{@attempted_path}, found #{@dir}/#{@existing_path}.")
|
||||
end
|
||||
end
|
||||
|
||||
class TemplateFilter
|
||||
@@filters = {}
|
||||
|
||||
def self.add_filter(pattern, &replacement)
|
||||
@@filters[pattern] = replacement
|
||||
end
|
||||
|
||||
def self.apply_filters(data)
|
||||
@@filters.each do |pattern, replacement|
|
||||
data.gsub!(pattern, replacement.call)
|
||||
end
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+6
-4
@@ -351,14 +351,11 @@ module Precious
|
||||
|
||||
get '/create/*' do
|
||||
forbid unless @allow_editing
|
||||
if settings.wiki_options[:template_page] then
|
||||
temppage = wiki_page('/_Template')
|
||||
@template_page = (temppage.page != nil) ? temppage.page.raw_data : 'Template page option is set, but no /_Template page is present or committed.'
|
||||
end
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = wikip.name
|
||||
@ext = wikip.ext
|
||||
@path = wikip.path
|
||||
@template_page = load_template(@path) if settings.wiki_options[:template_page]
|
||||
@allow_uploads = wikip.wiki.allow_uploads
|
||||
@upload_dest = find_upload_dest(wikip.fullpath)
|
||||
|
||||
@@ -638,6 +635,11 @@ module Precious
|
||||
end
|
||||
end
|
||||
|
||||
def load_template(path)
|
||||
template_page = wiki_page(::File.join(path, '_Template')).page || wiki_page('/_Template').page
|
||||
template_page ? Gollum::TemplateFilter.apply_filters(template_page.raw_data) : nil
|
||||
end
|
||||
|
||||
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
|
||||
return if !page ||
|
||||
((!content || page.raw_data == content) && page.format == format)
|
||||
|
||||
Reference in New Issue
Block a user