From e567759935a1e653873a4caa4dda2b8989f7dc51 Mon Sep 17 00:00:00 2001 From: Simon Williams Date: Sun, 17 Mar 2013 18:27:40 -0600 Subject: [PATCH] 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