Add page context to template filter, resolves #1603 (#1818)

* Add a test for template filter
* Add a test for template filter with page parameter
* Passing page as a parameter to template filter
This commit is contained in:
Tevin
2022-04-25 15:44:19 +08:00
committed by GitHub
parent 3f0b61081b
commit 81c90e55a7
3 changed files with 45 additions and 5 deletions
+3 -2
View File
@@ -29,9 +29,10 @@ module Gollum
@@filters[pattern] = replacement
end
def self.apply_filters(data)
def self.apply_filters(wiki_page, data)
@@filters.each do |pattern, replacement|
data.gsub!(pattern, replacement.call)
params = replacement.parameters.length == 0 ? nil : wiki_page
data.gsub!(pattern, replacement.call(*params))
end
data
end
+3 -3
View File
@@ -369,7 +369,7 @@ module Precious
@name = wikip.name
@ext = wikip.ext
@path = wikip.path
@template_page = load_template(@path) if settings.wiki_options[:template_page]
@template_page = load_template(wikip, @path) if settings.wiki_options[:template_page]
@allow_uploads = wikip.wiki.allow_uploads
@upload_dest = find_upload_dest(wikip.fullpath)
@@ -661,9 +661,9 @@ module Precious
end
end
def load_template(path)
def load_template(wiki_page, path)
template_page = wiki_page(::File.join(path, '_Template')).page || wiki_page('/_Template').page
template_page ? Gollum::TemplateFilter.apply_filters(template_page.text_data) : nil
template_page ? Gollum::TemplateFilter.apply_filters(wiki_page, template_page.text_data) : nil
end
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)