From fcdffc39ff33dad5eb153bb280c4a75fe963dfb6 Mon Sep 17 00:00:00 2001 From: Hiroshi Saito Date: Thu, 7 Oct 2010 17:55:40 +0900 Subject: [PATCH 01/23] Added --page-file-dir option to gollum command --- bin/gollum | 8 +++++++- lib/gollum/frontend/app.rb | 18 +++++++++--------- lib/gollum/wiki.rb | 15 +++++++++++++-- test/test_wiki.rb | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/bin/gollum b/bin/gollum index 86ac7622..4d1a70d3 100755 --- a/bin/gollum +++ b/bin/gollum @@ -19,6 +19,7 @@ require 'gollum' exec = {} options = { 'port' => 4567, 'bind' => '127.0.0.1' } +wiki_options = {} opts = OptionParser.new do |opts| opts.banner = help @@ -38,6 +39,10 @@ opts = OptionParser.new do |opts| opts.on("--irb", "Start an irb process with gollum loaded for the current wiki.") do options['irb'] = 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 end # Read command line options into `options` hash @@ -77,7 +82,7 @@ if options['irb'] end begin - wiki = Gollum::Wiki.new(gollum_path) + wiki = Gollum::Wiki.new(gollum_path, wiki_options) if !wiki.exist? then raise Grit::InvalidGitRepositoryError end puts "Loaded Gollum wiki at #{File.expand_path(gollum_path).inspect}." puts @@ -99,5 +104,6 @@ if options['irb'] else require 'gollum/frontend/app' Precious::App.set(:gollum_path, gollum_path) + Precious::App.set(:wiki_options, wiki_options) Precious::App.run!(options) end diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index b91e23d0..7f06d8eb 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -42,7 +42,7 @@ module Precious get '/edit/*' do @name = params[:splat].first - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) if page = wiki.page(@name) @page = page @content = page.raw_data @@ -54,7 +54,7 @@ module Precious post '/edit/*' do name = params[:splat].first - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) page = wiki.page(name) format = params[:format].intern name = params[:rename] if params[:rename] @@ -66,7 +66,7 @@ module Precious post '/create/*' do name = params[:page] - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) format = params[:format].intern @@ -82,13 +82,13 @@ module Precious post '/preview' do format = params['wiki_format'] data = params['text'] - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) wiki.preview_page("Preview", data, format).formatted_data end get '/history/:name' do @name = params[:name] - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) @page = wiki.page(@name) @page_num = [params[:page].to_i, 1].max @versions = @page.versions :page => @page_num @@ -110,7 +110,7 @@ module Precious get '/compare/:name/:version_list' do @name = params[:name] @versions = params[:version_list].split(/\.{2,3}/) - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) @page = wiki.page(@name) diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path) @diff = diffs.first @@ -119,7 +119,7 @@ module Precious get %r{/(.+?)/([0-9a-f]{40})} do name = params[:captures][0] - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) if page = wiki.page(name, params[:captures][1]) @page = page @name = name @@ -132,7 +132,7 @@ module Precious get '/search' do @query = params[:q] - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) @results = wiki.search @query mustache :search end @@ -142,7 +142,7 @@ module Precious end def show_page_or_file(name) - wiki = Gollum::Wiki.new(settings.gollum_path) + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) if page = wiki.page(name) @page = page @name = name diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 172aa9aa..11645eff 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -46,6 +46,8 @@ module Gollum # to "/". attr_reader :base_path + attr_reader :page_file_dir + # Public: Initialize a new Gollum Repo. # # repo - The String path to the Git repository that holds the Gollum @@ -55,6 +57,7 @@ module Gollum # Default: "/" # :page_class - The page Class. Default: Gollum::Page # :file_class - The file Class. Default: Gollum::File + # :page_file_dir - String the directory in which all page files reside # # Returns a fresh Gollum::Repo. def initialize(path, options = {}) @@ -63,6 +66,7 @@ module Gollum @base_path = options[:base_path] || "/" @page_class = options[:page_class] || self.class.page_class @file_class = options[:file_class] || self.class.file_class + @page_file_dir = options[:page_file_dir] clear_cache end @@ -339,6 +343,9 @@ module Gollum else ::File.join(dir, page_file_name(name, format)) end + if @page_file_dir + path = ::File.join(@page_file_dir, path) + end Dir.chdir(::File.join(@repo.path, '..')) do if file_path_scheduled_for_deletion?(index.tree, path) @@ -433,7 +440,7 @@ module Gollum dir = '/' if dir.strip.empty? - fullpath = ::File.join(dir, path) + fullpath = ::File.join(*[@page_file_dir, dir, path].compact) fullpath = fullpath[1..-1] if fullpath =~ /^\// if index.current_tree && tree = index.current_tree / dir @@ -507,7 +514,11 @@ module Gollum tree.split("\0").each do |line| items << parse_tree_line(line) end - items + if dir = @page_file_dir + items.select{|i| i.path =~ /^#{dir}\// } + else + items + end end # Parses a line of output from the `ls-tree` command. diff --git a/test/test_wiki.rb b/test/test_wiki.rb index 51cd287b..cf3e6aa7 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -282,3 +282,39 @@ context "Wiki sync with working directory" do FileUtils.rm_r(@path) end end + +context "page_file_dir option" do + setup do + @path = testpath('examples/pfdtest') + @repo = Grit::Repo.init(@path) + @page_file_dir = 'docs' + Dir.chdir(@path) do + Dir.mkdir(@page_file_dir) + File.open("docs/foo.md", "w"){|f| f.print "Hello foo" } + @repo.add("docs/foo.md") + File.open("bar.md", "w"){|f| f.print "Hello bar" } + @repo.add("bar.md") + @repo.commit_index("Added docs/foo.md and bar.md") + end + + @wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_file_dir) + end + + test "write a page in sub directory" do + @wiki.write_page("New Page", :markdown, "Hi", commit_details) + assert_equal "Hi", File.read(File.join(@path, @page_file_dir, "New-Page.md")) + assert !File.exist?(File.join(@path, "New-Page.md")) + end + + test "a file in page file dir should be found" do + assert @wiki.page("foo") + end + + test "a file out of page file dir should not be found" do + assert !@wiki.page("bar") + end + + teardown do + FileUtils.rm_r(@path) + end +end From f8e7fcf2d29658d1515203ea0a9997b4316d4abf Mon Sep 17 00:00:00 2001 From: Hiroshi Saito Date: Thu, 7 Oct 2010 23:01:27 +0900 Subject: [PATCH 02/23] FIX: results of Wiki#search contains files out of page_file_dir --- lib/gollum/wiki.rb | 6 +++++- test/test_wiki.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 11645eff..8e0b7498 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -246,7 +246,11 @@ module Gollum # Returns an Array with Objects of page name and count of matches def search(query) # See: http://github.com/Sirupsen/gollum/commit/f0a6f52bdaf6bee8253ca33bb3fceaeb27bfb87e - search_output = @repo.git.grep({:c => query}, 'master') + if @page_file_dir + search_output = @repo.git.grep({:c => query}, 'master', '--', @page_file_dir) + else + search_output = @repo.git.grep({:c => query}, 'master') + end search_output.split("\n").collect do |line| result = line.split(':') diff --git a/test/test_wiki.rb b/test/test_wiki.rb index cf3e6aa7..6df4e170 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -314,6 +314,12 @@ context "page_file_dir option" do assert !@wiki.page("bar") end + test "search results should be restricted in page filer dir" do + results = @wiki.search("Hello") + assert_equal 1, results.size + assert_equal "foo", results[0][:name] + end + teardown do FileUtils.rm_r(@path) end From 32d1f9eb2f3da8eb8ddbb8fb5915b38171683545 Mon Sep 17 00:00:00 2001 From: Hugo Duncan Date: Fri, 7 Jan 2011 23:59:36 -0500 Subject: [PATCH 03/23] Add parsing of org-mode [[file:path.org][label]] links --- lib/gollum/markup.rb | 13 ++++++++++++- test/test_markup.rb | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 6b8a4582..9617d3dd 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -120,7 +120,18 @@ module Gollum if $1 == "'" && $3 != "'" "[[#{$2}]]#{$3}" elsif $2.include?('][') - $& + if $2[0..4] == 'file:' + pre = $1 + post = $3 + parts = $2.split('][') + parts[0][0..4] = "" + link = "#{parts[1]}|#{parts[0].sub(/\.org/,'')}" + id = Digest::SHA1.hexdigest(link) + @tagmap[id] = link + "#{pre}#{id}#{post}" + else + $& + end else id = Digest::SHA1.hexdigest($2) @tagmap[id] = $2 diff --git a/test/test_markup.rb b/test/test_markup.rb index 098b9512..fa420c79 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -414,6 +414,12 @@ context "Markup" do compare(content, output, 'org') end + test "org mode style double file links" do + content = "a [[file:f.org][Google]] b" + output = "

a Google b

" + compare(content, output, 'org') + end + ######################################################################### # # TeX From 0fd639a149cedaf26f976562361253752026f7a0 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 10 Jan 2011 16:44:07 -0800 Subject: [PATCH 04/23] whitespace plugin --- lib/gollum/frontend/app.rb | 2 +- lib/gollum/markup.rb | 18 ++++++++-------- lib/gollum/wiki.rb | 43 ++++++++++++++++++++------------------ 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 0d0b540e..617c432a 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -59,7 +59,7 @@ module Precious page = wiki.page(params[:splat].first) name = params[:rename] || page.name msg = commit_message - update_wiki_page(wiki, page, params[:content], msg, name, + update_wiki_page(wiki, page, params[:content], msg, name, params[:format]) update_wiki_page(wiki, page.footer, params[:footer], msg) if params[:footer] update_wiki_page(wiki, page.sidebar, params[:sidebar], msg) if params[:sidebar] diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 6b8a4582..b57e5adf 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -28,8 +28,8 @@ module Gollum # # Returns the formatted String content. def render(no_follow = false) - sanitize = no_follow ? - @wiki.history_sanitizer : + sanitize = no_follow ? + @wiki.history_sanitizer : @wiki.sanitizer data = extract_tex(@data.dup) @@ -147,7 +147,7 @@ module Gollum # Process a single tag into its final HTML form. # - # tag - The String tag contents (the stuff inside the double + # tag - The String tag contents (the stuff inside the double # brackets). # no_follow - Boolean that determines if rel="nofollow" is added to all # tags. @@ -252,7 +252,7 @@ module Gollum # Attempt to process the tag as a file link tag. # - # tag - The String tag contents (the stuff inside the double + # tag - The String tag contents (the stuff inside the double # brackets). # no_follow - Boolean that determines if rel="nofollow" is added to all # tags. @@ -286,7 +286,7 @@ module Gollum # Attempt to process the tag as a page link tag. # - # tag - The String tag contents (the stuff inside the double + # tag - The String tag contents (the stuff inside the double # brackets). # no_follow - Boolean that determines if rel="nofollow" is added to all # tags. @@ -335,7 +335,7 @@ module Gollum # # cname - The String canonical page name. # - # Returns a Gollum::Page instance if a page is found, or an Array of + # Returns a Gollum::Page instance if a page is found, or an Array of # [Gollum::Page, String extra] if a page without the extra anchor data # is found. def find_page_from_name(cname) @@ -362,8 +362,8 @@ module Gollum data.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do id = Digest::SHA1.hexdigest($2) cached = check_cache(:code, id) - @codemap[id] = cached ? - { :output => cached } : + @codemap[id] = cached ? + { :output => cached } : { :lang => $1, :code => $2 } id end @@ -393,7 +393,7 @@ module Gollum data end - # Hook for getting the formatted value of extracted tag data. + # Hook for getting the formatted value of extracted tag data. # # type - Symbol value identifying what type of data is being extracted. # id - String SHA1 hash of original extracted tag data. diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index d5ce1e84..a93e0e83 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -59,7 +59,7 @@ module Gollum end end - # Gets the default sanitization options for current pages used by + # Gets the default sanitization options for current pages used by # instances of this Wiki. def sanitization if @sanitization.nil? @@ -68,7 +68,7 @@ module Gollum @sanitization end - # Gets the default sanitization options for older page revisions used by + # Gets the default sanitization options for older page revisions used by # instances of this Wiki. def history_sanitization if @history_sanitization.nil? @@ -120,7 +120,7 @@ module Gollum @markup_class = options[:markup_class] || self.class.markup_class @repo = @access.repo @sanitization = options[:sanitization] || self.class.sanitization - @history_sanitization = options[:history_sanitization] || + @history_sanitization = options[:history_sanitization] || self.class.history_sanitization end @@ -266,7 +266,7 @@ module Gollum tree_list(treeish || 'master') end - # Public: Returns the number of pages accessible from a commit + # Public: Returns the number of pages accessible from a commit # # ref - A String ref that is either a commit SHA or references one. # @@ -340,7 +340,7 @@ module Gollum @access.refresh end - # Public: Creates a Sanitize instance using the Wiki's sanitization + # Public: Creates a Sanitize instance using the Wiki's sanitization # options. # # Returns a Sanitize instance. @@ -350,7 +350,7 @@ module Gollum end end - # Public: Creates a Sanitize instance using the Wiki's history sanitization + # Public: Creates a Sanitize instance using the Wiki's history sanitization # options. # # Returns a Sanitize instance. @@ -536,6 +536,12 @@ module Gollum index.add(fullpath, normalize(data)) end + # Commits to the repo. This is a common method used by Gollum for + # creating, updating, and deleting pages. There are typically three steps: + # building an index with the current tree, yielding the index for + # modification, and then writing the commit. + # + # options - Hash of option def commit_index(options = {}) normalize_commit(options) parents = [options[:parent] || @repo.commit('master')] @@ -549,6 +555,8 @@ module Gollum end yield index if block_given? + options[:name] = default_committer_name if options[:name].to_s.empty? + options[:email] = default_committer_email if options[:email].to_s.empty? actor = Grit::Actor.new(options[:name], options[:email]) index.commit(options[:message], parents, actor) end @@ -558,32 +566,27 @@ module Gollum repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path) end - # Ensures a commit hash has all the required fields for a commit. - # - # commit - The commit Hash details: - # :message - The String commit message. - # :name - The String author full name. - # :email - The String email address. - # - # Returns the commit Hash - def normalize_commit(commit = {}) - commit[:name] = default_committer_name if commit[:name].to_s.empty? - commit[:email] = default_committer_email if commit[:email].to_s.empty? - commit - end - # Gets the default name for commits. + # + # Returns the String name. def default_committer_name @default_committer_name ||= \ @repo.config['user.name'] || self.class.default_committer_name end # Gets the default email for commits. + # + # Returns the String email address. def default_committer_email @default_committer_email ||= \ @repo.config['user.email'] || self.class.default_committer_email end + # Gets the commit object for the given ref or sha. + # + # ref - A string ref or SHA pointing to a valid commit. + # + # Returns a Grit::Commit instance. def commit_for(ref) @access.commit(ref) rescue Grit::GitRuby::Repository::NoSuchShaFound From 41a21efe9febe6b3eef96545be9541b4264c78ef Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 10 Jan 2011 16:44:20 -0800 Subject: [PATCH 05/23] don't attempt to serve public assets from sinatra --- lib/gollum/frontend/app.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 617c432a..06329494 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -141,6 +141,10 @@ module Precious mustache :compare end + get %r{^/(javascript|css|images)} do + halt 404 + end + get %r{/(.+?)/([0-9a-f]{40})} do name = params[:captures][0] wiki = Gollum::Wiki.new(settings.gollum_path) From 992ec36295854dd3ad61b634ce2faeb6fdccfb22 Mon Sep 17 00:00:00 2001 From: rick Date: Tue, 11 Jan 2011 00:04:38 -0800 Subject: [PATCH 06/23] accidental removal --- lib/gollum/wiki.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index a93e0e83..d736b6da 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -566,6 +566,20 @@ module Gollum repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path) end + # Ensures a commit hash has all the required fields for a commit. + # + # commit - The commit Hash details: + # :message - The String commit message. + # :name - The String author full name. + # :email - The String email address. + # + # Returns the commit Hash + def normalize_commit(commit = {}) + commit[:name] = default_committer_name if commit[:name].to_s.empty? + commit[:email] = default_committer_email if commit[:email].to_s.empty? + commit + end + # Gets the default name for commits. # # Returns the String name. From 45765eb161119a56815e57c9912ce4a81c4eb18d Mon Sep 17 00:00:00 2001 From: rick Date: Tue, 11 Jan 2011 00:30:22 -0800 Subject: [PATCH 07/23] add proper shell escaping for Albino --- lib/gollum/albino.rb | 13 +++++++++++++ test/test_markup.rb | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/gollum/albino.rb b/lib/gollum/albino.rb index c3a18a27..03725e47 100644 --- a/lib/gollum/albino.rb +++ b/lib/gollum/albino.rb @@ -14,4 +14,17 @@ class Gollum::Albino < Albino html.sub!(%r{\Z}, "\n") html end + + # Hotfix for vulnerable versions of Albino + if !instance_methods.include?('shell_escape') + def convert_options(options = {}) + @options.merge(options).inject('') do |string, (flag, value)| + string + " -#{flag} #{shell_escape value}" + end + end + + def shell_escape(str) + str.to_s.gsub("'", "\\\\'").gsub(";", '\\;') + end + end end \ No newline at end of file diff --git a/test/test_markup.rb b/test/test_markup.rb index 098b9512..83f71e2f 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -387,6 +387,18 @@ context "Markup" do compare(content, output) end + test "code block with invalid lang" do + content = "a\n\n``` ls -al;\n\tbooya\n\tboom\n```\n\nb" + output = "

a

\n\n\n\n

b

" + compare(content, output) + end + + test "code block with no lang" do + content = "a\n\n```\n\tls -al;\n\tbooya\n```\n\nb" + output = "

a

\n\n\n\n

b

" + compare(content, output) + end + ######################################################################### # # Various From c5e4935e85d820c01267a6e8e333232d7add4288 Mon Sep 17 00:00:00 2001 From: rick Date: Tue, 11 Jan 2011 00:47:46 -0800 Subject: [PATCH 08/23] tweak code markup parser so that blocks without a language are just output in pre tags --- lib/gollum/markup.rb | 9 ++++++--- test/test_markup.rb | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index b57e5adf..7a521ed8 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -359,7 +359,7 @@ module Gollum # # Returns the placeholder'd String data. def extract_code(data) - data.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do + data.gsub!(/^``` ?([^\r\n]+)?\r?\n(.+?)\r?\n```\r?$/m) do id = Digest::SHA1.hexdigest($2) cached = check_cache(:code, id) @codemap[id] = cached ? @@ -379,12 +379,15 @@ module Gollum def process_code(data) @codemap.each do |id, spec| formatted = spec[:output] || begin - lang = spec[:lang] code = spec[:code] if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ } code.gsub!(/^( |\t)/m, '') end - formatted = Gollum::Albino.new(code, lang).colorize + formatted = if lang = spec[:lang] + Gollum::Albino.new(code, lang).colorize + else + "
#{CGI.escapeHTML(code)}
" + end update_cache(:code, id, formatted) formatted end diff --git a/test/test_markup.rb b/test/test_markup.rb index 83f71e2f..7d729aba 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -394,8 +394,8 @@ context "Markup" do end test "code block with no lang" do - content = "a\n\n```\n\tls -al;\n\tbooya\n```\n\nb" - output = "

a

\n\n\n\n

b

" + content = "a\n\n```\n\tls -al;\n\t\n```\n\nb" + output = "

a

\n\n
ls -al;\n<booya>
\n\n

b

" compare(content, output) end From e4103e6181b69b46a3af3eba9a615f787e70ab79 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Tue, 11 Jan 2011 22:50:59 -0200 Subject: [PATCH 09/23] testing link labeling current behavior --- test/test_markup.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_markup.rb b/test/test_markup.rb index 7d729aba..3664bc5a 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -162,6 +162,13 @@ context "Markup" do assert_equal "

a http://example.com b

", page.formatted_data end + test "page link with different text" do + @wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details) + page = @wiki.page("Potato") + output = page.formatted_data + assert_equal "

a Potato Heaad

", output + end + ######################################################################### # # Images From 2dbb4e9fa7d5b1f8175249a2f51c028332de1f4f Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Tue, 11 Jan 2011 23:57:22 -0200 Subject: [PATCH 10/23] fixed mediawiki link handling --- lib/gollum/markup.rb | 37 +++++++++++++++++++++---------------- test/test_markup.rb | 7 +++++++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 7a521ed8..236c0fc2 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -13,6 +13,7 @@ module Gollum @name = page.filename @data = page.text_data @version = page.version.id + @format = page.format @dir = ::File.dirname(page.path) @tagmap = {} @codemap = {} @@ -294,22 +295,26 @@ module Gollum # Returns the String HTML if the tag is a valid page link tag or nil # if it is not. def process_page_link_tag(tag, no_follow = false) - parts = tag.split('|') - name = parts[0].strip - cname = @wiki.page_class.cname((parts[1] || parts[0]).strip) - tag = if name =~ %r{^https?://} && parts[1].nil? - %{#{name}} - else - presence = "absent" - link_name = cname - page, extra = find_page_from_name(cname) - if page - link_name = @wiki.page_class.cname(page.name) - presence = "present" - end - link = ::File.join(@wiki.base_path, CGI.escape(link_name)) - %{#{name}} - end + parts = if @format == :mediawiki + tag.split('|').reverse + else + tag.split('|') + end + name, page_name = *parts.compact.map(&:strip) + cname = @wiki.page_class.cname(page_name || name) + tag = if name =~ %r{^https?://} && page_name.nil? + %{#{name}} + else + presence = "absent" + link_name = cname + page, extra = find_page_from_name(cname) + if page + link_name = @wiki.page_class.cname(page.name) + presence = "present" + end + link = ::File.join(@wiki.base_path, CGI.escape(link_name)) + %{#{name}} + end if tag && no_follow tag.sub! /^a Potato Heaad

", output end + test "page link with different text on mediawiki" do + @wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details) + page = @wiki.page("Potato") + output = page.formatted_data + assert_equal "

\na Potato Heaad \n

", output + end + ######################################################################### # # Images From 0a1ecde7b61ade23400d89756c6cba06a094315b Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Wed, 12 Jan 2011 01:00:01 -0200 Subject: [PATCH 11/23] typo --- lib/gollum/markup.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 236c0fc2..5f2adf7e 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -316,7 +316,7 @@ module Gollum %{#{name}} end if tag && no_follow - tag.sub! /^ Date: Wed, 12 Jan 2011 15:00:58 -0800 Subject: [PATCH 12/23] update albino to 1.2.3, handle bad code blocks gracefully --- gollum.gemspec | 2 +- lib/gollum/albino.rb | 22 ++-------------------- lib/gollum/markup.rb | 12 ++++++++---- test/test_markup.rb | 10 +++++----- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/gollum.gemspec b/gollum.gemspec index 74ae1c28..73290aca 100644 --- a/gollum.gemspec +++ b/gollum.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |s| s.add_dependency('grit', "~> 2.3") s.add_dependency('github-markup', [">= 0.4.0", "< 1.0.0"]) - s.add_dependency('albino', "~> 1.0") + s.add_dependency('albino', "~> 1.2.3") s.add_dependency('sinatra', "~> 1.0") s.add_dependency('mustache', [">= 0.11.2", "< 1.0.0"]) s.add_dependency('sanitize', "~> 1.1") diff --git a/lib/gollum/albino.rb b/lib/gollum/albino.rb index 03725e47..b731ae9d 100644 --- a/lib/gollum/albino.rb +++ b/lib/gollum/albino.rb @@ -1,30 +1,12 @@ require 'albino' class Gollum::Albino < Albino - def self.bin - Albino.bin - end - - def bin - Albino.bin - end + self.bin = ::Albino.bin + self.default_encoding = ::Albino.default_encoding def colorize(options = {}) html = super.to_s html.sub!(%r{\Z}, "\n") html end - - # Hotfix for vulnerable versions of Albino - if !instance_methods.include?('shell_escape') - def convert_options(options = {}) - @options.merge(options).inject('') do |string, (flag, value)| - string + " -#{flag} #{shell_escape value}" - end - end - - def shell_escape(str) - str.to_s.gsub("'", "\\\\'").gsub(";", '\\;') - end - end end \ No newline at end of file diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 7a521ed8..93909649 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -380,14 +380,18 @@ module Gollum @codemap.each do |id, spec| formatted = spec[:output] || begin code = spec[:code] + lang = spec[:lang] + if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ } code.gsub!(/^( |\t)/m, '') end - formatted = if lang = spec[:lang] - Gollum::Albino.new(code, lang).colorize - else - "
#{CGI.escapeHTML(code)}
" + + formatted = begin + lang && Gollum::Albino.colorize(code, lang) + rescue ::Albino::ShellArgumentError, ::Albino::Process::TimeoutExceeded, + ::Albino::Process::MaximumOutputExceeded end + formatted ||= "
#{CGI.escapeHTML(code)}
" update_cache(:code, id, formatted) formatted end diff --git a/test/test_markup.rb b/test/test_markup.rb index 7d729aba..4ee8bb28 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -343,7 +343,7 @@ context "Markup" do content = "a\n\n```ruby\nx = 1\n```\n\nb" output = "

a

\n\n
" +
              "x = " +
-             "1\n
\n
\n\n

b

" + "1\n\n\n\n\n

b

" index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) @@ -358,7 +358,7 @@ context "Markup" do content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb" output = "

a

\n\n
" +
              "x = " +
-             "1\n
\n
\n\n

b

" + "1\n\n\n\n\n

b

" index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) @@ -374,7 +374,7 @@ context "Markup" do output = "

a

\n\n
" +
              "x = 1" +
              "\n\ny =" +
-             " 2\n
\n
\n\n

b

" + " 2\n\n\n\n\n

b

" compare(content, output) end @@ -383,13 +383,13 @@ context "Markup" do output = "

a

\n\n
" +
              "x = 1" +
              "\n\ny =" +
-             " 2\n
\n
\n\n

b

" + " 2\n\n\n\n\n

b

" compare(content, output) end test "code block with invalid lang" do content = "a\n\n``` ls -al;\n\tbooya\n\tboom\n```\n\nb" - output = "

a

\n\n\n\n

b

" + output = "

a

\n\n
booya\nboom
\n\n

b

" compare(content, output) end From daa07326dff699384718a1ed9caef0f241f54466 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 13 Jan 2011 13:21:14 -0800 Subject: [PATCH 13/23] docs for some of the diffing methods --- lib/gollum/wiki.rb | 69 +++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index d736b6da..68ecfbb2 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -257,6 +257,43 @@ module Gollum sha1 end + # Public: Reverts a reverse diff for a given page. If only 1 SHA is given, + # the reverse diff will be taken from its parent (^SHA...SHA). If two SHAs + # are given, the reverse diff is taken from SHA1...SHA2. + # + # page - The Gollum::Page to delete. + # sha1 - String SHA1 of the earlier parent if two SHAs are given, + # or the child. + # sha2 - Optional String SHA1 of the child. + # commit - The commit Hash details: + # :message - The String commit message. + # :name - The String author full name. + # :email - The String email address. + # + # Returns a String SHA1 of the new commit, or nil if the reverse diff does + # not apply. + def revert_page(page, sha1, sha2 = nil, commit = {}) + if sha2.is_a?(Hash) + commit = sha2 + sha2 = nil + end + + pcommit = @repo.commit('master') + patch = full_reverse_diff_for(page, sha1, sha2) + commit[:parent] = [pcommit] + commit[:tree] = @repo.git.apply_patch(pcommit.sha, patch) + return false unless commit[:tree] + + index = nil + sha1 = commit_index(commit) { |i| index = i } + dir = ::File.dirname(page.path) + dir = '' if dir == '.' + + @access.refresh + update_working_dir(index, dir, page.name, page.format) + sha1 + end + # Public: Lists all pages for this wiki. # # treeish - The String commit ID or ref to find (default: master) @@ -310,28 +347,6 @@ module Gollum @repo.log('master', nil, log_pagination_options(options)) end - def revert_page(page, sha1, sha2 = nil, commit = {}) - if sha2.is_a?(Hash) - commit = sha2 - sha2 = nil - end - - pcommit = @repo.commit('master') - patch = full_reverse_diff_for(page, sha1, sha2) - commit[:parent] = [pcommit] - commit[:tree] = @repo.git.apply_patch(pcommit.sha, patch) - return false unless commit[:tree] - - index = nil - sha1 = commit_index(commit) { |i| index = i } - dir = ::File.dirname(page.path) - dir = '' if dir == '.' - - @access.refresh - update_working_dir(index, dir, page.name, page.format) - sha1 - end - # Public: Refreshes just the cached Git reference data. This should # be called after every Gollum update. # @@ -542,6 +557,8 @@ module Gollum # modification, and then writing the commit. # # options - Hash of option + # + # Returns the String SHA of the new Commit. def commit_index(options = {}) normalize_commit(options) parents = [options[:parent] || @repo.commit('master')] @@ -561,6 +578,14 @@ module Gollum index.commit(options[:message], parents, actor) end + # Creates a reverse diff for the given SHAs on the given Gollum::Page. + # + # page - The Gollum::Page to scope the patch to. + # sha1 - String SHA1 of the earlier parent if two SHAs are given, + # or the child. + # sha2 - Optional String SHA1 of the child. + # + # Returns a String of the reverse Diff to apply. def full_reverse_diff_for(page, sha1, sha2 = nil) sha1, sha2 = "#{sha1}^", sha1 if sha2.nil? repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path) From 710741813b01616c8349b11bf92887f2b220ed06 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 13 Jan 2011 13:22:36 -0800 Subject: [PATCH 14/23] upgrade to grit ~2.4.0 to take advantage of Grit::Process --- gollum.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gollum.gemspec b/gollum.gemspec index 73290aca..22764d55 100644 --- a/gollum.gemspec +++ b/gollum.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.rdoc_options = ["--charset=UTF-8"] s.extra_rdoc_files = %w[README.md LICENSE] - s.add_dependency('grit', "~> 2.3") + s.add_dependency('grit', "~> 2.4.0") s.add_dependency('github-markup', [">= 0.4.0", "< 1.0.0"]) s.add_dependency('albino', "~> 1.2.3") s.add_dependency('sinatra', "~> 1.0") From 002fe8d409849ad655c7e3930bdc359945fe2294 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 13 Jan 2011 13:32:15 -0800 Subject: [PATCH 15/23] add method for getting the reverse diff without a page path --- lib/gollum/wiki.rb | 19 +++++++++++++++++-- test/test_wiki.rb | 37 +++++++++++++------------------------ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 68ecfbb2..7840c1c1 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -580,7 +580,7 @@ module Gollum # Creates a reverse diff for the given SHAs on the given Gollum::Page. # - # page - The Gollum::Page to scope the patch to. + # page - The Gollum::Page to scope the patch to, or a String Path. # sha1 - String SHA1 of the earlier parent if two SHAs are given, # or the child. # sha2 - Optional String SHA1 of the child. @@ -588,7 +588,22 @@ module Gollum # Returns a String of the reverse Diff to apply. def full_reverse_diff_for(page, sha1, sha2 = nil) sha1, sha2 = "#{sha1}^", sha1 if sha2.nil? - repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path) + args = [{:R => true}, sha1, sha2] + if page + args << '--' << (page.respond_to?(:path) ? page.path : page.to_s) + end + repo.git.native(:diff, *args) + end + + # Creates a reverse diff for the given SHAs. + # + # sha1 - String SHA1 of the earlier parent if two SHAs are given, + # or the child. + # sha2 - Optional String SHA1 of the child. + # + # Returns a String of the reverse Diff to apply. + def full_reverse_diff(sha1, sha2 = nil) + full_reverse_diff_for(nil, sha1, sha2) end # Ensures a commit hash has all the required fields for a commit. diff --git a/test/test_wiki.rb b/test/test_wiki.rb index b4766ca2..0702ccc3 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -61,30 +61,6 @@ context "Wiki" do @wiki.normalize_commit(commit.dup)) end - #test "#tree_map_for caches ref and tree" do - # assert @wiki.ref_map.empty? - # assert @wiki.tree_map.empty? - # @wiki.tree_map_for 'master' - # assert_equal({"master"=>"60f12f4254f58801b9ee7db7bca5fa8aeefaa56b"}, @wiki.ref_map) - # - # map = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'] - # assert_equal 'Bilbo-Baggins.md', map[0].path - # assert_equal '', map[0].dir - # assert_equal map[0].path, map[0].name - # assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path - # assert_equal '/Mordor', map[3].dir - # assert_equal 'Eye-Of-Sauron.md', map[3].name - #end - # - #test "#tree_map_for only caches tree for commit" do - # assert @wiki.tree_map.empty? - # @wiki.tree_map_for '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b' - # assert @wiki.ref_map.empty? - # - # entry = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0] - # assert_equal 'Bilbo-Baggins.md', entry.path - #end - test "text_data" do wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git")) if String.instance_methods.include?(:encoding) @@ -97,6 +73,19 @@ context "Wiki" do assert_equal page.raw_data, page.text_data end end + + test "gets reverse diff" do + diff = @wiki.full_reverse_diff('a8ad3c09dd842a3517085bfadd37718856dee813') + assert_match "b/Mordor/_Sidebar.md", diff + assert_match "b/_Sidebar.md", diff + end + + test "gets reverse diff for a page" do + diff = @wiki.full_reverse_diff_for('_Sidebar.md', 'a8ad3c09dd842a3517085bfadd37718856dee813') + regex = /b\/Mordor\/\_Sidebar\.md/ + assert_match "b/_Sidebar.md", diff + assert_no_match regex, diff + end end context "Wiki page previewing" do From e2a4514be56b7d8a18c692323734d47a92260c07 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 13 Jan 2011 15:50:35 -0800 Subject: [PATCH 16/23] add the ability to revert whole commits that touch multiple files --- HISTORY.md | 5 ++-- lib/gollum/page.rb | 59 ++++++++++++++++++++++++---------------- lib/gollum/wiki.rb | 49 +++++++++++++++++++++++++++++---- test/test_page_revert.rb | 17 ++++++++++-- 4 files changed, 96 insertions(+), 34 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e4f977dc..ba09e875 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,12 +2,13 @@ * Major Enhancements * Add Page sidebars, similar to Page footers. + * Add the ability to revert commits to the wiki. * Minor Enhancements - * Add `:sanitization` and `:history_sanitization` options for customizing + * Add `:sanitization` and `:history_sanitization` options for customizing how `Sanitize.clean` modifies formatted wiki content. * Add `--config` option for the command line, to specify a ruby file that is run during startup. - * Provide access to a parsed Nokogiri::DocumentFragment during markup + * Provide access to a parsed Nokogiri::DocumentFragment during markup rendering for added customization. * Bug Fixes * Use `@wiki.page_class` in Gollum::Markup where appropriate (#63). diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index faa5f1a1..61d04484 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -41,6 +41,40 @@ module Gollum filename =~ /^_/ ? false : match end + # Public: The format of a given filename. + # + # filename - The String filename. + # + # Returns the Symbol format of the page. One of: + # [ :markdown | :textile | :rdoc | :org | :rest | :asciidoc | :pod | + # :roff ] + def self.format_for(filename) + case filename.to_s + when /\.(md|mkdn?|mdown|markdown)$/i + :markdown + when /\.(textile)$/i + :textile + when /\.(rdoc)$/i + :rdoc + when /\.(org)$/i + :org + when /\.(creole)$/i + :creole + when /\.(re?st(\.txt)?)$/i + :rest + when /\.(asciidoc)$/i + :asciidoc + when /\.(pod)$/i + :pod + when /\.(\d)$/i + :roff + when /\.(media)?wiki$/i + :mediawiki + else + nil + end + end + # Reusable filter to turn a filename (without path) into a canonical name. # Strips extension, converts spaces to dashes. # @@ -143,30 +177,7 @@ module Gollum # [ :markdown | :textile | :rdoc | :org | :rest | :asciidoc | :pod | # :roff ] def format - case @blob.name - when /\.(md|mkdn?|mdown|markdown)$/i - :markdown - when /\.(textile)$/i - :textile - when /\.(rdoc)$/i - :rdoc - when /\.(org)$/i - :org - when /\.(creole)$/i - :creole - when /\.(re?st(\.txt)?)$/i - :rest - when /\.(asciidoc)$/i - :asciidoc - when /\.(pod)$/i - :pod - when /\.(\d)$/i - :roff - when /\.(media)?wiki$/i - :mediawiki - else - nil - end + self.class.format_for(@blob.name) end # Public: The current version of the page. diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 7840c1c1..c94973eb 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -257,7 +257,7 @@ module Gollum sha1 end - # Public: Reverts a reverse diff for a given page. If only 1 SHA is given, + # Public: Applies a reverse diff for a given page. If only 1 SHA is given, # the reverse diff will be taken from its parent (^SHA...SHA). If two SHAs # are given, the reverse diff is taken from SHA1...SHA2. # @@ -286,14 +286,53 @@ module Gollum index = nil sha1 = commit_index(commit) { |i| index = i } - dir = ::File.dirname(page.path) - dir = '' if dir == '.' - @access.refresh - update_working_dir(index, dir, page.name, page.format) + + files = [] + if page + files << [page.path, page.name, page.format] + else + # Grit::Diff can't parse reverse diffs.... yet + lines = patch.split("\n") + while line = lines.shift + if line =~ %r{^diff --git b/.+? a/(.+)$} + path = $1 + ext = ::File.extname(path) + name = ::File.basename(path, ext) + if format = ::Gollum::Page.format_for(ext) + files << [path, name, format] + end + end + end + end + + files.each do |(path, name, format)| + dir = ::File.dirname(path) + dir = '' if dir == '.' + update_working_dir(index, dir, name, format) + end + sha1 end + # Public: Applies a reverse diff to the repo. If only 1 SHA is given, + # the reverse diff will be taken from its parent (^SHA...SHA). If two SHAs + # are given, the reverse diff is taken from SHA1...SHA2. + # + # sha1 - String SHA1 of the earlier parent if two SHAs are given, + # or the child. + # sha2 - Optional String SHA1 of the child. + # commit - The commit Hash details: + # :message - The String commit message. + # :name - The String author full name. + # :email - The String email address. + # + # Returns a String SHA1 of the new commit, or nil if the reverse diff does + # not apply. + def revert_commit(sha1, sha2 = nil, commit = {}) + revert_page(nil, sha1, sha2, commit) + end + # Public: Lists all pages for this wiki. # # treeish - The String commit ID or ref to find (default: master) diff --git a/test/test_page_revert.rb b/test/test_page_revert.rb index 9f96852f..6dcb4bde 100644 --- a/test/test_page_revert.rb +++ b/test/test_page_revert.rb @@ -12,19 +12,30 @@ context "Page Reverting" do end test "reverts single commit" do + page1 = @wiki.page("B") + sha = @wiki.revert_commit('7c45b5f16ff3bae2a0063191ef832701214d4df5') + page2 = @wiki.page("B") + assert_equal sha, page2.version.sha + assert_equal "INITIAL", body=page2.raw_data.strip + assert_equal body, File.read(File.join(@path, "B.md")).strip + end + + test "reverts single commit for a page" do page1 = @wiki.page('B') sha = @wiki.revert_page(page1, '7c45b5f16ff3bae2a0063191ef832701214d4df5') page2 = @wiki.page('B') assert_equal sha, page2.version.sha - assert_equal "INITIAL", page2.raw_data.strip + assert_equal "INITIAL", body=page2.raw_data.strip + assert_equal body, File.read(File.join(@path, "B.md")).strip end - test "reverts multiple commits" do + test "reverts multiple commits for a page" do page1 = @wiki.page('A') sha = @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2^', 'b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f') page2 = @wiki.page('A') assert_equal sha, page2.version.sha - assert_equal "INITIAL", page2.raw_data.strip + assert_equal "INITIAL", body=page2.raw_data.strip + assert_equal body, File.read(File.join(@path, "A.md")).strip end test "cannot revert conflicting commit" do From dda8a7374f0113e0a5afc3a4b90103570e3c6459 Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Fri, 14 Jan 2011 13:55:49 -0500 Subject: [PATCH 17/23] Clarified a couple of points in the documentation --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5100bb18..acc4b79c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ Gollum wikis are simply Git repositories that adhere to a specific format. Gollum pages may be written in a variety of formats and can be edited in a number of ways depending on your needs. You can edit your wiki locally: -* With your favorite text editor or IDE. +* With your favorite text editor or IDE (changes will be visible after +* committing). * With the built-in web interface. * With the Gollum Ruby API. @@ -268,8 +269,8 @@ This is useful for writing about the link syntax in your wiki pages. ## SYNTAX HIGHLIGHTING In page files you can get automatic syntax highlighting for a wide range of -languages (courtesy of [Pygments](http://pygments.org/)) by using the -following syntax: +languages (courtesy of [Pygments](http://pygments.org/) - must install +separately) by using the following syntax: ```ruby def foo @@ -432,4 +433,4 @@ your changes merged back into core is as follows: 1. Do not change the version number, I will do that on my end 1. If necessary, rebase your commits into logical chunks, without errors 1. Push the branch up to GitHub -1. Send me (mojombo) a pull request for your branch \ No newline at end of file +1. Send me (mojombo) a pull request for your branch From a1876ccd7a007c43539d77d144d80c83c669da22 Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Fri, 14 Jan 2011 13:59:03 -0500 Subject: [PATCH 18/23] Fixed formatting mistake (auto-wrap in vim) --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index acc4b79c..9a5fdaca 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,7 @@ Gollum wikis are simply Git repositories that adhere to a specific format. Gollum pages may be written in a variety of formats and can be edited in a number of ways depending on your needs. You can edit your wiki locally: -* With your favorite text editor or IDE (changes will be visible after -* committing). +* With your favorite text editor or IDE (changes will be visible after committing). * With the built-in web interface. * With the Gollum Ruby API. From 11fcf0c784267ab3bc2b4d50321c4694da103304 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 17 Jan 2011 09:09:00 -0800 Subject: [PATCH 19/23] fix whitespace, remove old no_follow code (nokogiri to the rescue) --- lib/gollum/markup.rb | 67 +++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 7fad4911..5de24de6 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -135,13 +135,11 @@ module Gollum # final markup. # # data - The String data (with placeholders). - # no_follow - Boolean that determines if rel="nofollow" is added to all - #
tags. # # Returns the marked up String data. - def process_tags(data, no_follow = false) + def process_tags(data) @tagmap.each do |id, tag| - data.gsub!(id, process_tag(tag, no_follow)) + data.gsub!(id, process_tag(tag)) end data end @@ -150,17 +148,15 @@ module Gollum # # tag - The String tag contents (the stuff inside the double # brackets). - # no_follow - Boolean that determines if rel="nofollow" is added to all - # tags. # # Returns the String HTML version of the tag. - def process_tag(tag, no_follow = false) + def process_tag(tag) if html = process_image_tag(tag) html - elsif html = process_file_link_tag(tag, no_follow) + elsif html = process_file_link_tag(tag) html else - process_page_link_tag(tag, no_follow) + process_page_link_tag(tag) end end @@ -255,12 +251,10 @@ module Gollum # # tag - The String tag contents (the stuff inside the double # brackets). - # no_follow - Boolean that determines if rel="nofollow" is added to all - # tags. # # Returns the String HTML if the tag is a valid file link tag or nil # if it is not. - def process_file_link_tag(tag, no_follow = false) + def process_file_link_tag(tag) parts = tag.split('|') name = parts[0].strip path = parts[1] && parts[1].strip @@ -272,53 +266,42 @@ module Gollum nil end - tag = if name && path && file + if name && path && file %{#{name}} elsif name && path %{#{name}} else nil end - if tag && no_follow - tag.sub! /^ tags. # # Returns the String HTML if the tag is a valid page link tag or nil # if it is not. - def process_page_link_tag(tag, no_follow = false) - parts = if @format == :mediawiki - tag.split('|').reverse - else - tag.split('|') - end + def process_page_link_tag(tag) + parts = tag.split('|') + parts.reverse! if @format == :mediawiki + name, page_name = *parts.compact.map(&:strip) cname = @wiki.page_class.cname(page_name || name) - tag = if name =~ %r{^https?://} && page_name.nil? - %{#{name}} - else - presence = "absent" - link_name = cname - page, extra = find_page_from_name(cname) - if page - link_name = @wiki.page_class.cname(page.name) - presence = "present" - end - link = ::File.join(@wiki.base_path, CGI.escape(link_name)) - %{#{name}} - end - if tag && no_follow - tag.sub! /^#{name}} + else + presence = "absent" + link_name = cname + page, extra = find_page_from_name(cname) + if page + link_name = @wiki.page_class.cname(page.name) + presence = "present" + end + link = ::File.join(@wiki.base_path, CGI.escape(link_name)) + %{#{name}} end - tag end # Find the given file in the repo. @@ -393,7 +376,7 @@ module Gollum formatted = begin lang && Gollum::Albino.colorize(code, lang) - rescue ::Albino::ShellArgumentError, ::Albino::Process::TimeoutExceeded, + rescue ::Albino::ShellArgumentError, ::Albino::Process::TimeoutExceeded, ::Albino::Process::MaximumOutputExceeded end formatted ||= "
#{CGI.escapeHTML(code)}
" From e77cba96fd2ecf51564121d9e7c48c5ee286bc81 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 17 Jan 2011 10:08:58 -0800 Subject: [PATCH 20/23] add git test fixture for page_file_dir tests --- test/examples/page_file_dir.git/COMMIT_EDITMSG | 1 + test/examples/page_file_dir.git/HEAD | 1 + test/examples/page_file_dir.git/config | 6 ++++++ test/examples/page_file_dir.git/description | 1 + test/examples/page_file_dir.git/index | Bin 0 -> 184 bytes test/examples/page_file_dir.git/info/exclude | 6 ++++++ test/examples/page_file_dir.git/logs/HEAD | 1 + .../page_file_dir.git/logs/refs/heads/master | 1 + .../0c/7d27db1f575263efdcab3dc650f4502a2dbcbf | Bin 0 -> 51 bytes .../22/b404803c966dd92865614d86ff22ca12e50c1e | Bin 0 -> 125 bytes .../25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 | Bin 0 -> 19 bytes .../57/16ca5987cbf97d6bb54920bea6adde242d87e6 | Bin 0 -> 19 bytes .../5b/43e14e0a15fb6f08feab1773d1c0991e9f71e2 | Bin 0 -> 81 bytes test/examples/page_file_dir.git/refs/heads/master | 1 + test/test_wiki.rb | 13 ++----------- 15 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 test/examples/page_file_dir.git/COMMIT_EDITMSG create mode 100644 test/examples/page_file_dir.git/HEAD create mode 100644 test/examples/page_file_dir.git/config create mode 100644 test/examples/page_file_dir.git/description create mode 100644 test/examples/page_file_dir.git/index create mode 100644 test/examples/page_file_dir.git/info/exclude create mode 100644 test/examples/page_file_dir.git/logs/HEAD create mode 100644 test/examples/page_file_dir.git/logs/refs/heads/master create mode 100644 test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf create mode 100644 test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e create mode 100644 test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 create mode 100644 test/examples/page_file_dir.git/objects/57/16ca5987cbf97d6bb54920bea6adde242d87e6 create mode 100644 test/examples/page_file_dir.git/objects/5b/43e14e0a15fb6f08feab1773d1c0991e9f71e2 create mode 100644 test/examples/page_file_dir.git/refs/heads/master diff --git a/test/examples/page_file_dir.git/COMMIT_EDITMSG b/test/examples/page_file_dir.git/COMMIT_EDITMSG new file mode 100644 index 00000000..80260766 --- /dev/null +++ b/test/examples/page_file_dir.git/COMMIT_EDITMSG @@ -0,0 +1 @@ +initial commit diff --git a/test/examples/page_file_dir.git/HEAD b/test/examples/page_file_dir.git/HEAD new file mode 100644 index 00000000..cb089cd8 --- /dev/null +++ b/test/examples/page_file_dir.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/examples/page_file_dir.git/config b/test/examples/page_file_dir.git/config new file mode 100644 index 00000000..af107929 --- /dev/null +++ b/test/examples/page_file_dir.git/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true diff --git a/test/examples/page_file_dir.git/description b/test/examples/page_file_dir.git/description new file mode 100644 index 00000000..498b267a --- /dev/null +++ b/test/examples/page_file_dir.git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/examples/page_file_dir.git/index b/test/examples/page_file_dir.git/index new file mode 100644 index 0000000000000000000000000000000000000000..85640369ae5c970ee4d03af38fcc72706d9533fd GIT binary patch literal 184 zcmZ?q402{*U|<4aUz1i*Ak6@y`9R`w6V5X*G%jIaVEhV{5&>eCaIsU7?Wcd%W^eUW z*tcx$Jr&*dXAEpfiA8$3DNy|~$TZZP2k7Rg)*MaI*|;F&L(d6&-6?iqf9>|oWZ+K8 kPcGI^%g=`z1~h0%^ol?07OpuhH$y(+#*Fq#! 1295287591 -0800 commit (initial): initial commit diff --git a/test/examples/page_file_dir.git/logs/refs/heads/master b/test/examples/page_file_dir.git/logs/refs/heads/master new file mode 100644 index 00000000..60cde1b1 --- /dev/null +++ b/test/examples/page_file_dir.git/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 22b404803c966dd92865614d86ff22ca12e50c1e rick 1295287591 -0800 commit (initial): initial commit diff --git a/test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf b/test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf new file mode 100644 index 0000000000000000000000000000000000000000..bffaebf088838d419fe6c782c8a8428975c607c8 GIT binary patch literal 51 zcmV-30L=e*0V^p=O;s>9VK6i>Ff%bxNXyUH%S~ZWtvQ;avvEPlhn^Gmx>M}J{@U%E J2>>0$56}JD7Tf>; literal 0 HcmV?d00001 diff --git a/test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e b/test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e new file mode 100644 index 0000000000000000000000000000000000000000..a52143a15a5d758e787842f20a42bf928bc7d223 GIT binary patch literal 125 zcmV-@0D}K`0hNtW3IZVzK>PL-bAiIqH5HcVDr#dpv?|C%*KeT{^!wnwS4L|rfZm>D z5`oK$C0s}+bTwbA4wX_y@9hJNju9zVk7QJO%QhxVE-zSx%GSq+s59N4E%AOSqul^a fbS8Kg5zabjtqywZg#H#4cNR`N{0iy|ok}?yi;y-< literal 0 HcmV?d00001 diff --git a/test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 b/test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 new file mode 100644 index 0000000000000000000000000000000000000000..bdcf704c9e663f3a11b3146b1b455bc2581b4761 GIT binary patch literal 19 acmb6WiT`_Ff%bxNJ=cy%S~Yj7dsW%e)?x^_Et}YeaqI~Q_*dI nW?}#Y3Mu)?#SA>P>bK>?gOcChS#5hP;7fp(?w @page_file_dir) end @@ -318,7 +309,7 @@ context "page_file_dir option" do end test "search results should be restricted in page filer dir" do - results = @wiki.search("Hello") + results = @wiki.search("foo") assert_equal 1, results.size assert_equal "foo", results[0][:name] end From a9d4e117aa8dd9f4919d4fc935090145ec64c104 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 17 Jan 2011 10:17:14 -0800 Subject: [PATCH 21/23] fix markup formatting edge case --- lib/gollum/markup.rb | 4 ++++ test/test_markup.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 0067d367..dbb6f4b8 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -179,6 +179,8 @@ module Gollum # if it is not. def process_image_tag(tag) parts = tag.split('|') + return if parts.size.zero? + name = parts[0].strip path = if file = find_file(name) ::File.join @wiki.base_path, file.path @@ -267,6 +269,8 @@ module Gollum # if it is not. def process_file_link_tag(tag) parts = tag.split('|') + return if parts.size.zero? + name = parts[0].strip path = parts[1] && parts[1].strip path = if path && file = find_file(path) diff --git a/test/test_markup.rb b/test/test_markup.rb index 9c52f4ac..4f759ca3 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -446,6 +446,18 @@ context "Markup" do compare(content, output, 'org') end + test "short double links" do + content = "a [[b]] c" + output = %(

a b c

) + compare(content, output, 'org') + end + + test "double linked pipe" do + content = "a [[|]] b" + output = %(

a b

) + compare(content, output, 'org') + end + ######################################################################### # # TeX From 1150303f77bd70c4cb11cd8e910fcab15556e1f3 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 17 Jan 2011 10:21:22 -0800 Subject: [PATCH 22/23] update history --- HISTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index ba09e875..79c20873 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,7 @@ * Major Enhancements * Add Page sidebars, similar to Page footers. * Add the ability to revert commits to the wiki. + * Add MediaWiki support. * Minor Enhancements * Add `:sanitization` and `:history_sanitization` options for customizing how `Sanitize.clean` modifies formatted wiki content. @@ -12,6 +13,7 @@ rendering for added customization. * Bug Fixes * Use `@wiki.page_class` in Gollum::Markup where appropriate (#63). + * Fix parsing of Org mode file links (#87). # 1.1.0 / 2010-10-28 From e1f92e3ca2c209ddfbcbf1e0d4f6cffe10e26e44 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 17 Jan 2011 10:30:26 -0800 Subject: [PATCH 23/23] update readme with new features --- README.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9a5fdaca..04685350 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ to install the dependencies for the formats that you plan to use. * [RDoc](http://rdoc.sourceforge.net/) * [ReStructuredText](http://docutils.sourceforge.net/rst.html) -- `easy_install docutils` * [Textile](http://www.textism.com/tools/textile/) -- `gem install RedCloth` +* [MediaWiki](http://www.mediawiki.org/wiki/Help:Formatting) -- `gem install wikicloth` ## RUNNING @@ -74,6 +75,7 @@ current list of formats and allowed extensions is: * RDoc: .rdoc * ReStructuredText: .rest.txt, .rst.txt, .rest, .rst * Textile: .textile +* MediaWiki: .mediawiki, .wiki Gollum detects the page file format via the extension, so files must have one of the supported extensions in order to be converted. @@ -90,13 +92,19 @@ The special page file `Home.ext` (where the extension is one of the supported formats) will be used as the entrance page to your wiki. If it is missing, an automatically generated table of contents will be shown instead. +## SIDEBAR FILES + +Sidebar files allow you to add a simple sidebar to your wiki. Sidebar files +are named `_Sidebar.ext` where the extension is one of the supported formats. +Sidebars affect all pages in their directory and any subdirectories that do not +have a sidebar file of their own. ## FOOTER FILES Footer files allow you to add a simple footer to your wiki. Footer files must be named `_Footer.ext` where the extension is one of the supported formats. -Footers affect all pages in their directory and any subdirectories that do not -have a footer file of their own. +Like sidebars, footers affect all pages in their directory and any +subdirectories that do not have a footer file of their own. ## HTML SANITIZATION @@ -124,6 +132,9 @@ the link text displayed on the page. If the tag is an embedded image, the first thing in the tag will be a path to an image file. Use this trick to easily remember which order things should appear in tags. +Some formats, such as MediaWiki, support the opposite syntax: + + [[Page Title|Link]] ## PAGE LINKS @@ -210,7 +221,7 @@ the pipe. ## IMAGES To display images that are contained in the Gollum repository you should use -the Gollum Image Tag. This will display the actual image on the page. +the Gollum Image Tag. This will display the actual image on the page. [[gollum.png]] @@ -432,4 +443,4 @@ your changes merged back into core is as follows: 1. Do not change the version number, I will do that on my end 1. If necessary, rebase your commits into logical chunks, without errors 1. Push the branch up to GitHub -1. Send me (mojombo) a pull request for your branch +1. Send a pull request to the github/gollum project.