diff --git a/README.md b/README.md index 5523d98f..cd9a1efd 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ Gollum comes with the following command line options: | --template-dir | [PATH] | Specify custom mustache template directory. | | --help | none | Display the list of options on the command line. | | --version | none | Display the current version of Gollum. | +| --template-page | none | Tell Gollum to use /_Template as the default content for new pages. _Template must be git committed. | **Notes:** diff --git a/bin/gollum b/bin/gollum index b47875ef..d8b130bb 100755 --- a/bin/gollum +++ b/bin/gollum @@ -148,7 +148,9 @@ 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 + wiki_options[:template_page] = true + end opts.separator "" opts.separator " Common:" @@ -162,7 +164,6 @@ MSG end opts.separator "" - end # Read command line options into `options` hash @@ -208,6 +209,7 @@ if options[:irb] if !wiki.exist? then raise Gollum::InvalidGitRepositoryError end + puts puts "Loaded Gollum wiki at:" puts "#{File.expand_path(gollum_path).inspect}" diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 5be0e43b..2f0611f4 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -314,6 +314,10 @@ 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.gsub('+', '-')) @name = wikip.name.to_url @path = wikip.path diff --git a/lib/gollum/views/create.rb b/lib/gollum/views/create.rb index d976df83..5973d6a0 100755 --- a/lib/gollum/views/create.rb +++ b/lib/gollum/views/create.rb @@ -56,6 +56,11 @@ module Precious def default_markup Precious::App.settings.default_markup end + + #QND - sets default template page if specified + def content + @template_page + end end end end diff --git a/test/test_app.rb b/test/test_app.rb index 0eec3726..5a0da233 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -310,6 +310,28 @@ context "Frontend" do assert_no_match(/[^\/]#{dir}/, last_response.body) end + test "create with template succeed if template exists" do + Precious::App.set(:wiki_options, { :template_page => true }) + page='_Template' + post '/create', :content => 'fake template', :page => page, + :path => '/', :format => 'markdown', :message => '' + follow_redirect! + assert last_response.ok? + #puts last_response + @wiki.clear_cache + get "/create/TT" + assert last_response.ok? + get '/delete/_Template' + Precious::App.set(:wiki_options, { :template_page => false }) + end + + test "create with template succeed if template doesn't exist" do + Precious::App.set(:wiki_options, { :template_page => true }) + get "/create/TT" + assert last_response.ok? + Precious::App.set(:wiki_options, { :template_page => false }) + end + test "create sets the correct path for a relative path subdirectory with the page file directory set" do Precious::App.set(:wiki_options, { :page_file_dir => "foo" }) dir = "bardir"