Compare commits

..

51 Commits

Author SHA1 Message Date
risk c7729f81ad Release 1.3.1 2011-07-21 16:30:59 -07:00
risk 7e12de0087 tomdoc 2011-07-21 16:19:48 -07:00
risk c9c7db5a53 add backwards compatible Gollum::Wiki.markup_class 2011-07-21 16:17:09 -07:00
risk aadbdd8b76 keep the versions of rake in the gemspec and gemfile in sync for cry babies 2011-07-21 16:04:08 -07:00
risk b2d372ab3c id attribute transformers should always return a hash or nil 2011-07-21 15:47:00 -07:00
risk c47a47bc30 disable notifications 2011-07-21 15:43:03 -07:00
risk ad5ec77f41 smaller #inspect output for wiki and page objects 2011-07-21 15:27:56 -07:00
risk c0bf387cb4 requiring gollum doesnt require the load path to be set to the lib directory ahead of time (good for rake console) 2011-07-21 15:27:34 -07:00
risk 267323c7c3 merge gfm 2011-07-21 15:04:50 -07:00
risk d9b1ea3d51 track builds in travis-ci 2011-07-21 14:53:05 -07:00
risk 70bf86f561 specify rake gem in gemfile 2011-07-21 14:53:05 -07:00
rick e1eebb2f75 Merge pull request #182 from schacon/test-fixes
Fixing Tests
2011-07-21 14:37:58 -07:00
Scott Chacon aa258dbe6b fix test breaking due to new footnote anchor 2011-07-19 12:55:43 -07:00
Scott Chacon 5a7659e1c3 fix tests breaking due to whitespace issues 2011-07-19 12:55:19 -07:00
Scott Chacon d51a829038 rake is needed to run the tests in dev 2011-07-19 12:54:13 -07:00
Ryan Tomayko b7ffc4051c Wiki#tree_list returns an empty array if the ref doesnt resolve
Signed-off-by: risk <technoweenie@gmail.com>
2011-07-14 14:35:58 -07:00
risk bb06b566cd GitAccess#ref_to_sha should never return a blank string 2011-07-14 14:30:23 -07:00
Vicent Marti fc6149a171 Bless Gollum with the power of GFM
With these changes, the Markdown rendered in Gollum wikis will have the
same quality and safety as the MD we render everywhere else @ GitHub.

This commit also changes the old `markup_class` accessor to
`markup_classes`, allowing users to specify a custom Markup class for
each markup language.
2011-06-21 18:28:28 +02:00
rick 4abc32f1ec Merge pull request #143 from kashif/patch-1
Fixed spelling.
2011-06-20 09:18:22 -07:00
rick efd734d962 Merge pull request #162 from ttscoff/master
Spacing fix for issue #145
2011-06-20 09:17:59 -07:00
rick 8158610587 Merge pull request #164 from arr2036/patches_1.3.0
Remove edit button on preview pages
2011-06-20 09:15:38 -07:00
rick 2bb62309be Merge pull request #157 from nealpoole/master
Fixed broken preview functionality
2011-06-20 09:15:23 -07:00
rick 401e41b699 Merge pull request #169 from JoshCheek/fix_page_file_dir_option
Fix page_file_dir option
2011-06-07 23:44:51 -07:00
Josh Cheek 3015831d66 fix bug where can't edit pages while using page_file_dir 2011-06-07 22:47:01 -05:00
Josh Cheek c2919897e2 add test that fails when editing pages while using page_file_dir 2011-06-07 22:45:41 -05:00
Arran Cudbard-Bell 83d6cae53f Remove edit button on preview pages 2011-05-26 21:35:34 -07:00
Brett Terpstra 7ad54e3c94 Added spacing to allow has-rightbar and has-footer classes to work 2011-05-23 13:12:47 -05:00
Neal Poole c1fc3a92c0 Fixed broken preview functionality in Gollum. 2011-05-16 17:10:08 -04:00
Aman Gupta 23508d3867 Merge pull request #153 from guilleiguaran/patch-1
default_executable= have been deprecated
2011-05-08 22:43:00 -07:00
Guillermo Iguaran b5cb2e6dd6 default_executable= have been deprecated 2011-05-08 22:38:24 -07:00
rick 1ff486e16c Merge pull request #146 from schuyler1d/master
allow prefixed @id attributes to allow internal linking
2011-05-06 03:51:13 -07:00
Schuyler Duveen c22050fca8 allow @id attributes but force a "wiki-" prefix 2011-05-04 11:50:38 -04:00
Kashif Rasul e910dd0ccf Fixed spelling. 2011-05-02 07:15:11 -07:00
rick 748d76dff1 Release 1.3.0 2011-04-25 20:59:57 -04:00
rick 2ebed41225 Merge branch 'master' of github.com:github/gollum 2011-04-25 20:47:46 -04:00
rick 86d14fa7ab Merged pull request #134 from mrjbq7/master.
Fixing search box location.
2011-04-25 11:38:01 -07:00
rick 82e31e971a Merged pull request #136 from freerange/master.
Remove redundant 1.8 compatibilty
2011-04-25 11:37:21 -07:00
Chris Roos 3d591b49cb Updated the gemspec.
Commit df505a7289 removed ruby1.8.rb but it was still included in the gemspec which caused Bundler to complain about an invalid Gemspec.

*NOTE* There are five test failures when running 'rake'.  I checked out the last commit before Tom's change (d3594f6652) and that also has these five failures so I'm happy that we didn't introduce them.
2011-04-15 15:54:35 +01:00
Tom Ward df505a7289 ruby1.8 compatibility isn't required to run gollum using ruby 1.8.7
The sanitize gem requires 1.8.7 or later, so compatibility with earlier versions is moot
2011-04-12 15:23:23 +01:00
rick 17dcde1f61 fix xss vulnerability in mathjax parsing 2011-04-11 23:29:06 -04:00
John Benediktsson 2a052cae8d Remove default width of page name header. 2011-04-10 22:28:37 -07:00
Tom Clark d3594f6652 Added 'All Pages' route and view 2011-04-09 14:09:36 -07:00
rick ad561226b9 merrrge 2011-03-31 15:11:24 -07:00
Tom Clark 8403868ac3 Test that wikis can write to different branches in isolation 2011-02-22 00:12:32 -05:00
Tom Clark a1d760df1e Write pages to the proper branch 2011-02-21 23:32:27 -05:00
Randy Merrill e3950d52c1 Removing the ref as an argument to the Committer#parents and just using the @wiki.ref.
Updated the test to reflect the change and to test creating a wiki with a custom ref returns the correct parent for the `Committer#parents`.
2011-01-27 13:59:39 -08:00
Randy Merrill 7427ddd900 Adding some tests to test that the commiter can retrieve parents that are not the same as the wiki ref.
Also testing that the default wiki ref works without passing a ref.
2011-01-27 13:00:54 -08:00
Randy Merrill 364b2b85ae Moving the ref to be an argument to the parents that defaults to the @wiki.ref 2011-01-27 12:46:29 -08:00
Randy Merrill a71ab7c418 Changing from using branch as the variable to using ref. 2011-01-27 11:38:48 -08:00
Randy Merrill 2bb1937fa9 Fixing the docs for the default branch. 2011-01-27 11:29:21 -08:00
Randy Merrill 3c44205be7 Adding the logic to accept a command line flag for the branch to use to retrieve pages. 2011-01-27 11:24:15 -08:00
25 changed files with 395 additions and 77 deletions
+6
View File
@@ -0,0 +1,6 @@
rvm:
- 1.8.7
- 1.9.2
- rbx-2.0
notifications:
disabled: true
+1
View File
@@ -1,3 +1,4 @@
source "http://rubygems.org"
gemspec
gem "rake", "~> 0.9.2"
+32 -2
View File
@@ -1,4 +1,34 @@
# HEAD
# 1.3.1 / 2011-07-21
* Major Enhancements
* Allow prefixed ID attributes in headers to support internal linking
(#146).
* Markdown pages are rendered through Redcarpet by default (#176).
* Minor Enhancements
* Remove Edit button on Preview pages (#164).
* Simplify Wiki#inspect and Page#inspect.
* Bug Fixes
* Fixed broken preview functionality (#157).
* Fixed sidebar/footer rendering problems related to whitespace (#145).
# 1.3.0 / 2011-04-25
* Major Enhancements
* Listing of all Pages
* Support for running Gollum under a separate branch.
* Minor Enhancements
* Fix a security issue with rendering Mathjax.
# 1.2.0 / 2011-03-11
* Major Enhancements
* Major HTML/CSS/JS overhaul.
* Add Sidebars (similar to Footers).
* Add commit reverts.
* Minor Enhancements
* Optimization in source code highlighting, resulting in a huge
decrease in rendering time.
* Security fixes related to source code highlighting.
* Major Enhancements
* Add Page sidebars, similar to Page footers.
@@ -51,4 +81,4 @@
# 1.0.0 / 2010-08-12
* Open Source Birthday!
* Open Source Birthday!
+1 -1
View File
@@ -318,7 +318,7 @@ and `\]`. For example:
Inline equations are delimited by `\(` and `\)`. These equations will appear
inline with regular text. For example:
The Pythagorean theorum is \( a^2 + b^2 = c^2 \).
The Pythagorean theorem is \( a^2 + b^2 = c^2 \).
Gollum uses [MathJax](http://www.mathjax.org/) to convert the TeX syntax into
output suitable for display in web browsers.
+4
View File
@@ -48,6 +48,10 @@ opts = OptionParser.new do |opts|
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
opts.on("--ref [REF]", "Specify the repository ref to use (default: master).") do |ref|
wiki_options[:ref] = ref
end
end
# Read command line options into `options` hash
+6 -4
View File
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
s.rubygems_version = '1.3.5'
s.name = 'gollum'
s.version = '1.2.0'
s.date = '2011-03-31'
s.version = '1.3.1'
s.date = '2011-07-21'
s.rubyforge_project = 'gollum'
s.summary = "A simple, Git-powered wiki."
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib]
s.executables = ["gollum"]
s.default_executable = 'gollum'
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md LICENSE]
@@ -30,6 +29,7 @@ Gem::Specification.new do |s|
s.add_dependency('mustache', [">= 0.11.2", "< 1.0.0"])
s.add_dependency('sanitize', "~> 2.0.0")
s.add_dependency('nokogiri', "~> 1.4")
s.add_dependency('redcarpet')
s.add_development_dependency('RedCloth')
s.add_development_dependency('mocha')
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('shoulda')
s.add_development_dependency('rack-test')
s.add_development_dependency('wikicloth')
s.add_development_dependency('rake', '~> 0.9.2')
# = MANIFEST =
s.files = %w[
@@ -697,6 +698,7 @@ Gem::Specification.new do |s|
lib/gollum/frontend/templates/history.mustache
lib/gollum/frontend/templates/layout.mustache
lib/gollum/frontend/templates/page.mustache
lib/gollum/frontend/templates/pages.mustache
lib/gollum/frontend/templates/search.mustache
lib/gollum/frontend/templates/searchbar.mustache
lib/gollum/frontend/views/compare.rb
@@ -707,12 +709,12 @@ Gem::Specification.new do |s|
lib/gollum/frontend/views/history.rb
lib/gollum/frontend/views/layout.rb
lib/gollum/frontend/views/page.rb
lib/gollum/frontend/views/pages.rb
lib/gollum/frontend/views/search.rb
lib/gollum/git_access.rb
lib/gollum/markup.rb
lib/gollum/page.rb
lib/gollum/pagination.rb
lib/gollum/ruby1.8.rb
lib/gollum/sanitization.rb
lib/gollum/wiki.rb
templates/formatting.html
+11 -14
View File
@@ -7,23 +7,20 @@ require 'grit'
require 'github/markup'
require 'sanitize'
# ruby 1.8 compatibility
require 'gollum/ruby1.8'
# internal
require 'gollum/git_access'
require 'gollum/committer'
require 'gollum/pagination'
require 'gollum/blob_entry'
require 'gollum/wiki'
require 'gollum/page'
require 'gollum/file'
require 'gollum/markup'
require 'gollum/albino'
require 'gollum/sanitization'
require File.expand_path('../gollum/git_access', __FILE__)
require File.expand_path('../gollum/committer', __FILE__)
require File.expand_path('../gollum/pagination', __FILE__)
require File.expand_path('../gollum/blob_entry', __FILE__)
require File.expand_path('../gollum/wiki', __FILE__)
require File.expand_path('../gollum/page', __FILE__)
require File.expand_path('../gollum/file', __FILE__)
require File.expand_path('../gollum/markup', __FILE__)
require File.expand_path('../gollum/albino', __FILE__)
require File.expand_path('../gollum/sanitization', __FILE__)
module Gollum
VERSION = '1.2.0'
VERSION = '1.3.1'
class Error < StandardError; end
+4 -4
View File
@@ -62,7 +62,7 @@ module Gollum
# Returns an array of Grit::Commit instances.
def parents
@parents ||= begin
arr = [@options[:parent] || @wiki.repo.commit('master')]
arr = [@options[:parent] || @wiki.repo.commit(@wiki.ref)]
arr.flatten!
arr.compact!
arr
@@ -118,7 +118,7 @@ module Gollum
def update_working_dir(dir, name, format)
unless @wiki.repo.bare
if @wiki.page_file_dir
dir = dir.size.zero? ? @wiki.page_file_dir : File.join(dir, @wiki.page_file_dir)
dir = dir.size.zero? ? @wiki.page_file_dir : ::File.join(dir, @wiki.page_file_dir)
end
path =
@@ -142,7 +142,7 @@ module Gollum
#
# Returns the String SHA1 of the new commit.
def commit
sha1 = index.commit(@options[:message], parents, actor)
sha1 = index.commit(@options[:message], parents, actor, nil, @wiki.ref)
@callbacks.each do |cb|
cb.call(self, sha1)
end
@@ -214,4 +214,4 @@ module Gollum
index.send(name, *args)
end
end
end
end
+14 -4
View File
@@ -106,10 +106,11 @@ module Precious
end
post '/preview' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@name = "Preview"
@page = wiki.preview_page(@name, params[:content], params[:format])
@content = @page.formatted_data
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@name = "Preview"
@page = wiki.preview_page(@name, params[:content], params[:format])
@content = @page.formatted_data
@editable = false
mustache :page
end
@@ -155,6 +156,7 @@ module Precious
@page = page
@name = name
@content = page.formatted_data
@editable = true
mustache :page
else
halt 404
@@ -169,6 +171,13 @@ module Precious
mustache :search
end
get '/pages' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@results = wiki.pages
@ref = wiki.ref
mustache :pages
end
get '/*' do
show_page_or_file(params[:splat].first)
end
@@ -179,6 +188,7 @@ module Precious
@page = page
@name = name
@content = page.formatted_data
@editable = true
mustache :page
elsif file = wiki.file(name)
content_type file.mime_type
@@ -42,7 +42,6 @@ a:hover, a:visited {
line-height: normal;
margin: 0;
padding: 0.08em 0 0 0;
width: 50%;
}
#head ul.actions {
@@ -62,7 +62,7 @@
// get form fields
var oldAction = $('#gollum-editor form').attr('action');
var $form = $($('#gollum-editor form').get(0));
$form.attr('action', this.href);
$form.attr('action', '/preview');
$form.attr('target', '_blank');
$form.submit();
+5 -1
View File
@@ -2,17 +2,21 @@
<div id="head">
<h1>{{title}}</h1>
<ul class="actions">
<li class="minibutton"><a href="/pages"
class="action-all-pages">All Pages</a></li>
<li class="minibutton" class="jaws">
<a href="#" id="minibutton-new-page">New Page</a></li>
{{#editable}}
<li class="minibutton"><a href="/edit/{{escaped_name}}"
class="action-edit-page">Edit Page</a></li>
{{/editable}}
<li class="minibutton"><a href="/history/{{escaped_name}}"
class="action-page-history">Page History</a></li>
</ul>
{{>searchbar}}
</div>
<div id="wiki-content">
<div class="wrap{{#has_footer}} has-footer{{/has_footer}}{{#has_sidebar}} has-rightbar{{/has_sidebar}}">
<div class="wrap {{#has_footer}} has-footer {{/has_footer}} {{#has_sidebar}} has-rightbar{{/has_sidebar}}">
<div id="wiki-body" class="gollum-{{format}}-content">
<div id="template">
{{{content}}}
@@ -0,0 +1,35 @@
<div id="wiki-wrapper" class="results">
<div id="head">
<h1>{{title}}</h1>
<ul class="actions">
<li class="minibutton"><a href="/"
class="action-edit-page">Home</a></li>
</ul>
{{>searchbar}}
</div>
<div id="results">
{{#has_results}}
<ul>
{{#results}}
<li>
<a href="/{{name}}">{{name}}</a>
</li>
{{/results}}
</ul>
{{/has_results}}
{{#no_results}}
<p id="no-results">
There are no pages in <strong>{{ref}}</strong>.
</p>
{{/no_results}}
</div>
<div id="footer">
<ul class="actions">
<li class="minibutton"><a href="#">Back to Top</a></li>
</ul>
</div>
</div>
+4
View File
@@ -18,6 +18,10 @@ module Precious
def date
@page.version.authored_date.strftime("%Y-%m-%d %H:%M:%S")
end
def editable
@editable
end
def has_footer
@footer = (@page.footer || false) if @footer.nil?
+19
View File
@@ -0,0 +1,19 @@
module Precious
module Views
class Pages < Layout
attr_reader :results, :ref
def title
"All pages in #{@ref}"
end
def has_results
!@results.empty?
end
def no_results
@results.empty?
end
end
end
end
+11 -7
View File
@@ -28,13 +28,17 @@ module Gollum
#
# ref - a String Git reference (ex: "master")
#
# Returns a String.
# Returns a String, or nil if the ref isn't found.
def ref_to_sha(ref)
if sha?(ref)
ref
else
get_cache(:ref, ref) { ref_to_sha!(ref) }
end
ref = ref.to_s
return if ref.empty?
sha =
if sha?(ref)
ref
else
get_cache(:ref, ref) { ref_to_sha!(ref) }
end.to_s
sha.empty? ? nil : sha
end
# Public: Gets a recursive list of Git blobs for the whole tree at the
@@ -238,4 +242,4 @@ module Gollum
path
end
end
end
end
+52 -4
View File
@@ -2,6 +2,7 @@ require 'digest/sha1'
require 'cgi'
module Gollum
class Markup
# Initialize a new Markup object.
#
@@ -74,12 +75,14 @@ module Gollum
# Returns the placeholder'd String data.
def extract_tex(data)
data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do
id = Digest::SHA1.hexdigest($1)
@texmap[id] = [:block, $1]
tag = CGI.escapeHTML($1)
id = Digest::SHA1.hexdigest(tag)
@texmap[id] = [:block, tag]
id
end.gsub(/\\\(\s*(.*?)\s*\\\)/m) do
id = Digest::SHA1.hexdigest($1)
@texmap[id] = [:inline, $1]
tag = CGI.escapeHTML($1)
id = Digest::SHA1.hexdigest(tag)
@texmap[id] = [:inline, tag]
id
end
end
@@ -435,4 +438,49 @@ module Gollum
def update_cache(type, id, data)
end
end
begin
require 'redcarpet'
class MarkupGFM < Markup
def render(no_follow = false)
sanitize = no_follow ?
@wiki.history_sanitizer :
@wiki.sanitizer
data = extract_tex(@data.dup)
data = extract_tags(data)
flags = [
:autolink,
:fenced_code,
:tables,
:strikethrough,
:lax_htmlblock,
:gh_blockcode,
:no_intraemphasis
]
data = Redcarpet.new(data, *flags).to_html
data = process_tags(data)
doc = Nokogiri::HTML::DocumentFragment.parse(data)
doc.search('pre').each do |node|
next unless lang = node['lang']
text = node.inner_text
html = Gollum::Albino.colorize(text, lang)
node.replace(html)
end
doc = sanitize.clean_node!(doc) if sanitize
yield doc if block_given?
data = doc_to_html(doc)
data = process_tex(data)
data
end
end
rescue LoadError
MarkupGFM = Markup
end
end
+7 -3
View File
@@ -168,7 +168,7 @@ module Gollum
#
# Returns the String data.
def formatted_data(&block)
@blob && @wiki.markup_class.new(self).render(historical?, &block)
@blob && @wiki.markup_classes[format].new(self).render(historical?, &block)
end
# Public: The format of the page.
@@ -199,10 +199,10 @@ module Gollum
options[:pretty] = 'raw'
options.delete :max_count
options.delete :skip
log = @wiki.repo.git.native "log", options, "master", "--", @path
log = @wiki.repo.git.native "log", options, @wiki.ref, "--", @path
Grit::Commit.list_from_string(@wiki.repo, log)
else
@wiki.repo.log('master', @path, log_pagination_options(options))
@wiki.repo.log(@wiki.ref, @path, log_pagination_options(options))
end
end
@@ -390,5 +390,9 @@ module Gollum
find_page_in_tree(map, name, '')
end
def inspect
%(#<#{self.class.name}:#{object_id} #{name} (#{format}) @wiki=#{@wiki.repo.path.inspect}>)
end
end
end
-3
View File
@@ -1,3 +0,0 @@
class String
alias :lines :to_a if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
end
+33 -1
View File
@@ -47,6 +47,27 @@ module Gollum
'img' => {'src' => ['http', 'https', :relative]}
}.freeze
# Default transformers to force @id attributes with 'wiki-' prefix
TRANSFORMERS = [
lambda do |env|
node = env[:node]
return if env[:is_whitelisted] || !node.element? || !node['id']
prefix = env[:config][:id_prefix]
node['id'] = node['id'].gsub(/\A(#{prefix})?/, prefix)
{:node_whitelist => [node]}
end,
lambda do |env|
node = env[:node]
return unless node['href']
prefix = env[:config][:id_prefix]
node['href'] = node['href'].gsub(/\A\#(#{prefix})?/, '#'+prefix)
{:node_whitelist => [node]}
end
].freeze
# Gets an Array of whitelisted HTML elements. Default: ELEMENTS.
attr_reader :elements
@@ -58,6 +79,13 @@ module Gollum
# attributes. Default: PROTOCOLS
attr_reader :protocols
# Gets a Hash describing which URI protocols are allowed in HTML
# attributes. Default: TRANSFORMERS
attr_reader :transformers
# Gets a String prefix which is added to ID attributes. Default: 'wiki-'
attr_reader :id_prefix
# Gets a Hash describing HTML attributes that Sanitize should add.
# Default: {}
attr_reader :add_attributes
@@ -70,8 +98,10 @@ module Gollum
@elements = ELEMENTS
@attributes = ATTRIBUTES
@protocols = PROTOCOLS
@transformers = TRANSFORMERS
@add_attributes = {}
@allow_comments = false
@id_prefix = 'wiki-'
yield self if block_given?
end
@@ -100,7 +130,9 @@ module Gollum
:attributes => attributes,
:protocols => protocols,
:add_attributes => add_attributes,
:allow_comments => allow_comments?
:allow_comments => allow_comments?,
:transformers => transformers,
:id_prefix => id_prefix
}
end
+59 -24
View File
@@ -10,7 +10,10 @@ module Gollum
attr_writer :file_class
# Sets the markup class used by all instances of this Wiki.
attr_writer :markup_class
attr_writer :markup_classes
# Sets the default ref for the wiki.
attr_accessor :default_ref
# Sets the default name for commits.
attr_accessor :default_committer_name
@@ -50,15 +53,33 @@ module Gollum
# Gets the markup class used by all instances of this Wiki.
# Default: Gollum::Markup
def markup_class
@markup_class ||
if superclass.respond_to?(:markup_class)
superclass.markup_class
def markup_classes
@markup_classes ||
if superclass.respond_to?(:markup_classes)
superclass.markup_classes
else
::Gollum::Markup
classes = Hash.new(::Gollum::Markup)
# Add custom markup classes for different languages
classes[:markdown] = ::Gollum::MarkupGFM
classes
end
end
# Gets the default markup class used by all instances of this Wiki.
# Kept for backwards compatibility until Gollum v2.x
def markup_class
markup_classes[:default]
end
# Sets the default markup class used by all instances of this Wiki.
# Kept for backwards compatibility until Gollum v2.x
def markup_class=(default)
new_classes = Hash.new default
@markup_classes = Hash.new(default).update(markup_classes)
default
end
# Gets the default sanitization options for current pages used by
# instances of this Wiki.
def sanitization
@@ -80,6 +101,7 @@ module Gollum
end
end
self.default_ref = 'master'
self.default_committer_name = 'Anonymous'
self.default_committer_email = 'anon@anon.com'
@@ -94,6 +116,9 @@ module Gollum
# Gets the sanitization options for older page revisions used by this Wiki.
attr_reader :history_sanitization
# Gets the String ref in which all page files reside.
attr_reader :ref
# Gets the String directory in which all page files reside.
attr_reader :page_file_dir
@@ -106,9 +131,11 @@ module Gollum
# Default: "/"
# :page_class - The page Class. Default: Gollum::Page
# :file_class - The file Class. Default: Gollum::File
# :markup_class - The markup Class. Default: Gollum::Markup
# :markup_classes - A hash containing the markup Classes for each
# document type. Default: { Gollum::Markup }
# :sanitization - An instance of Sanitization.
# :page_file_dir - String the directory in which all page files reside
# :ref - String the repository ref to retrieve pages from
#
# Returns a fresh Gollum::Repo.
def initialize(path, options = {})
@@ -122,8 +149,9 @@ 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
@markup_class = options[:markup_class] || self.class.markup_class
@markup_classes = options[:markup_classes] || self.class.markup_classes
@repo = @access.repo
@ref = options[:ref] || self.class.default_ref
@sanitization = options[:sanitization] || self.class.sanitization
@history_sanitization = options[:history_sanitization] ||
self.class.history_sanitization
@@ -139,20 +167,20 @@ module Gollum
# Public: Get the formatted page for a given page name.
#
# name - The human or canonical String page name of the wiki page.
# version - The String version ID to find (default: "master").
# version - The String version ID to find (default: @ref).
#
# Returns a Gollum::Page or nil if no matching page was found.
def page(name, version = 'master')
def page(name, version = @ref)
@page_class.new(self).find(name, version)
end
# Public: Get the static file for a given name.
#
# name - The full String pathname to the file.
# version - The String version ID to find (default: "master").
# version - The String version ID to find (default: @ref).
#
# Returns a Gollum::File or nil if no matching file was found.
def file(name, version = 'master')
def file(name, version = @ref)
@file_class.new(self).find(name, version)
end
@@ -290,7 +318,7 @@ module Gollum
else
Committer.new(self, commit)
end
committer.delete(page.path)
committer.after_commit do |index, sha|
@@ -381,11 +409,11 @@ module Gollum
# Public: Lists all pages for this wiki.
#
# treeish - The String commit ID or ref to find (default: master)
# treeish - The String commit ID or ref to find (default: @ref)
#
# Returns an Array of Gollum::Page instances.
def pages(treeish = nil)
tree_list(treeish || 'master')
tree_list(treeish || @ref)
end
# Public: Returns the number of pages accessible from a commit
@@ -394,7 +422,7 @@ module Gollum
#
# Returns a Fixnum
def size(ref = nil)
tree_map_for(ref || 'master').inject(0) do |num, entry|
tree_map_for(ref || @ref).inject(0) do |num, entry|
num + (@page_class.valid_page_name?(entry.name) ? 1 : 0)
end
rescue Grit::GitRuby::Repository::NoSuchShaFound
@@ -407,7 +435,7 @@ module Gollum
#
# Returns an Array with Objects of page name and count of matches
def search(query)
args = [{}, '-i', '-c', query, 'master', '--']
args = [{}, '-i', '-c', query, @ref, '--']
args << '--' << @page_file_dir if @page_file_dir
@repo.git.grep(*args).split("\n").map! do |line|
@@ -429,7 +457,7 @@ module Gollum
#
# Returns an Array of Grit::Commit.
def log(options = {})
@repo.log('master', nil, log_pagination_options(options))
@repo.log(@ref, nil, log_pagination_options(options))
end
# Public: Refreshes just the cached Git reference data. This should
@@ -483,7 +511,7 @@ module Gollum
attr_reader :file_class
# Gets the markup class used by all instances of this Wiki.
attr_reader :markup_class
attr_reader :markup_classes
# Normalize the data.
#
@@ -511,11 +539,14 @@ module Gollum
#
# Returns a flat Array of Gollum::Page instances.
def tree_list(ref)
sha = @access.ref_to_sha(ref)
commit = @access.commit(sha)
tree_map_for(sha).inject([]) do |list, entry|
next list unless @page_class.valid_page_name?(entry.name)
list << entry.page(self, commit)
if sha = @access.ref_to_sha(ref)
commit = @access.commit(sha)
tree_map_for(sha).inject([]) do |list, entry|
next list unless @page_class.valid_page_name?(entry.name)
list << entry.page(self, commit)
end
else
[]
end
end
@@ -584,5 +615,9 @@ module Gollum
rescue Grit::GitRuby::Repository::NoSuchShaFound
[]
end
def inspect
%(#<#{self.class.name}:#{object_id} #{@repo.path}>)
end
end
end
+6
View File
@@ -38,6 +38,12 @@ def commit_details
:email => "tom@github.com" }
end
def normal(text)
text.gsub!(' ', '')
text.gsub!("\n", '')
text
end
# test/spec/mini 3
# http://gist.github.com/25455
# chris@ozmm.org
+13
View File
@@ -48,4 +48,17 @@ context "Wiki" do
FileUtils.rm_rf(@path)
end
end
test "parents with default master ref" do
ref = 'a8ad3c09dd842a3517085bfadd37718856dee813'
committer = Gollum::Committer.new(@wiki)
assert_equal ref, committer.parents.first.sha
end
test "parents with custom ref" do
ref = '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), :ref => ref)
committer = Gollum::Committer.new(@wiki)
assert_equal ref, committer.parents.first.sha
end
end
+17 -3
View File
@@ -173,7 +173,7 @@ context "Markup" do
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
page = @wiki.page("Potato")
output = page.formatted_data
assert_equal "<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>", output
assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>"), normal(output)
end
#########################################################################
@@ -467,6 +467,20 @@ context "Markup" do
compare(content, output, 'org')
end
test "id with prefix ok" do
content = "h2(example#wiki-foo). xxxx"
output = %(<h2 class="example" id="wiki-foo">xxxx</h2>)
compare(content, output, :textile)
end
test "id prefix added" do
content = "h2(#foo). xxxx[1]\n\nfn1.footnote"
output = "<h2 id=\"wiki-foo\">xxxx" +
"<sup class=\"footnote\" id=\"wiki-fnr1\"><a href=\"#wiki-fn1\">1</a></sup></h2>" +
"\n<p class=\"footnote\" id=\"wiki-fn1\"><a href=\"#wiki-fnr1\"><sup>1</sup></a> footnote</p>"
compare(content, output, :textile)
end
#########################################################################
#
# TeX
@@ -499,7 +513,7 @@ context "Markup" do
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
if regexes.empty?
assert_equal output, rendered
assert_equal normal(output), normal(rendered)
else
regexes.each { |r| assert_match r, output }
end
@@ -514,6 +528,6 @@ context "Markup" do
@wiki.clear_cache
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_equal normal(output), normal(rendered)
end
end
+54
View File
@@ -4,6 +4,20 @@ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Wiki" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
Gollum::Wiki.markup_classes = nil
end
test "#markup_class gets default markup" do
assert_equal Gollum::Markup, Gollum::Wiki.markup_class
end
test "#markup_class= doesn't clobber alternate markups" do
custom = Class.new(Gollum::Markup)
Gollum::Wiki.markup_class = custom
assert_equal custom, Gollum::Wiki.markup_class
assert_equal custom, Gollum::Wiki.markup_classes[:orgmode]
assert_equal Gollum::MarkupGFM, Gollum::Wiki.markup_classes[:markdown]
end
test "repo path" do
@@ -282,6 +296,11 @@ context "page_file_dir option" do
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 "edit a page in a sub directory" do
page = @wiki.page('foo')
@wiki.update_page(page, page.name, page.format, 'new contents', commit_details)
end
test "a file in page file dir should be found" do
assert @wiki.page("foo")
@@ -301,3 +320,38 @@ context "page_file_dir option" do
FileUtils.rm_r(@path)
end
end
context "Wiki page writing with different branch" do
setup do
@path = testpath("examples/test.git")
FileUtils.rm_rf(@path)
@repo = Grit::Repo.init_bare(@path)
@wiki = Gollum::Wiki.new(@path)
# We need an initial commit to create the master branch
# before we can create new branches
cd = commit_details
@wiki.write_page("Gollum", :markdown, "# Gollum", cd)
# Create our test branch and check it out
@repo.update_ref("test", @repo.commits.first.id)
@branch = Gollum::Wiki.new(@path, :ref => "test")
end
teardown do
FileUtils.rm_rf(@path)
end
test "write_page" do
cd = commit_details
@branch.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
assert @branch.page("Bilbo")
assert @wiki.page("Gollum")
assert_equal 1, @wiki.repo.commits.size
assert_equal 1, @branch.repo.commits.size
assert_equal nil, @wiki.page("Bilbo")
end
end