From 8301428974c5729b2adebefc34e6eb43fb4c68e9 Mon Sep 17 00:00:00 2001 From: Henrik Hansen Date: Sun, 29 Aug 2010 10:08:08 +0200 Subject: [PATCH 01/13] Add sections to clean up markup test code --- test/test_markup.rb | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/test_markup.rb b/test/test_markup.rb index 8b3b4579..9744d3d5 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -21,6 +21,12 @@ context "Markup" do assert @wiki.pages[0].formatted_data end + ######################################################################### + # + # Links + # + ######################################################################### + test "double page links no space" do @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", @commit) @@ -100,6 +106,12 @@ context "Markup" do assert_equal "

a http://example.com b

", page.formatted_data end + ######################################################################### + # + # Images + # + ######################################################################### + test "image with http url" do ['http', 'https'].each do |scheme| name = "Bilbo Baggins #{scheme}" @@ -217,6 +229,12 @@ context "Markup" do relative_image(content, output) end + ######################################################################### + # + # File links + # + ######################################################################### + test "file link with absolute path" do index = @wiki.repo.index index.add("alpha.jpg", "hi") @@ -248,6 +266,12 @@ context "Markup" do assert_equal %{

a Alpha b

}, page.formatted_data end + ######################################################################### + # + # Code + # + ######################################################################### + test "code blocks" do content = "a\n\n```ruby\nx = 1\n```\n\nb" output = "

a

\n\n
" +
@@ -296,6 +320,12 @@ context "Markup" do
     compare(content, output)
   end
 
+  #########################################################################
+  #
+  # Various
+  #
+  #########################################################################
+
   test "escaped wiki link" do
     content = "a '[[Foo]], b"
     output = "

a [[Foo]], b

" @@ -317,6 +347,12 @@ context "Markup" do compare(content, output, 'org') end + ######################################################################### + # + # TeX + # + ######################################################################### + test "tex block syntax" do content = 'a \[ a^2 \] b' output = "

a b

" @@ -329,6 +365,12 @@ context "Markup" do compare(content, output, 'md') end + ######################################################################### + # + # Helpers + # + ######################################################################### + def compare(content, output, ext = "md", regexes = []) index = @wiki.repo.index index.add("Bilbo-Baggins.#{ext}", content) @@ -353,4 +395,4 @@ context "Markup" do rendered = Gollum::Markup.new(page).render assert_equal output, rendered end -end \ No newline at end of file +end From 959f02b50ed1d97a2c5a4aec4d50872d636a8ac3 Mon Sep 17 00:00:00 2001 From: Henrik Hansen Date: Sun, 29 Aug 2010 14:26:14 +0200 Subject: [PATCH 02/13] Use correct capitalization of TeX --- test/test_markup.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_markup.rb b/test/test_markup.rb index 9744d3d5..b93e8b6e 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -353,13 +353,13 @@ context "Markup" do # ######################################################################### - test "tex block syntax" do + test "TeX block syntax" do content = 'a \[ a^2 \] b' output = "

a b

" compare(content, output, 'md') end - test "tex inline syntax" do + test "TeX inline syntax" do content = 'a \( a^2 \) b' output = "

a b

" compare(content, output, 'md') From 50e9a42503e5ec3f60e5390fbee4f42827ed3d34 Mon Sep 17 00:00:00 2001 From: Paul Baumgart Date: Thu, 2 Sep 2010 20:30:13 -0700 Subject: [PATCH 03/13] fix documentation for Wiki.size --- lib/gollum/wiki.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 4770bec3..d6037183 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -224,11 +224,11 @@ module Gollum tree_list(treeish || 'master') end - # Fill an array with a list of pages. + # Public: Returns the number of pages accessible from a commit # # ref - A String ref that is either a commit SHA or references one. # - # Returns a flat Array of Gollum::Page instances. + # Returns a Fixnum def size(ref = nil) tree_map_for(ref || 'master').inject(0) do |num, entry| num + (@page_class.valid_page_name?(entry.name) ? 1 : 0) From 42bd6c221acd13021c59a79f4180e8daa948d0fd Mon Sep 17 00:00:00 2001 From: rick Date: Fri, 3 Sep 2010 10:59:30 -0700 Subject: [PATCH 04/13] invalid shas return empty treemaps --- lib/gollum/wiki.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index d6037183..16c4ed24 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -471,6 +471,8 @@ module Gollum @ref_map[ref] = real_sha if real_sha != ref @tree_map[real_sha] ||= parse_tree_for(real_sha) end + rescue Grit::GitRuby::Repository::NoSuchShaFound + [] end # Finds the full listing of files and their blob SHA for a given commit From e774ceaf1fcd7aa496c2174860ea13364e6840c7 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 12 Sep 2010 20:04:21 -0700 Subject: [PATCH 05/13] dont bomb when trying to find a page with a blank name --- lib/gollum/page.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index f2b7f1c2..3f1ce55f 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -264,11 +264,13 @@ module Gollum # # Returns a Gollum::Page or nil if the page could not be found. def find_page_in_tree(map, name, checked_dir = nil) + return nil if name.blank? if checked_dir = BlobEntry.normalize_dir(checked_dir) checked_dir.downcase! end map.each do |entry| + next if entry.name.blank? next unless checked_dir.nil? || entry.dir.downcase == checked_dir next unless page_match(name, entry.name) return entry.page(@wiki, @version) From 430436ce8d5378913280c79e097faf12b3624305 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 13 Sep 2010 15:48:54 -0700 Subject: [PATCH 06/13] handle non strings passed to Page.cname --- lib/gollum/page.rb | 4 +++- test/test_page.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 3f1ce55f..4ef8d1bc 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -202,7 +202,9 @@ module Gollum # # Returns the String canonical name. def self.cname(name) - name.gsub(%r{[ /<>]}, '-') + name.respond_to?(:gsub) ? + name.gsub(%r{[ /<>]}, '-') : + '' end # Convert a format Symbol into an extension String. diff --git a/test/test_page.rb b/test/test_page.rb index 0df52ecf..1316c713 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -110,4 +110,9 @@ context "Page" do footer = @wiki.page("_Footer") assert_nil footer.footer end + + test "cannot convert non string to human readable page title" do + assert_equal '', Gollum::Page.cname(nil) + assert_equal '', Gollum::Page.cname(3) + end end From d51f42e647d7f87ace99877605a4b15bf61caabe Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 13 Sep 2010 15:49:03 -0700 Subject: [PATCH 07/13] theres no blank? in ruby --- lib/gollum/page.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 4ef8d1bc..67e87cb6 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -266,13 +266,13 @@ module Gollum # # Returns a Gollum::Page or nil if the page could not be found. def find_page_in_tree(map, name, checked_dir = nil) - return nil if name.blank? + return nil if name.to_s.empty? if checked_dir = BlobEntry.normalize_dir(checked_dir) checked_dir.downcase! end map.each do |entry| - next if entry.name.blank? + next if entry.name.to_s.empty? next unless checked_dir.nil? || entry.dir.downcase == checked_dir next unless page_match(name, entry.name) return entry.page(@wiki, @version) From 9cc8790d4fa3f672081ba2a617cbef26105e9411 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 13 Sep 2010 16:09:05 -0700 Subject: [PATCH 08/13] history lesson --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index 29a7344d..9d9c8dbe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -19,6 +19,7 @@ anonymous info. * Prevent `Gollum::Wiki#write_page` from clobbering existing pages. * Handle duplicate page errors in frontend. + * Fix bugs trying to retrieve pages with invalid names. # 1.0.1 / 2010-08-12 From 48bfe954d16544685732f3676ed6d37ab4766397 Mon Sep 17 00:00:00 2001 From: Emilien Taque Date: Wed, 15 Sep 2010 22:53:15 +0200 Subject: [PATCH 09/13] add Sinatra --bind option through gollum binary --- bin/gollum | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/gollum b/bin/gollum index 4e257208..2ee57861 100755 --- a/bin/gollum +++ b/bin/gollum @@ -26,6 +26,10 @@ opts = OptionParser.new do |opts| options['port'] = port.to_i end + opts.on("--bind [HOST]", "Hostname or IP address to listen on (default 0.0.0.0).") do |host| + options['bind'] = host + end + opts.on("--version", "Display current version.") do puts "Gollum " + Gollum::VERSION exit 0 From e37a8b9da473cb0301d40be28b72e15b0bee31d1 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 16 Sep 2010 09:16:42 -0700 Subject: [PATCH 10/13] Gollum::Wiki#pages come back sorted by title, not permalink or the default ordering from `git ls-tree`. --- lib/gollum/wiki.rb | 4 +++- .../30/8fdf72d89351bf53fa6eeb00884273047e07fa | 2 ++ .../eb/578ff8ed46c6cc579d1a474fb2b94487f420fd | Bin 0 -> 259 bytes .../ed/d74f8d7f6d025d66eb67411c5db60959ae16fd | Bin 0 -> 35 bytes test/examples/lotr.git/refs/heads/master | 2 +- test/test_wiki.rb | 16 ++++++++-------- 6 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 test/examples/lotr.git/objects/30/8fdf72d89351bf53fa6eeb00884273047e07fa create mode 100644 test/examples/lotr.git/objects/eb/578ff8ed46c6cc579d1a474fb2b94487f420fd create mode 100644 test/examples/lotr.git/objects/ed/d74f8d7f6d025d66eb67411c5db60959ae16fd diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 16c4ed24..afdf2432 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -221,7 +221,9 @@ module Gollum # # Returns an Array of Gollum::Page instances. def pages(treeish = nil) - tree_list(treeish || 'master') + tree_list(treeish || 'master').sort! do |x, y| + x.title.downcase <=> y.title.downcase + end end # Public: Returns the number of pages accessible from a commit diff --git a/test/examples/lotr.git/objects/30/8fdf72d89351bf53fa6eeb00884273047e07fa b/test/examples/lotr.git/objects/30/8fdf72d89351bf53fa6eeb00884273047e07fa new file mode 100644 index 00000000..c32de7a4 --- /dev/null +++ b/test/examples/lotr.git/objects/30/8fdf72d89351bf53fa6eeb00884273047e07fa @@ -0,0 +1,2 @@ +x[ +0@QـyD$AH:=pᖾM$(UJ(ǹtqyv.EvVsUo 3Q9悞1!#~Vp*Fe䂟dᬣcOPa!m[@hrH \ No newline at end of file diff --git a/test/examples/lotr.git/objects/eb/578ff8ed46c6cc579d1a474fb2b94487f420fd b/test/examples/lotr.git/objects/eb/578ff8ed46c6cc579d1a474fb2b94487f420fd new file mode 100644 index 0000000000000000000000000000000000000000..ac381fc686fc02d1b598e779622e31abd3f8eeb3 GIT binary patch literal 259 zcmV+e0sQ`W0V^p=O;s>5vt%$dFfcPQQEYF!db67`ac%NP!Cv765^Et{jSigD5tv+XNdLiAXnYCQ6DQ}s$x zD@rnRQW<_de;@3kpuNjcbM+lzHr`3oZ%#=yF#rMu-~6JK{2~Sw&qEo~Yya9v%IM|0CTHfCf}OQ$oBWHpVLuXmxEcd*nf$c8^Y&K;RAszdett=6 z5yeJ)dM+Us;jnb>Wdk?X|% J0sy`NYkFF0f7Jj0 literal 0 HcmV?d00001 diff --git a/test/examples/lotr.git/objects/ed/d74f8d7f6d025d66eb67411c5db60959ae16fd b/test/examples/lotr.git/objects/ed/d74f8d7f6d025d66eb67411c5db60959ae16fd new file mode 100644 index 0000000000000000000000000000000000000000..b0c2bb523dab58e5913f7865e1b96bb9eb24df07 GIT binary patch literal 35 rcmb 2).map { |c| c.id } end - test "list pages" do + test "list pages, sorted by title" do pages = @wiki.pages assert_equal \ - %w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile My-Precious.md), - pages.map { |p| p.filename }.sort + %w(bilbo.md Bilbo-Baggins.md Eye-Of-Sauron.md My-Precious.md Home.textile), + pages.map { |p| p.filename } end test "counts pages" do - assert_equal 4, @wiki.size + assert_equal 5, @wiki.size end test "normalizes commit hash" do @@ -64,9 +64,9 @@ context "Wiki" do assert @wiki.ref_map.empty? assert @wiki.tree_map.empty? @wiki.tree_map_for 'master' - assert_equal({"master"=>"60f12f4254f58801b9ee7db7bca5fa8aeefaa56b"}, @wiki.ref_map) + assert_equal({"master"=>"308fdf72d89351bf53fa6eeb00884273047e07fa"}, @wiki.ref_map) - map = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'] + map = @wiki.tree_map['308fdf72d89351bf53fa6eeb00884273047e07fa'] assert_equal 'Bilbo-Baggins.md', map[0].path assert_equal '', map[0].dir assert_equal map[0].path, map[0].name @@ -77,10 +77,10 @@ context "Wiki" do test "#tree_map_for only caches tree for commit" do assert @wiki.tree_map.empty? - @wiki.tree_map_for '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b' + @wiki.tree_map_for '308fdf72d89351bf53fa6eeb00884273047e07fa' assert @wiki.ref_map.empty? - entry = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0] + entry = @wiki.tree_map['308fdf72d89351bf53fa6eeb00884273047e07fa'][0] assert_equal 'Bilbo-Baggins.md', entry.path end end From 4bb7d538540a54a8bf9818e6627e81641b5fd558 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 16 Sep 2010 09:23:02 -0700 Subject: [PATCH 11/13] history update --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index 9d9c8dbe..71291090 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ * Support a `:gollum_path` Sinatra setting for `Precious::App` * Add Wiki#size to efficiently count pages without loading them. * Add the correct content type when serving files from the frontend. + * Wiki#pages come back sorted by Page#title. * Bug Fixes * Increase minimum Sanitize version requirement to 1.1.0. 1.0.x versions of Sanitize require Hpricot instead of Nokogiri From ee6b71ff80c7c215e463c45b908907d7a2bbb223 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Wed, 29 Sep 2010 14:40:36 -0700 Subject: [PATCH 12/13] Change 'bind' CLI option to 'host'. Set default to 127.0.0.1. Closes #47. --- HISTORY.md | 1 + bin/gollum | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 71291090..58db2e6a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,7 @@ * Add Wiki#size to efficiently count pages without loading them. * Add the correct content type when serving files from the frontend. * Wiki#pages come back sorted by Page#title. + * Add --host option and default it to 127.0.0.1. * Bug Fixes * Increase minimum Sanitize version requirement to 1.1.0. 1.0.x versions of Sanitize require Hpricot instead of Nokogiri diff --git a/bin/gollum b/bin/gollum index 2ee57861..d3a73ffe 100755 --- a/bin/gollum +++ b/bin/gollum @@ -18,7 +18,7 @@ require 'rubygems' require 'gollum' exec = {} -options = {} +options = { 'bind' => '127.0.0.1' } opts = OptionParser.new do |opts| opts.banner = help @@ -26,7 +26,7 @@ opts = OptionParser.new do |opts| options['port'] = port.to_i end - opts.on("--bind [HOST]", "Hostname or IP address to listen on (default 0.0.0.0).") do |host| + opts.on("--host [HOST]", "Hostname or IP address to listen on (default 0.0.0.0).") do |host| options['bind'] = host end From 42985dc5c1a8758adc7bd7118f7b90276f382de4 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Wed, 29 Sep 2010 14:42:24 -0700 Subject: [PATCH 13/13] Explicitly set default port to 4567. --- bin/gollum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/gollum b/bin/gollum index d3a73ffe..86ac7622 100755 --- a/bin/gollum +++ b/bin/gollum @@ -8,7 +8,7 @@ Gollum is a multi-format Wiki Engine/API/Frontend. Basic Command Line Usage: gollum [OPTIONS] [PATH] - PATH The path to the Gollum repository. + PATH The path to the Gollum repository (default .). Options: HELP @@ -18,7 +18,7 @@ require 'rubygems' require 'gollum' exec = {} -options = { 'bind' => '127.0.0.1' } +options = { 'port' => 4567, 'bind' => '127.0.0.1' } opts = OptionParser.new do |opts| opts.banner = help