diff --git a/HISTORY.md b/HISTORY.md index 29a7344d..58db2e6a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,8 @@ * 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. + * 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 @@ -19,6 +21,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 diff --git a/bin/gollum b/bin/gollum index 4e257208..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 = {} +options = { 'port' => 4567, 'bind' => '127.0.0.1' } opts = OptionParser.new do |opts| opts.banner = help @@ -26,6 +26,10 @@ opts = OptionParser.new do |opts| options['port'] = port.to_i end + opts.on("--host [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 diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index f2b7f1c2..67e87cb6 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. @@ -264,11 +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.to_s.empty? if checked_dir = BlobEntry.normalize_dir(checked_dir) checked_dir.downcase! end map.each do |entry| + 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) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 4770bec3..afdf2432 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -221,14 +221,16 @@ 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 - # 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) @@ -471,6 +473,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 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 00000000..ac381fc6 Binary files /dev/null and b/test/examples/lotr.git/objects/eb/578ff8ed46c6cc579d1a474fb2b94487f420fd differ diff --git a/test/examples/lotr.git/objects/ed/d74f8d7f6d025d66eb67411c5db60959ae16fd b/test/examples/lotr.git/objects/ed/d74f8d7f6d025d66eb67411c5db60959ae16fd new file mode 100644 index 00000000..b0c2bb52 Binary files /dev/null and b/test/examples/lotr.git/objects/ed/d74f8d7f6d025d66eb67411c5db60959ae16fd differ diff --git a/test/examples/lotr.git/refs/heads/master b/test/examples/lotr.git/refs/heads/master index 3f114d47..96bb51f5 100644 --- a/test/examples/lotr.git/refs/heads/master +++ b/test/examples/lotr.git/refs/heads/master @@ -1 +1 @@ -60f12f4254f58801b9ee7db7bca5fa8aeefaa56b \ No newline at end of file +308fdf72d89351bf53fa6eeb00884273047e07fa diff --git a/test/test_markup.rb b/test/test_markup.rb index 0a3e6649..c8c7a3d3 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -17,6 +17,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_details) @@ -96,6 +102,12 @@ context "Markup" do assert_equal "
", page.formatted_data end + ######################################################################### + # + # Images + # + ######################################################################### + test "image with http url" do ['http', 'https'].each do |scheme| name = "Bilbo Baggins #{scheme}" @@ -213,6 +225,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") @@ -244,6 +262,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" +
@@ -292,6 +316,12 @@ context "Markup" do
compare(content, output)
end
+ #########################################################################
+ #
+ # Various
+ #
+ #########################################################################
+
test "escaped wiki link" do
content = "a '[[Foo]], b"
output = "a [[Foo]], b
"
@@ -313,18 +343,30 @@ context "Markup" do
compare(content, output, 'org')
end
- test "tex block syntax" do
+ #########################################################################
+ #
+ # TeX
+ #
+ #########################################################################
+
+ 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')
end
+ #########################################################################
+ #
+ # Helpers
+ #
+ #########################################################################
+
def compare(content, output, ext = "md", regexes = [])
index = @wiki.repo.index
index.add("Bilbo-Baggins.#{ext}", content)
@@ -350,4 +392,4 @@ context "Markup" do
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
end
-end
\ No newline at end of file
+end
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
diff --git a/test/test_wiki.rb b/test/test_wiki.rb
index 51cd287b..5e769f43 100644
--- a/test/test_wiki.rb
+++ b/test/test_wiki.rb
@@ -32,15 +32,15 @@ context "Wiki" do
assert_equal commits, @wiki.log(:page => 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