From e567759935a1e653873a4caa4dda2b8989f7dc51 Mon Sep 17 00:00:00 2001 From: Simon Williams Date: Sun, 17 Mar 2013 18:27:40 -0600 Subject: [PATCH 1/4] Fix for embedding code from github --- README.md | 4 ++-- lib/gollum/markup.rb | 20 ++++++++++---------- test/test_gitcode.rb | 16 +++++++++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5efaf8d9..90f56f1c 100644 --- a/README.md +++ b/README.md @@ -358,9 +358,9 @@ As an extra feature, you can syntax highlight a file from your repository, allow you keep some of your sample code in the main repository. The code-snippet is updated when the wiki is rebuilt. You include github code like this: - ```html:gollum/gollum/master/test/file_view/1_file.txt``` + ```html:github:gollum/gollum/master/test/file_view/1_file.txt``` -This will make the builder look at the **github user**, in the **gollum project**, +This will make the builder look at the **gollum user**, in the **gollum project**, in the **master branch**, at path **test/file_view/1_file.txt**. It will be rewritten to: diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 405fc08f..5a495046 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -460,23 +460,23 @@ module Gollum # Acceptable formats: # ```language:local-file.ext``` # ```language:/abs/other-file.ext``` - # ```language:gollum/gollum/master/somefile.txt``` + # ```language:github:gollum/gollum/master/somefile.txt``` # ######################################################################### def extract_gitcode data - data.gsub /^[ \t]*``` ?([^:\n\r]+):([^`\n\r]+)```/ do + data.gsub /^[ \t]*``` ?([^:\n\r]+):(?:(github:))?([^`\n\r]+)```/ do contents = '' # Use empty string if $2 is nil. - uri = $2 || '' + uri = $3 || '' # Detect local file. - if uri[0..6] != 'gollum/' - if file = self.find_file(uri, @wiki.ref) - contents = file.raw_data - else - # How do we communicate a render error? - next "File not found: #{Rack::Utils::escape_html(uri)}" - end + if $2.nil? + if file = self.find_file(uri, @wiki.ref) + contents = file.raw_data + else + # How do we communicate a render error? + next "File not found: #{Rack::Utils::escape_html(uri)}" + end else contents = Gollum::Gitcode.new(uri).contents end diff --git a/test/test_gitcode.rb b/test/test_gitcode.rb index 9d72769b..ca38b3f3 100644 --- a/test/test_gitcode.rb +++ b/test/test_gitcode.rb @@ -16,16 +16,18 @@ context "gitcode" do setup do # context @wiki, @path, @cleanup = WikiFactory.create 'examples/test.git' - - # given - p = page_with_content "a\n\n```html:gollum/gollum/master/test/file_view/1_file.txt```\n\nb" - - # when rendering the page - @rendered = Gollum::Markup.new(p).render end test 'that the rendered output is correctly fetched and rendered as html code' do - assert_equal %Q{

a

\n\n
<ol class=\"tree\">\n  <li class=\"file\">\n    <a href=\"0\"><span class=\"icon\"></span>0</a>\n  </li>\n</ol>\n
\n\n

b

}, @rendered + # given + p = page_with_content "a\n\n```html:github:gollum/gollum/master/test/file_view/1_file.txt```\n\nb" + + # when rendering the page + rendered = Gollum::Markup.new(p).render + + # we expect + expected = %Q{

a

\n\n
<ol class=\"tree\">\n  <li class=\"file\">\n    <a href=\"0\"><span class=\"icon\"></span>0</a>\n  </li>\n</ol>\n
\n\n

b

} + assert_equal expected, rendered end test 'contents' do From 846ebb285efa4e1a739d891f40ca81490bd63865 Mon Sep 17 00:00:00 2001 From: Simon Williams Date: Thu, 14 Mar 2013 23:38:53 -0600 Subject: [PATCH 2/4] Add option for custom js (like custom css) * Add a new 'js' flag to indicate you want to embed a file named 'custom.js' which should exist at the root of the wiki --- README.md | 4 +++- bin/gollum | 4 ++++ lib/gollum/frontend/app.rb | 1 + .../frontend/templates/file_view.mustache | 1 + lib/gollum/frontend/templates/layout.mustache | 1 + lib/gollum/frontend/views/layout.rb | 4 ++++ test/test_app.rb | 24 +++++++++++++++++++ 7 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5efaf8d9..45d56628 100644 --- a/README.md +++ b/README.md @@ -548,10 +548,12 @@ Note that filenames on windows must not contain any of the following characters Gollum optionally takes a `--config file`. See [config.rb](https://github.com/gollum/gollum/blob/master/config.rb) for an example. -## CUSTOM CSS +## CUSTOM CSS/JS The `--css` flag will inject `custom.css` from the root of your git repository into each page. `custom.css` must be commited to git or you will get a 302 redirect to the create page. +The `--js` flag will inject `custom.js` from the root of your git repository into each page. `custom.js` must be commited to git or you will get a 302 redirect to the create page. + ## CONTRIBUTE If you'd like to hack on Gollum, start by forking the repo on GitHub: diff --git a/bin/gollum b/bin/gollum index 61e6ecc0..3f2748bb 100755 --- a/bin/gollum +++ b/bin/gollum @@ -49,6 +49,10 @@ opts = OptionParser.new do |opts| wiki_options[:css] = true end + opts.on("--js", "Inject custom js. Uses custom.js from root repository") do + wiki_options[:js] = true + end + opts.on("--page-file-dir [PATH]", "Specify the sub directory for all page files (default: repository root).") do |path| wiki_options[:page_file_dir] = path end diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 50893184..3adf1c79 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -85,6 +85,7 @@ module Precious # above will detect base_path when it's used with map in a config.ru settings.wiki_options.merge!({ :base_path => @base_url }) @css = settings.wiki_options[:css] + @js = settings.wiki_options[:js] end get '/' do diff --git a/lib/gollum/frontend/templates/file_view.mustache b/lib/gollum/frontend/templates/file_view.mustache index 16e9f968..830839fc 100644 --- a/lib/gollum/frontend/templates/file_view.mustache +++ b/lib/gollum/frontend/templates/file_view.mustache @@ -6,6 +6,7 @@ {{#css}}{{/css}} + {{#js}}{{/js}} {{title}} diff --git a/lib/gollum/frontend/templates/layout.mustache b/lib/gollum/frontend/templates/layout.mustache index 493ca8d1..282e141f 100644 --- a/lib/gollum/frontend/templates/layout.mustache +++ b/lib/gollum/frontend/templates/layout.mustache @@ -43,6 +43,7 @@ (d.head || d.getElementsByTagName('head')[0]).appendChild(j); }(document)); {{/mathjax}} + {{#js}}{{/js}} {{title}} diff --git a/lib/gollum/frontend/views/layout.rb b/lib/gollum/frontend/views/layout.rb index 3dcd4ecd..5cc2f372 100644 --- a/lib/gollum/frontend/views/layout.rb +++ b/lib/gollum/frontend/views/layout.rb @@ -28,6 +28,10 @@ module Precious @css end + def js # custom js + @js + end + end end end diff --git a/test/test_app.rb b/test/test_app.rb index 3ef56e90..6ee2bf03 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -461,6 +461,30 @@ context "Frontend" do assert_equal 'jkl', author.email end + test "do not add custom.js by default" do + page = 'nocustom' + text = 'nope none' + + @wiki.write_page(page, :markdown, text, + { :name => 'user1', :email => 'user1' }); + + get page + assert_no_match /custom.js/, last_response.body + end + + test "add custom.js if setting" do + Precious::App.set(:wiki_options, { :js => true }) + page = 'yaycustom' + text = 'customized!' + + @wiki.write_page(page, :markdown, text, + { :name => 'user1', :email => 'user1' }); + + get page + assert_match /custom.js/, last_response.body + Precious::App.set(:wiki_options, { :js => nil }) + end + def app Precious::App end From 0885702873eeca93be491a6e8ea5df255ebd5441 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 19 Mar 2013 21:10:22 -0300 Subject: [PATCH 3/4] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d467ca4e..68de987c 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ Gollum follows the rules of [Semantic Versioning](http://semver.org/) and uses - Unix like operating system (OS X, Ubuntu, Debian, and more) - Will not work on Windows (because of [grit](https://github.com/github/grit)) +## SECURITY + +Don't enable `--custom-css` or `--custom-js` unless you trust every user who has the ability to edit the wiki. +A better solution with more security is being tracked in #665. + ## INSTALLATION The best way to install Gollum is with RubyGems: From ab8599da6dee3bf9a34402a90f5300edf8d54ea9 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 19 Mar 2013 21:11:41 -0300 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68de987c..c91b47f0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Gollum follows the rules of [Semantic Versioning](http://semver.org/) and uses ## SECURITY Don't enable `--custom-css` or `--custom-js` unless you trust every user who has the ability to edit the wiki. -A better solution with more security is being tracked in #665. +A better solution with more security is being tracked in [#665](https://github.com/gollum/gollum/issues/665). ## INSTALLATION