From 1cceb7d4b444c0b117430e6579837c430a72080b Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Thu, 5 Feb 2015 01:05:30 +0900 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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"