From 1cceb7d4b444c0b117430e6579837c430a72080b Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Thu, 5 Feb 2015 01:05:30 +0900 Subject: [PATCH 01/12] Add option to configure PlantUML endpoint --- bin/gollum | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/gollum b/bin/gollum index 9a5f32cc..9eb55f75 100755 --- a/bin/gollum +++ b/bin/gollum @@ -120,6 +120,10 @@ opts = OptionParser.new do |opts| opts.on("--h1-title", "Sets page title to value of first h1") do wiki_options[:h1_title] = true end + + opts.on("--plantuml-url [URL]", "Sets the PlantUML server endpoint.") do |url| + wiki_options[:plantuml_url] = url + end end # Read command line options into `options` hash @@ -167,6 +171,12 @@ if options['irb'] if !wiki.exist? then raise Gollum::InvalidGitRepositoryError end + if wiki_options[:plantuml_url] + Gollum::Filter::PlantUML.configure do |config| + puts "Using #{wiki_options[:plantuml_url]} as PlantUML endpoint" + config.url = wiki_options[:plantuml_url] + end + end puts "Loaded Gollum wiki at #{File.expand_path(gollum_path).inspect}." puts puts %( page = wiki.page('page-name')) @@ -197,6 +207,13 @@ else require cfg end + if wiki_options[:plantuml_url] + Gollum::Filter::PlantUML.configure do |config| + puts "Using #{wiki_options[:plantuml_url]} as PlantUML endpoint" + config.url = wiki_options[:plantuml_url] + end + end + base_path = wiki_options[:base_path] if wiki_options[:base_path].nil? From 0675844d97a14a788d81a9b99efa373c339dbfec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 27 Jun 2016 13:50:47 -0400 Subject: [PATCH 02/12] Fix compare page not accessible in no-edit mode Permission checking was spread across `post` action handlers instead of inside the `before` to normalize between `get` and `post` action handlers and be more explicit. --- lib/gollum/app.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 9e060f8d..4d002aee 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -96,7 +96,6 @@ module Precious before do settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) @allow_editing = settings.wiki_options[:allow_editing] - forbid unless @allow_editing || request.request_method == "GET" Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] @base_url = url('/', false).chomp('/') @page_dir = settings.wiki_options[:page_file_dir].to_s @@ -173,6 +172,8 @@ module Precious end post '/uploadFile' do + forbid unless @allow_editing + wiki = wiki_new unless wiki.allow_uploads @@ -222,6 +223,8 @@ module Precious end post '/rename/*' do + forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) halt 500 if wikip.nil? wiki = wikip.wiki @@ -258,6 +261,8 @@ module Precious end post '/edit/*' do + forbid unless @allow_editing + path = '/' + clean_url(sanitize_empty_params(params[:path])).to_s page_name = CGI.unescape(params[:page]) wiki = wiki_new @@ -317,6 +322,8 @@ module Precious end post '/create' do + forbid unless @allow_editing + name = params[:page].to_url path = sanitize_empty_params(params[:path]) || '' format = params[:format].intern @@ -336,6 +343,8 @@ module Precious end post '/revert/*/:sha1/:sha2' do + forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) @path = wikip.path @name = wikip.name @@ -359,6 +368,8 @@ module Precious end post '/preview' do + forbid unless @allow_editing + wiki = wiki_new @name = params[:page] || "Preview" @page = wiki.preview_page(@name, params[:content], params[:format]) From a50fcd31e29a6c6461ec02e38db56ae2fdb51243 Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Thu, 25 Aug 2016 10:11:22 +0200 Subject: [PATCH 03/12] final --- README.md | 1 + bin/gollum | 4 +++- lib/gollum/app.rb | 1 + lib/gollum/views/create.rb | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) 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 db8e714a..6d7cf46e 100755 --- a/bin/gollum +++ b/bin/gollum @@ -151,7 +151,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:" diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 0896a79f..730d9c62 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -104,6 +104,7 @@ module Precious @css = settings.wiki_options[:css] @js = settings.wiki_options[:js] @mathjax_config = settings.wiki_options[:mathjax_config] + @template_page=wiki_page("/_Template").page.raw_data if settings.wiki_options[:template_page] end get '/' do 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 From 54ece4e432a51aa0a8e9d3d0f050f426741ce791 Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Sat, 27 Aug 2016 15:51:18 +0200 Subject: [PATCH 04/12] mv template load in page create and added tests --- lib/gollum/app.rb | 8 +++++++- test/test_app.rb | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 730d9c62..ed766b46 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -104,7 +104,6 @@ module Precious @css = settings.wiki_options[:css] @js = settings.wiki_options[:js] @mathjax_config = settings.wiki_options[:mathjax_config] - @template_page=wiki_page("/_Template").page.raw_data if settings.wiki_options[:template_page] end get '/' do @@ -147,6 +146,7 @@ module Precious get '/edit/*' do forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) @name = wikip.name @path = wikip.path @@ -311,6 +311,12 @@ 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/test/test_app.rb b/test/test_app.rb index 32ba29ea..4ce98ac7 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -321,6 +321,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" From 72c8e1aff3247aa9f55a58f0fed5ec6c42baa44f Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Thu, 5 Feb 2015 01:05:30 +0900 Subject: [PATCH 05/12] Add option to configure PlantUML endpoint --- bin/gollum | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/gollum b/bin/gollum index b47875ef..0ca9d7f3 100755 --- a/bin/gollum +++ b/bin/gollum @@ -162,7 +162,6 @@ MSG end opts.separator "" - end # Read command line options into `options` hash @@ -208,6 +207,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}" @@ -243,6 +243,13 @@ else require cfg end + if wiki_options[:plantuml_url] + Gollum::Filter::PlantUML.configure do |config| + puts "Using #{wiki_options[:plantuml_url]} as PlantUML endpoint" + config.url = wiki_options[:plantuml_url] + end + end + base_path = wiki_options[:base_path] if base_path.nil? From e2d55b45ba64a7e12fa8d49cd46369745945bbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 27 Jun 2016 13:50:47 -0400 Subject: [PATCH 06/12] Fix compare page not accessible in no-edit mode Permission checking was spread across `post` action handlers instead of inside the `before` to normalize between `get` and `post` action handlers and be more explicit. --- lib/gollum/app.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 5be0e43b..c266e19d 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -97,7 +97,6 @@ module Precious before do settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) @allow_editing = settings.wiki_options[:allow_editing] - forbid unless @allow_editing || request.request_method == "GET" Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] @base_url = url('/', false).chomp('/') @page_dir = settings.wiki_options[:page_file_dir].to_s @@ -182,6 +181,8 @@ module Precious end post '/uploadFile' do + forbid unless @allow_editing + wiki = wiki_new unless wiki.allow_uploads @@ -244,6 +245,8 @@ module Precious end post '/rename/*' do + forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) halt 500 if wikip.nil? wiki = wikip.wiki @@ -280,6 +283,8 @@ module Precious end post '/edit/*' do + forbid unless @allow_editing + path = '/' + clean_url(sanitize_empty_params(params[:path])).to_s page_name = CGI.unescape(params[:page]) wiki = wiki_new @@ -339,6 +344,8 @@ module Precious end post '/create' do + forbid unless @allow_editing + name = params[:page].to_url path = sanitize_empty_params(params[:path]) || '' format = params[:format].intern @@ -358,6 +365,8 @@ module Precious end post '/revert/*/:sha1/:sha2' do + forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) @path = wikip.path @name = wikip.name @@ -381,6 +390,8 @@ module Precious end post '/preview' do + forbid unless @allow_editing + wiki = wiki_new @name = params[:page] || "Preview" @page = wiki.preview_page(@name, params[:content], params[:format]) From d7020261348987ab03661b91bb4842a8589c1545 Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Thu, 25 Aug 2016 10:11:22 +0200 Subject: [PATCH 07/12] final --- README.md | 1 + bin/gollum | 4 +++- lib/gollum/app.rb | 1 + lib/gollum/views/create.rb | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) 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 0ca9d7f3..2600579c 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:" diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index c266e19d..ba62a74d 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -105,6 +105,7 @@ module Precious @css = settings.wiki_options[:css] @js = settings.wiki_options[:js] @mathjax_config = settings.wiki_options[:mathjax_config] + @template_page=wiki_page("/_Template").page.raw_data if settings.wiki_options[:template_page] end get '/' do 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 From fdbde7840de82aa000a44b1c6217b258f55773d0 Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Sat, 27 Aug 2016 15:51:18 +0200 Subject: [PATCH 08/12] mv template load in page create and added tests --- lib/gollum/app.rb | 8 +++++++- test/test_app.rb | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index ba62a74d..40510727 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -105,7 +105,6 @@ module Precious @css = settings.wiki_options[:css] @js = settings.wiki_options[:js] @mathjax_config = settings.wiki_options[:mathjax_config] - @template_page=wiki_page("/_Template").page.raw_data if settings.wiki_options[:template_page] end get '/' do @@ -156,6 +155,7 @@ module Precious get '/edit/*' do forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) @name = wikip.name @path = wikip.path @@ -320,6 +320,12 @@ 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/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" From 2b8497531df0c005af1d5dc849f5f933093b2117 Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Fri, 24 Feb 2017 13:41:52 +0100 Subject: [PATCH 09/12] rebasing --- bin/gollum | 7 ------- lib/gollum/app.rb | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/gollum b/bin/gollum index 2600579c..d8b130bb 100755 --- a/bin/gollum +++ b/bin/gollum @@ -245,13 +245,6 @@ else require cfg end - if wiki_options[:plantuml_url] - Gollum::Filter::PlantUML.configure do |config| - puts "Using #{wiki_options[:plantuml_url]} as PlantUML endpoint" - config.url = wiki_options[:plantuml_url] - end - end - base_path = wiki_options[:base_path] if base_path.nil? diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 40510727..00ba6a74 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -97,6 +97,7 @@ module Precious before do settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) @allow_editing = settings.wiki_options[:allow_editing] + forbid unless @allow_editing || request.request_method == "GET" Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] @base_url = url('/', false).chomp('/') @page_dir = settings.wiki_options[:page_file_dir].to_s From 37a11546fa39e5d44704fd30581a9c1d99c0aa4c Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Fri, 24 Feb 2017 13:49:28 +0100 Subject: [PATCH 10/12] rebasing --- bin/gollum | 10 ---------- lib/gollum/app.rb | 24 ++---------------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/bin/gollum b/bin/gollum index 48440f9f..d8b130bb 100755 --- a/bin/gollum +++ b/bin/gollum @@ -145,9 +145,6 @@ MSG "If not specified, uses the '/mathjax.config.js' file.") do |file| wiki_options[:mathjax_config] = file || 'mathjax.config.js' end - opts.on("--plantuml-url [URL]", "Sets the PlantUML server endpoint.") do |url| - wiki_options[:plantuml_url] = url - end opts.on("--template-dir [PATH]", "Specify custom mustache template directory.") do |path| wiki_options[:template_dir] = path end @@ -248,13 +245,6 @@ else require cfg end - if wiki_options[:plantuml_url] - Gollum::Filter::PlantUML.configure do |config| - puts "Using #{wiki_options[:plantuml_url]} as PlantUML endpoint" - config.url = wiki_options[:plantuml_url] - end - end - base_path = wiki_options[:base_path] if base_path.nil? diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index cba879ac..58d1ba00 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -97,8 +97,7 @@ module Precious before do settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) @allow_editing = settings.wiki_options[:allow_editing] - - forbid unless @allow_editing || request.request_method == "GET" + forbid unless @allow_editing || request.request_method == "GET" Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] @base_url = url('/', false).chomp('/') @page_dir = settings.wiki_options[:page_file_dir].to_s @@ -157,7 +156,6 @@ module Precious get '/edit/*' do forbid unless @allow_editing - wikip = wiki_page(params[:splat].first) @name = wikip.name @path = wikip.path @@ -184,8 +182,6 @@ module Precious end post '/uploadFile' do - forbid unless @allow_editing - wiki = wiki_new unless wiki.allow_uploads @@ -248,8 +244,6 @@ module Precious end post '/rename/*' do - forbid unless @allow_editing - wikip = wiki_page(params[:splat].first) halt 500 if wikip.nil? wiki = wikip.wiki @@ -286,8 +280,6 @@ module Precious end post '/edit/*' do - forbid unless @allow_editing - path = '/' + clean_url(sanitize_empty_params(params[:path])).to_s page_name = CGI.unescape(params[:page]) wiki = wiki_new @@ -322,12 +314,6 @@ 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 @@ -353,8 +339,6 @@ module Precious end post '/create' do - forbid unless @allow_editing - name = params[:page].to_url path = sanitize_empty_params(params[:path]) || '' format = params[:format].intern @@ -374,8 +358,6 @@ module Precious end post '/revert/*/:sha1/:sha2' do - forbid unless @allow_editing - wikip = wiki_page(params[:splat].first) @path = wikip.path @name = wikip.name @@ -399,8 +381,6 @@ module Precious end post '/preview' do - forbid unless @allow_editing - wiki = wiki_new @name = params[:page] || "Preview" @page = wiki.preview_page(@name, params[:content], params[:format]) @@ -604,4 +584,4 @@ module Precious ) : '' end end -end +end \ No newline at end of file From 318a4717d12bae0ccbb8b1021ff1e55d4f5bedd0 Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Fri, 24 Feb 2017 13:50:38 +0100 Subject: [PATCH 11/12] rebasing --- lib/gollum/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 58d1ba00..5be0e43b 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -584,4 +584,4 @@ module Precious ) : '' end end -end \ No newline at end of file +end From c5f3270ff6bb6e7f2f0835291f13cfecb80572ed Mon Sep 17 00:00:00 2001 From: Daniele Grandini Date: Fri, 24 Feb 2017 13:54:29 +0100 Subject: [PATCH 12/12] final before pull request --- lib/gollum/app.rb | 4 ++++ 1 file changed, 4 insertions(+) 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