allow configurable page/file classes
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
module Gollum
|
module Gollum
|
||||||
class File
|
class File
|
||||||
|
Wiki.file_class = self
|
||||||
|
|
||||||
# Public: Initialize a file.
|
# Public: Initialize a file.
|
||||||
#
|
#
|
||||||
# wiki - The Gollum::Wiki in question.
|
# wiki - The Gollum::Wiki in question.
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ module Gollum
|
|||||||
class Page
|
class Page
|
||||||
include Pagination
|
include Pagination
|
||||||
|
|
||||||
|
Wiki.page_class = self
|
||||||
|
|
||||||
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|re?st(\.txt)?|asciidoc|pod|\d)$/i
|
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|re?st(\.txt)?|asciidoc|pod|\d)$/i
|
||||||
|
|
||||||
# Public: Initialize a page.
|
# Public: Initialize a page.
|
||||||
|
|||||||
+19
-9
@@ -2,14 +2,24 @@ module Gollum
|
|||||||
class Wiki
|
class Wiki
|
||||||
include Pagination
|
include Pagination
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_accessor :page_class, :file_class
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Initialize a new Gollum Repo.
|
# Public: Initialize a new Gollum Repo.
|
||||||
#
|
#
|
||||||
# repo - The String path to the Git repository that holds the Gollum site.
|
# repo - The String path to the Git repository that holds the Gollum
|
||||||
|
# site.
|
||||||
|
# options - Optional Hash:
|
||||||
|
# :page_class - The page Class. Default: Gollum::Page
|
||||||
|
# :file_class - The file Class. Default: Gollum::File
|
||||||
#
|
#
|
||||||
# Returns a fresh Gollum::Repo.
|
# Returns a fresh Gollum::Repo.
|
||||||
def initialize(path)
|
def initialize(path, options = {})
|
||||||
@path = path
|
@path = path
|
||||||
@repo = Grit::Repo.new(path)
|
@repo = Grit::Repo.new(path)
|
||||||
|
@page_class = options[:page_class] || self.class.page_class
|
||||||
|
@file_class = options[:file_class] || self.class.file_class
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: check whether the wiki's git repo exists on the filesystem.
|
# Public: check whether the wiki's git repo exists on the filesystem.
|
||||||
@@ -26,7 +36,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns a Gollum::Page or nil if no matching page was found.
|
# Returns a Gollum::Page or nil if no matching page was found.
|
||||||
def page(name, version = 'master')
|
def page(name, version = 'master')
|
||||||
Page.new(self).find(name, version)
|
@page_class.new(self).find(name, version)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get the static file for a given name.
|
# Public: Get the static file for a given name.
|
||||||
@@ -36,7 +46,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns a Gollum::File or nil if no matching file was found.
|
# Returns a Gollum::File or nil if no matching file was found.
|
||||||
def file(name, version = 'master')
|
def file(name, version = 'master')
|
||||||
File.new(self).find(name, version)
|
@file_class.new(self).find(name, version)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Write a new version of a page to the Gollum repo root.
|
# Public: Write a new version of a page to the Gollum repo root.
|
||||||
@@ -50,8 +60,8 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the String SHA1 of the newly written version.
|
# Returns the String SHA1 of the newly written version.
|
||||||
def write_page(name, format, data, commit = {})
|
def write_page(name, format, data, commit = {})
|
||||||
ext = Page.format_to_ext(format)
|
ext = @page_class.format_to_ext(format)
|
||||||
path = Page.cname(name) + '.' + ext
|
path = @page_class.cname(name) + '.' + ext
|
||||||
|
|
||||||
map = {}
|
map = {}
|
||||||
if pcommit = @repo.commit('master')
|
if pcommit = @repo.commit('master')
|
||||||
@@ -162,7 +172,7 @@ module Gollum
|
|||||||
tree.contents.each do |item|
|
tree.contents.each do |item|
|
||||||
case item
|
case item
|
||||||
when Grit::Blob
|
when Grit::Blob
|
||||||
list << Page.new(self).populate(item, path)
|
list << @page_class.new(self).populate(item, path)
|
||||||
when Grit::Tree
|
when Grit::Tree
|
||||||
list.push *tree_list(item, path)
|
list.push *tree_list(item, path)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user