* 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|
|
opts.on('--template-dir [PATH]', 'Specify custom mustache template directory.') do |path|
|
||||||
wiki_options[:template_dir] = path
|
wiki_options[:template_dir] = path
|
||||||
end
|
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
|
wiki_options[:template_page] = true
|
||||||
end
|
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
|
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}.")
|
super(message || "Cannot write #{@dir}/#{@attempted_path}, found #{@dir}/#{@existing_path}.")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
+6
-4
@@ -351,14 +351,11 @@ module Precious
|
|||||||
|
|
||||||
get '/create/*' do
|
get '/create/*' do
|
||||||
forbid unless @allow_editing
|
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)
|
wikip = wiki_page(params[:splat].first)
|
||||||
@name = wikip.name
|
@name = wikip.name
|
||||||
@ext = wikip.ext
|
@ext = wikip.ext
|
||||||
@path = wikip.path
|
@path = wikip.path
|
||||||
|
@template_page = load_template(@path) if settings.wiki_options[:template_page]
|
||||||
@allow_uploads = wikip.wiki.allow_uploads
|
@allow_uploads = wikip.wiki.allow_uploads
|
||||||
@upload_dest = find_upload_dest(wikip.fullpath)
|
@upload_dest = find_upload_dest(wikip.fullpath)
|
||||||
|
|
||||||
@@ -638,6 +635,11 @@ module Precious
|
|||||||
end
|
end
|
||||||
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)
|
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
|
||||||
return if !page ||
|
return if !page ||
|
||||||
((!content || page.raw_data == content) && page.format == format)
|
((!content || page.raw_data == content) && page.format == format)
|
||||||
|
|||||||
Reference in New Issue
Block a user