diff --git a/README.md b/README.md index c2a19b76..71491360 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,11 @@ Gollum runs on Unix-like systems using its [adapter](https://github.com/gollum/r ## INSTALLATION 1. Ruby is best installed either via [RVM](https://rvm.io/) or a package manager of choice. -2. Gollum is best installed via RubyGems: +2. Gollum is best installed via RubyGems: ``` [sudo] gem install gollum ``` - + Installation examples for individual systems can be seen [here](https://github.com/gollum/gollum/wiki/Installation). To run, simply: @@ -126,7 +126,7 @@ Gollum comes with the following command line options: | --no-display-metadata | none | Do not render metadata tables in pages. | | --user-icons | [MODE] | Tell Gollum to use specific user icons for history view. Can be set to `gravatar`, `identicon` or `none`. Default: `none`. | | --mathjax-config | [FILE] | Specify path to a custom MathJax configuration. If not specified, uses the `mathjax.config.js` file from repository root. | -| --template-dir | [PATH] | Specify custom mustache template directory. | +| --template-dir | [PATH] | Specify custom mustache template directory. Only overrides templates that exist in this directory. | | --template-page | none | Use _Template in root as a template for new pages. Must be committed. | | --emoji | none | Parse and interpret emoji tags (e.g. `:heart:`) except when the leading colon is backslashed (e.g. `\:heart:`). | | --lenient-tag-lookup | none | 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. | diff --git a/bin/gollum b/bin/gollum index 4acedd5a..13af0c04 100755 --- a/bin/gollum +++ b/bin/gollum @@ -149,7 +149,7 @@ MSG 'Can be set to \'gravatar\' or \'identicon\'. Default: standard avatar.') do |mode| wiki_options[:user_icons] = mode.to_s end - opts.on('--template-dir [PATH]', 'Specify custom mustache template directory.') do |path| + opts.on('--template-dir [PATH]', 'Specify custom mustache template directory. Only overrides templates that exist in this directory.') do |path| wiki_options[:template_dir] = path end opts.on('--template-page', 'Use _Template.{ext} as a template for new pages.') do @@ -271,7 +271,6 @@ else Precious::App.set(:environment, ENV.fetch('RACK_ENV', :production).to_sym) Precious::App.set(:gollum_path, gollum_path) Precious::App.set(:wiki_options, wiki_options) - Precious::App.settings.mustache[:templates] = wiki_options[:template_dir] if wiki_options[:template_dir] if cfg = options[:config] # If the path begins with a '/' it will be considered an absolute path, diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index f9c40d57..d18582bf 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -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 diff --git a/lib/gollum/views/template_cascade.rb b/lib/gollum/views/template_cascade.rb new file mode 100644 index 00000000..9bddc1cd --- /dev/null +++ b/lib/gollum/views/template_cascade.rb @@ -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 diff --git a/test/examples/template_cascade/navbar.mustache b/test/examples/template_cascade/navbar.mustache new file mode 100644 index 00000000..88fb8641 --- /dev/null +++ b/test/examples/template_cascade/navbar.mustache @@ -0,0 +1,8 @@ + diff --git a/test/examples/template_cascade/page.mustache b/test/examples/template_cascade/page.mustache new file mode 100644 index 00000000..4cb6b3e9 --- /dev/null +++ b/test/examples/template_cascade/page.mustache @@ -0,0 +1,12 @@ +
Include an overridden partial:
+