From 4e3b4e23da4f966e64c5054b73eedf816c4e648d Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Sat, 14 Aug 2010 07:42:36 +0000 Subject: [PATCH] Ruby 1.9 compatibility * Adds current directory to load path for tests because 1.9 does not * Aliases String#lines to String#to_a under 1.8 to match 1.9 behavior * Sets encoding magic comment in test file with characters outside ascii * Require 'ostruct' explicitly This depends on a patch to Grit to have full functionality through the whole stack. --- Rakefile | 4 ++-- lib/gollum.rb | 4 ++++ lib/gollum/markup.rb | 4 ++-- lib/gollum/ruby1.8.rb | 3 +++ lib/gollum/wiki.rb | 2 +- test/test_page.rb | 3 ++- 6 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 lib/gollum/ruby1.8.rb diff --git a/Rakefile b/Rakefile index 81fbce0b..ca153db9 100644 --- a/Rakefile +++ b/Rakefile @@ -47,7 +47,7 @@ task :default => :test require 'rake/testtask' Rake::TestTask.new(:test) do |test| - test.libs << 'lib' << 'test' + test.libs << 'lib' << 'test' << '.' test.pattern = 'test/**/test_*.rb' test.verbose = true end @@ -143,4 +143,4 @@ task :validate do puts "A `VERSION` file at root level violates Gem best practices." exit! end -end \ No newline at end of file +end diff --git a/lib/gollum.rb b/lib/gollum.rb index 4b8c44f7..f4b82ca7 100644 --- a/lib/gollum.rb +++ b/lib/gollum.rb @@ -1,11 +1,15 @@ # stdlib require 'digest/md5' +require 'ostruct' # external require 'grit' require 'github/markup' require 'sanitize' +# ruby 1.8 compatibility +require 'gollum/ruby1.8' + # internal require 'gollum/pagination' require 'gollum/wiki' diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 0a6fe3a9..6359c528 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -320,7 +320,7 @@ module Gollum @codemap.each do |id, spec| lang = spec[:lang] code = spec[:code] - if code.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ } + if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ } code.gsub!(/^( |\t)/m, '') end data.gsub!(id, Gollum::Albino.new(code, lang).colorize) @@ -328,4 +328,4 @@ module Gollum data end end -end \ No newline at end of file +end diff --git a/lib/gollum/ruby1.8.rb b/lib/gollum/ruby1.8.rb new file mode 100644 index 00000000..d24d5f29 --- /dev/null +++ b/lib/gollum/ruby1.8.rb @@ -0,0 +1,3 @@ +class String + alias :lines :to_a if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9' +end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 09df6bd1..d4d68b6e 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -332,4 +332,4 @@ module Gollum map end end -end \ No newline at end of file +end diff --git a/test/test_page.rb b/test/test_page.rb index 6f2376e9..0df52ecf 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ require File.join(File.dirname(__FILE__), *%w[helper]) context "Page" do @@ -109,4 +110,4 @@ context "Page" do footer = @wiki.page("_Footer") assert_nil footer.footer end -end \ No newline at end of file +end