9
9
module GitWiki
10
10
class << self
11
11
attr_accessor :wiki_path , :root_page , :extension , :link_pattern
12
- attr_reader :wiki_name , :repository
12
+ attr_reader :wiki_name , :repo
13
13
def wiki_path = ( path )
14
14
@wiki_name = File . basename ( path )
15
- @repository = Grit ::Repo . new ( path )
15
+ @repo = Grit ::Repo . new ( path )
16
16
end
17
17
def all_page_blobs
18
- @repository . head . commit . tree . contents . select do |obj |
18
+ @repo . head . commit . tree . contents . select do |obj |
19
19
obj . kind_of? ( Grit ::Blob ) && obj . name . end_with? ( @extension )
20
20
end
21
21
end
22
+ def create_blob ( path )
23
+ Grit ::Blob . create ( @repo , :name => path )
24
+ end
22
25
def file_path ( name )
23
26
( name . empty? ? @root_page : name ) + @extension
24
27
end
@@ -42,9 +45,9 @@ def self.find_all
42
45
43
46
def self . find_or_create ( name , rev = nil )
44
47
path = GitWiki . file_path ( name )
45
- commit = rev ? GitWiki . repository . commit ( rev ) : GitWiki . repository . head . commit
48
+ commit = rev ? GitWiki . repo . commit ( rev ) : GitWiki . repo . head . commit
46
49
blob = commit . tree /path
47
- new ( blob || Grit :: Blob . create ( GitWiki . repository , :name => path ) )
50
+ new ( blob || GitWiki . create_blob ( path ) )
48
51
end
49
52
50
53
def initialize ( blob )
@@ -68,16 +71,16 @@ def to_html
68
71
end
69
72
70
73
def log
71
- head = GitWiki . repository . head . name
72
- GitWiki . repository . log ( head , @blob . name ) . map { |commit | commit . to_hash }
74
+ head = GitWiki . repo . head . name
75
+ GitWiki . repo . log ( head , @blob . name ) . map { |commit | commit . to_hash }
73
76
end
74
77
75
78
def save! ( data , msg )
76
79
msg = "web commit: #{ name } " if msg . empty?
77
- Dir . chdir ( GitWiki . repository . working_dir ) do
80
+ Dir . chdir ( GitWiki . repo . working_dir ) do
78
81
File . open ( @blob . name , 'w' ) { |f | f . puts ( data . gsub ( "\r \n " , "\n " ) ) }
79
- GitWiki . repository . add ( @blob . name )
80
- GitWiki . repository . commit_index ( msg )
82
+ GitWiki . repo . add ( @blob . name )
83
+ GitWiki . repo . commit_index ( msg )
81
84
end
82
85
end
83
86
end
0 commit comments