Skip to content

Commit cff6102

Browse files
committed
Replace configuration system, use this repo as repo, .md as extension
1 parent 299ff8d commit cff6102

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

git-wiki.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77

88
module GitWiki
99
class << self
10-
attr_accessor :root_page, :extension, :link_pattern
10+
attr_accessor :wiki_path, :root_page, :extension, :link_pattern
1111
attr_reader :wiki_name, :repository
12+
def wiki_path=(path)
13+
@wiki_name = File.basename(path)
14+
@repository = Grit::Repo.new(path)
15+
end
16+
def all_page_blobs
17+
@repository.tree.contents.select do |obj|
18+
obj.kind_of?(Grit::Blob) && obj.name.end_with?(@extension)
19+
end
20+
end
1221
end
13-
@wiki_name = File.basename(File.expand_path(ARGV[0] || '~/wiki'))
14-
@repository = Grit::Repo.new(File.expand_path(ARGV[0] || '~/wiki'))
15-
@extension = ARGV[1] || '.markdown'
16-
@root_page = ARGV[2] || 'index'
17-
@link_pattern = /\[\[(.*?)\]\]/
1822
end
1923

2024
class Page
2125
def self.find_all
22-
GitWiki.repository.tree.contents.collect {|blob| new(blob) }
26+
GitWiki.all_page_blobs.map {|blob| new(blob) }
2327
end
2428

2529
def self.find_or_create(name)
@@ -101,3 +105,10 @@ def save!(data)
101105
@page.save!(params[:body])
102106
redirect @page.url
103107
end
108+
109+
configure do
110+
GitWiki.wiki_path = Dir.pwd
111+
GitWiki.root_page = 'index'
112+
GitWiki.extension = '.md'
113+
GitWiki.link_pattern = /\[\[(.*?)\]\]/
114+
end

0 commit comments

Comments
 (0)