gollum_rails 0.0.2.8 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +6 -4
- data/Gemfile.lock +151 -151
- data/HISTORY.md +43 -15
- data/LICENSE +661 -0
- data/README.md +75 -185
- data/Rakefile +170 -160
- data/examples/rails/initializer.rb +0 -0
- data/gollum_rails.gemspec +72 -57
- data/lib/gollum_rails.rb +35 -18
- data/lib/gollum_rails/adapters/activemodel.rb +46 -0
- data/lib/gollum_rails/adapters/activemodel/boolean.rb +15 -0
- data/lib/gollum_rails/adapters/activemodel/callback.rb +61 -0
- data/lib/gollum_rails/adapters/activemodel/error.rb +27 -0
- data/lib/gollum_rails/adapters/activemodel/naming.rb +42 -0
- data/lib/gollum_rails/adapters/activemodel/validation.rb +188 -0
- data/lib/gollum_rails/adapters/gollum.rb +61 -0
- data/lib/gollum_rails/adapters/gollum/.gitkeep +0 -0
- data/lib/gollum_rails/adapters/gollum/committer.rb +9 -0
- data/lib/gollum_rails/adapters/gollum/error.rb +19 -0
- data/lib/gollum_rails/adapters/gollum/page.rb +177 -0
- data/lib/gollum_rails/adapters/gollum/wiki.rb +43 -0
- data/lib/gollum_rails/initializer.rb +8 -0
- data/lib/gollum_rails/{hash.rb → modules/hash.rb} +33 -20
- data/lib/gollum_rails/modules/loader.rb +5 -0
- data/lib/gollum_rails/page.rb +283 -406
- data/lib/gollum_rails/setup.rb +68 -0
- metadata +56 -99
- data/LICENSE.md +0 -7
- data/lib/generators/gollum_rails/model/model_generator.rb +0 -10
- data/lib/gollum_rails/config.rb +0 -36
- data/lib/gollum_rails/dependency_injector.rb +0 -24
- data/lib/gollum_rails/engine.rb +0 -12
- data/lib/gollum_rails/file.rb +0 -9
- data/lib/gollum_rails/messages.yml +0 -8
- data/lib/gollum_rails/validations.rb +0 -10
- data/lib/gollum_rails/versions.rb +0 -79
- data/lib/gollum_rails/wiki.rb +0 -36
@@ -0,0 +1,61 @@
|
|
1
|
+
# ~*~ encoding: utf-8 ~*~
|
2
|
+
module GollumRails
|
3
|
+
module Adapters
|
4
|
+
# Gollum Wiki connector classes
|
5
|
+
#
|
6
|
+
# TODO:
|
7
|
+
# * implement
|
8
|
+
#
|
9
|
+
# FIXME:
|
10
|
+
# currently nothing implemented
|
11
|
+
#
|
12
|
+
module Gollum
|
13
|
+
# connector version
|
14
|
+
VERSION="0.0.0"
|
15
|
+
|
16
|
+
# Gollum connector class, keeping defaults!
|
17
|
+
#
|
18
|
+
class Connector
|
19
|
+
class << self
|
20
|
+
# Sets the page class used by all instances
|
21
|
+
attr_writer :page_class
|
22
|
+
|
23
|
+
# Sets the wiki class used by all instances
|
24
|
+
attr_writer :wiki_class
|
25
|
+
|
26
|
+
# Sets the committer
|
27
|
+
attr_writer :committer_class
|
28
|
+
|
29
|
+
# Gets the Globally used Page class or use a new one if not defined
|
30
|
+
#
|
31
|
+
#
|
32
|
+
# Returns the internal page class or a fresh ::Gollum::Page
|
33
|
+
def page_class
|
34
|
+
@page_class || Page
|
35
|
+
end
|
36
|
+
|
37
|
+
# Gets the Globally used Page class or use a new one if not defined
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Returns the internal page class or a fresh ::Gollum::Page
|
41
|
+
def wiki_class
|
42
|
+
@wiki_class || Wiki
|
43
|
+
end
|
44
|
+
|
45
|
+
# Gets the current committer or using anon
|
46
|
+
#
|
47
|
+
#
|
48
|
+
def committer_class
|
49
|
+
@committer_class || Committer
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
require File.expand_path '../gollum/error', __FILE__
|
58
|
+
require File.expand_path '../gollum/wiki', __FILE__
|
59
|
+
require File.expand_path '../gollum/committer', __FILE__
|
60
|
+
require File.expand_path '../gollum/page', __FILE__
|
61
|
+
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GollumRails
|
2
|
+
module Adapters
|
3
|
+
module Gollum
|
4
|
+
|
5
|
+
# Gollum adapter Error handling class
|
6
|
+
#
|
7
|
+
# provides better errors
|
8
|
+
class Error < ::StandardError
|
9
|
+
|
10
|
+
# does the formatting of the Error message
|
11
|
+
#
|
12
|
+
#
|
13
|
+
def initialize(error_message, urgence)
|
14
|
+
super "#{urgence.upcase} :: #{error_message}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
module GollumRails
|
2
|
+
module Adapters
|
3
|
+
module Gollum
|
4
|
+
|
5
|
+
# Main page class for the Gollum connector.
|
6
|
+
#
|
7
|
+
# It provides some awesome features for connecting gollum to gollum_rails such as:
|
8
|
+
# * new_page
|
9
|
+
# * find_page
|
10
|
+
# * delete_page
|
11
|
+
# * rename_page
|
12
|
+
# * move_page
|
13
|
+
# * first_page_commit
|
14
|
+
# * page_creation time
|
15
|
+
# * ...
|
16
|
+
#
|
17
|
+
class Page
|
18
|
+
|
19
|
+
Connector.page_class = self
|
20
|
+
|
21
|
+
# Gets / Sets current page
|
22
|
+
attr_accessor :page
|
23
|
+
|
24
|
+
# Gets / Sets the wiki
|
25
|
+
attr_accessor :wiki
|
26
|
+
|
27
|
+
# Initializer
|
28
|
+
def initialize
|
29
|
+
@wiki = Wiki.class_variable_get(:@@wiki)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# creates a new Page
|
34
|
+
#
|
35
|
+
# name - String
|
36
|
+
# type - Symbol
|
37
|
+
# content - Text
|
38
|
+
# commit - Hash or instance of Committer
|
39
|
+
#
|
40
|
+
# Returns the commit id
|
41
|
+
def new_page( name, content,type=:markdown, commit={} )
|
42
|
+
@wiki.write_page name.to_s, type, content, commit if name
|
43
|
+
@page = @wiki.page name
|
44
|
+
@page
|
45
|
+
end
|
46
|
+
|
47
|
+
# updates an existing page
|
48
|
+
#
|
49
|
+
# new - Hash with changed data
|
50
|
+
# commit - Hash or instance of Committer
|
51
|
+
# old - also an instance of self
|
52
|
+
#
|
53
|
+
# Returns the commit id
|
54
|
+
def update_page( new, commit={}, old=nil)
|
55
|
+
if new.is_a?(Hash)
|
56
|
+
commit_id = @wiki.update_page (old||@page),
|
57
|
+
new[:name]||@page.name,
|
58
|
+
new[:format]||@page.format,
|
59
|
+
new[:content]||@page.raw_data,
|
60
|
+
commit
|
61
|
+
else
|
62
|
+
raise Error.new "commit must be a Hash. #{new.class} given", :crit
|
63
|
+
end
|
64
|
+
|
65
|
+
# this is very ugly. Shouldn't gollum return the new page?
|
66
|
+
@page = @page.find(new[:name]||@page.name, commit_id)
|
67
|
+
@page
|
68
|
+
end
|
69
|
+
|
70
|
+
# deletes an existing page
|
71
|
+
#
|
72
|
+
# page - instance of self
|
73
|
+
# commit - Hash or instance of Committer
|
74
|
+
#
|
75
|
+
# Returns the commit id
|
76
|
+
def delete_page( commit={}, page = nil )
|
77
|
+
@wiki.delete_page (page||@page), commit
|
78
|
+
end
|
79
|
+
|
80
|
+
# renames an existing page
|
81
|
+
#
|
82
|
+
# page - instance of myself
|
83
|
+
# newname - new pagename
|
84
|
+
# commit - Hash or instance of Committer
|
85
|
+
#
|
86
|
+
# Returns the commit id
|
87
|
+
def rename_page( page, newname, commit={} )
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
# finds all versions of a page
|
92
|
+
#
|
93
|
+
# name - the pagename to search
|
94
|
+
#
|
95
|
+
# Returns the Gollum::Page class
|
96
|
+
def find_page(name)
|
97
|
+
@wiki.page ::Gollum::Page.cname(name)
|
98
|
+
end
|
99
|
+
|
100
|
+
# moves an existing page
|
101
|
+
#
|
102
|
+
# TODO:
|
103
|
+
# * implement
|
104
|
+
def move_page()
|
105
|
+
end
|
106
|
+
|
107
|
+
# gets page last edit date
|
108
|
+
#
|
109
|
+
# Returns an instance of Time
|
110
|
+
def page_last_edited_date
|
111
|
+
if @page
|
112
|
+
return @page.versions.first.authored_date
|
113
|
+
else
|
114
|
+
raise Error.new "page cannot be empty for #{__method__}", :high
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# gets the latest commit
|
119
|
+
#
|
120
|
+
# Returns an instance of Grit::Commit
|
121
|
+
def page_last_commit
|
122
|
+
if @page
|
123
|
+
return @page.versions.first
|
124
|
+
else
|
125
|
+
raise Error.new "page cannot be empty for #{__method__}", :high
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# gets the creation date of the page
|
130
|
+
#
|
131
|
+
# Returns an instance of Time
|
132
|
+
def page_created
|
133
|
+
if @page
|
134
|
+
return @page.versions.last.authored_date
|
135
|
+
else
|
136
|
+
raise Error.new "page cannot be empty for #{__method__}", :high
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
# gets the first page commit
|
142
|
+
#
|
143
|
+
# Returns an instance of Grit::Commit
|
144
|
+
def page_first_commit
|
145
|
+
if @page
|
146
|
+
return @page.versions.last
|
147
|
+
else
|
148
|
+
raise Error.new "page cannot be empty for #{__method__}", :high
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# gets a specific commit version
|
153
|
+
#
|
154
|
+
# Returns an instance of Grit::Commit
|
155
|
+
def page_commit(id)
|
156
|
+
if @page
|
157
|
+
return @page.versions.each{|v| return v if v.id == id}
|
158
|
+
else
|
159
|
+
raise Error.new "page cannot be empty for #{__method__}", :high
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# gets a specific commit time
|
164
|
+
#
|
165
|
+
# Returns an instance of Time
|
166
|
+
def page_commit_date(id)
|
167
|
+
if @page
|
168
|
+
return @page.versions.each{|v| return v.authored_date if v.id == id}
|
169
|
+
else
|
170
|
+
raise Error.new "page cannot be empty for #{__method__}", :high
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'grit'
|
2
|
+
module GollumRails
|
3
|
+
module Adapters
|
4
|
+
module Gollum
|
5
|
+
|
6
|
+
# TODO: doc
|
7
|
+
class Wiki
|
8
|
+
|
9
|
+
Connector.wiki_class = self
|
10
|
+
|
11
|
+
# Gets / Sets the git path or object
|
12
|
+
attr_accessor :git
|
13
|
+
|
14
|
+
# Static callers
|
15
|
+
class << self
|
16
|
+
# Gets / Sets the wiki instance
|
17
|
+
attr_accessor :wiki
|
18
|
+
end
|
19
|
+
|
20
|
+
# Initializes the class
|
21
|
+
#
|
22
|
+
# location - String or Grit::Repo
|
23
|
+
def initialize(location)
|
24
|
+
gollum = ::Gollum::Wiki
|
25
|
+
@git = location
|
26
|
+
if location.is_a? ::String
|
27
|
+
@@wiki = gollum.new @git
|
28
|
+
else
|
29
|
+
@@wiki = gollum.new @git.path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Static call from within any other class
|
34
|
+
#
|
35
|
+
# Returns a new instance of this class
|
36
|
+
def self.wiki(location)
|
37
|
+
Wiki.new(location)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,20 +1,33 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# See http://ruby-doc.org/core-2.0/Hash.html for further information
|
2
|
+
#
|
3
|
+
# Extended methods:
|
4
|
+
# * object support
|
5
|
+
# * setter
|
6
|
+
# * hash setter
|
7
|
+
# * isset
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# TODO
|
11
|
+
# * implement is? method
|
12
|
+
# * improve testing
|
13
|
+
#
|
14
|
+
class ::Hash
|
15
|
+
|
16
|
+
|
17
|
+
# Public: Converts a method . into an Hash element
|
18
|
+
#
|
19
|
+
# Examples
|
20
|
+
# hash = {a: "b", b: "c", c: "d"}
|
21
|
+
# hash.a
|
22
|
+
# # => "b"
|
23
|
+
# # hash.b
|
24
|
+
# # => "c"
|
25
|
+
#
|
26
|
+
# Returns an instance of Hash if the name is the key of a new hash
|
27
|
+
def method_missing(name, *args)
|
28
|
+
return self[name] if key? name
|
29
|
+
self.each { |k,v| return v if k.to_s.to_sym == name }
|
30
|
+
super.method_missing name
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/gollum_rails/page.rb
CHANGED
@@ -1,406 +1,283 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
#
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
#
|
190
|
-
#
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
if
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
return
|
280
|
-
end
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
# name - Search string
|
285
|
-
#
|
286
|
-
# Returns nil if no result was found or no name was given
|
287
|
-
attr_reader :page
|
288
|
-
|
289
|
-
# Public: Finds a page based on given search string
|
290
|
-
#
|
291
|
-
# Be careful: At the moment you must initialize the class by .new
|
292
|
-
#
|
293
|
-
# Examples
|
294
|
-
# page = Page.new attributes
|
295
|
-
# page.find('static')
|
296
|
-
#
|
297
|
-
# Returns either nil or an instance of Gollum::Page
|
298
|
-
def find(name = nil)
|
299
|
-
if !name.nil?
|
300
|
-
page = @wiki.wiki.page(name)
|
301
|
-
if page.nil?
|
302
|
-
@error = @options.messages.no_page_found
|
303
|
-
return nil
|
304
|
-
end
|
305
|
-
|
306
|
-
#need a better solution. Thats fu***** bull*****
|
307
|
-
@page = page
|
308
|
-
@name = page.name
|
309
|
-
@format = page.format
|
310
|
-
|
311
|
-
return page
|
312
|
-
else
|
313
|
-
@error = @options.messages.name_not_set_or_nil
|
314
|
-
return nil
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
# Public: Checks if the object is already persisted
|
319
|
-
#
|
320
|
-
# Examples
|
321
|
-
# page = Page.new
|
322
|
-
# page.persisted?
|
323
|
-
# # => false
|
324
|
-
# page.save
|
325
|
-
# page.persisted?
|
326
|
-
# # => false
|
327
|
-
#
|
328
|
-
# @commit = {
|
329
|
-
# :message => "test creation of page",
|
330
|
-
# :name => 'Florian Kasper',
|
331
|
-
# :email => 'nirnanaaa@khnetworks.com'
|
332
|
-
# }
|
333
|
-
# attributes = {
|
334
|
-
# name: 'TestPage',
|
335
|
-
# content: 'content',
|
336
|
-
# format: :markdown,
|
337
|
-
# commit: @commit
|
338
|
-
# }
|
339
|
-
# page.save
|
340
|
-
# page.persisted?
|
341
|
-
# # => true
|
342
|
-
#
|
343
|
-
# Returns a Boolean(false|true)
|
344
|
-
def persisted?
|
345
|
-
@persisted
|
346
|
-
end
|
347
|
-
|
348
|
-
# Public: Magic method ( static )
|
349
|
-
#
|
350
|
-
# name - The functions name
|
351
|
-
# args - Pointer of arguments
|
352
|
-
#
|
353
|
-
# Static into non static converter
|
354
|
-
def self.method_missing(name, *args)
|
355
|
-
klass = self.new
|
356
|
-
return klass.find(args) if name.to_s == 'find'
|
357
|
-
end
|
358
|
-
|
359
|
-
################################################
|
360
|
-
######### P A G E # L O A D E D ################
|
361
|
-
################################################
|
362
|
-
|
363
|
-
# Public: A simple wrapper for Gollum::Page.raw_data
|
364
|
-
#
|
365
|
-
# Page needs to be loaded!
|
366
|
-
#
|
367
|
-
# Returns raw data
|
368
|
-
def raw_data
|
369
|
-
if @page
|
370
|
-
@page.raw_data
|
371
|
-
else
|
372
|
-
@error = @options.messages.no_page_fetched
|
373
|
-
return false
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
# Public: A simple wrapper for Gollum::Page.formatted_data
|
378
|
-
#
|
379
|
-
# Page needs to be loaded!
|
380
|
-
#
|
381
|
-
# Returns formatted html
|
382
|
-
def formatted_data
|
383
|
-
if @page
|
384
|
-
@page.formatted_data
|
385
|
-
else
|
386
|
-
@error = @options.messages.no_page_fetched
|
387
|
-
return false
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
# Public: Active Record like
|
392
|
-
#
|
393
|
-
#
|
394
|
-
#
|
395
|
-
# see Active Model documentation
|
396
|
-
def versions
|
397
|
-
if @page && @page.is_a?(Gollum::Page) #&& (persisted? || found?)
|
398
|
-
return GollumRails::Versions.new(@page)
|
399
|
-
else
|
400
|
-
@error = @options.messages.no_page_fetched
|
401
|
-
return false
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
end
|
406
|
-
end
|
1
|
+
module GollumRails
|
2
|
+
|
3
|
+
# Main class, used to interact with rails.
|
4
|
+
#
|
5
|
+
# Methods, which are available:
|
6
|
+
# * find
|
7
|
+
# * update_attributes
|
8
|
+
# * find_by_*
|
9
|
+
# * create
|
10
|
+
# * new
|
11
|
+
# * save
|
12
|
+
# * delete
|
13
|
+
# * find_or_initialize_by_naname
|
14
|
+
#
|
15
|
+
class Page < Adapters::ActiveModel::Callback
|
16
|
+
include ::ActiveModel::Conversion
|
17
|
+
extend ::ActiveModel::Naming
|
18
|
+
|
19
|
+
|
20
|
+
# static
|
21
|
+
class << self
|
22
|
+
# Gets / Sets the gollum page
|
23
|
+
#
|
24
|
+
attr_accessor :gollum_page
|
25
|
+
|
26
|
+
# Sets the validator
|
27
|
+
attr_writer :validator
|
28
|
+
|
29
|
+
end
|
30
|
+
# Initializes a new Page
|
31
|
+
#
|
32
|
+
# attrs - Hash of attributes
|
33
|
+
#
|
34
|
+
# commit must be given to perform any page action!
|
35
|
+
def initialize(attrs = {})
|
36
|
+
attrs.each{|k,v| self.instance_variable_set("@#{k}", v)}
|
37
|
+
attrs.each{|k,v| self.class.validator.instance_variable_set("@#{k}", v)}
|
38
|
+
end
|
39
|
+
|
40
|
+
#########
|
41
|
+
# Setters
|
42
|
+
#########
|
43
|
+
|
44
|
+
# Sets the wiki instance
|
45
|
+
attr_writer :wiki
|
46
|
+
|
47
|
+
# Sets the pages name
|
48
|
+
attr_writer :name
|
49
|
+
|
50
|
+
# Sets the contents content
|
51
|
+
attr_writer :content
|
52
|
+
|
53
|
+
# Sets the commit Hash
|
54
|
+
attr_writer :commit
|
55
|
+
|
56
|
+
# Sets the format
|
57
|
+
attr_writer :format
|
58
|
+
|
59
|
+
# Sets the page
|
60
|
+
attr_writer :page
|
61
|
+
|
62
|
+
#########
|
63
|
+
# Getters
|
64
|
+
#########
|
65
|
+
|
66
|
+
# Gets the wiki instance
|
67
|
+
def wiki
|
68
|
+
@wiki || Adapters::Gollum::Connector.wiki_class.class_variable_get(:@@wiki)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets the pages' name
|
72
|
+
def name
|
73
|
+
@name || @gollum_page.name
|
74
|
+
end
|
75
|
+
|
76
|
+
# Gets the raw content of the current page
|
77
|
+
def content
|
78
|
+
@content || @gollum_page.raw_content
|
79
|
+
end
|
80
|
+
|
81
|
+
# Need to implement the Committer connector (forgot it completely)
|
82
|
+
# Gets the commit Hash from current object
|
83
|
+
def commit
|
84
|
+
@commit
|
85
|
+
end
|
86
|
+
|
87
|
+
# Gets the pages format
|
88
|
+
def format
|
89
|
+
(@format || @gollum_page.format).to_sym
|
90
|
+
end
|
91
|
+
|
92
|
+
# Gets the validator
|
93
|
+
def self.validator
|
94
|
+
@@validator ||= Adapters::ActiveModel::Validation.new
|
95
|
+
end
|
96
|
+
|
97
|
+
# Gets the page class
|
98
|
+
def page
|
99
|
+
@page ||= Adapters::Gollum::Connector.page_class.new
|
100
|
+
end
|
101
|
+
|
102
|
+
# Statically page getter
|
103
|
+
#
|
104
|
+
# DEPRECATED! Do not use
|
105
|
+
def self.page
|
106
|
+
Adapters::Gollum::Connector.page_class
|
107
|
+
end
|
108
|
+
|
109
|
+
#############
|
110
|
+
# activemodel
|
111
|
+
#############
|
112
|
+
|
113
|
+
# Handles the connection betweet plain activemodel and Gollum
|
114
|
+
# Saves current page in GIT wiki
|
115
|
+
# If another page with the same name is existing, gollum_rails
|
116
|
+
# will detect it and returns that page instead.
|
117
|
+
#
|
118
|
+
# Examples:
|
119
|
+
#
|
120
|
+
# obj = GollumRails::Page.new <params>
|
121
|
+
# @article = obj.save
|
122
|
+
# # => Gollum::Page
|
123
|
+
#
|
124
|
+
# @article.name
|
125
|
+
# whatever name you have entered OR the name of the previous
|
126
|
+
# created page
|
127
|
+
#
|
128
|
+
#
|
129
|
+
# TODO:
|
130
|
+
# * overriding for creation(duplicates)
|
131
|
+
# * do not alias save! on save
|
132
|
+
#
|
133
|
+
# Returns an instance of Gollum::Page or false
|
134
|
+
def save
|
135
|
+
begin
|
136
|
+
page.instance_variable_set("@page", page.new_page(name, content, format, commit)) if valid?
|
137
|
+
return page.page||false
|
138
|
+
rescue ::Gollum::DuplicatePageError => e
|
139
|
+
page.instance_variable_set "@page",page.find_page(name)
|
140
|
+
return page.page
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# aliasing save
|
145
|
+
#
|
146
|
+
# TODO:
|
147
|
+
# * implement full method!
|
148
|
+
alias_method :save!, :save
|
149
|
+
|
150
|
+
# first creates an instance of itself and executes the save function.
|
151
|
+
#
|
152
|
+
# hash - Hash containing the page data
|
153
|
+
#
|
154
|
+
#
|
155
|
+
# Returns an instance of Gollum::Page or false
|
156
|
+
def self.create(hash)
|
157
|
+
page = Page.new hash
|
158
|
+
page.save
|
159
|
+
end
|
160
|
+
|
161
|
+
# calls `create` on current class. If returned value is nil an exception will be thrown
|
162
|
+
#
|
163
|
+
# hash - Hash containing the page data
|
164
|
+
#
|
165
|
+
# TODO:
|
166
|
+
# * much testing
|
167
|
+
#
|
168
|
+
# Returns an instance of Gollum::Page
|
169
|
+
def self.create!(hash)
|
170
|
+
action = self.create(hash)
|
171
|
+
if action.nil? or action.is_a? Adapters::ActiveModel::Boolean
|
172
|
+
raise GollumInternalError, "Page is nil"
|
173
|
+
end
|
174
|
+
action
|
175
|
+
end
|
176
|
+
|
177
|
+
# Updates an existing page (or created)
|
178
|
+
#
|
179
|
+
# hash - Hash containing the attributes, you want to update
|
180
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
181
|
+
# to initialize the instance
|
182
|
+
#
|
183
|
+
#
|
184
|
+
# Returns an instance of Gollum::Page
|
185
|
+
def update_attributes(hash, commit=nil)
|
186
|
+
page.update_page hash, get_right_commit(commit)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Deletes current page (also available static. See below)
|
190
|
+
#
|
191
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
192
|
+
# to initialize the instance
|
193
|
+
#
|
194
|
+
# Returns the commit id of the current action as String
|
195
|
+
def delete(commit=nil)
|
196
|
+
page.delete_page get_right_commit(commit)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Previews the page - Mostly used if you want to see what you do before saving
|
200
|
+
#
|
201
|
+
# This is an extremely performant method!
|
202
|
+
# 1 rendering attempt take depending on the content about 0.001 (simple markdown)
|
203
|
+
# upto 0.004 (1000 chars markdown) seconds, which is quite good
|
204
|
+
#
|
205
|
+
#
|
206
|
+
# format - Specify the format you want to render with see {self.format_supported?}
|
207
|
+
# for formats
|
208
|
+
#
|
209
|
+
# Returns a String
|
210
|
+
def preview(format=:markdown)
|
211
|
+
preview = wiki.preview_page @name, @content, format
|
212
|
+
preview.formatted_data
|
213
|
+
end
|
214
|
+
|
215
|
+
# Finds a page based on the name and specified version
|
216
|
+
#
|
217
|
+
# name - the name of the page
|
218
|
+
#
|
219
|
+
# Return an instance of Gollum::Page
|
220
|
+
def self.find(name)
|
221
|
+
page = GollumRails::Adapters::Gollum::Page.new
|
222
|
+
page.find_page name
|
223
|
+
end
|
224
|
+
|
225
|
+
# todo
|
226
|
+
def valid?
|
227
|
+
self.class.validate self,true
|
228
|
+
end
|
229
|
+
|
230
|
+
# todo
|
231
|
+
def self.validate(context=nil,check=false,&block)
|
232
|
+
if block
|
233
|
+
@@gollum_page = block
|
234
|
+
end
|
235
|
+
if check
|
236
|
+
@@gollum_page.call context.class.validator
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# todo
|
241
|
+
def self.register_validations_for(*args)
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
# module templates following:
|
246
|
+
|
247
|
+
# empty
|
248
|
+
#def self.method_missing(name, *args)
|
249
|
+
#
|
250
|
+
#end
|
251
|
+
|
252
|
+
# empty
|
253
|
+
#def method_missing(name, *args)
|
254
|
+
#end
|
255
|
+
|
256
|
+
# Finds an existing page or creates it
|
257
|
+
#
|
258
|
+
# Returns self
|
259
|
+
def self.find_or_initialize_by_name(name, commit)
|
260
|
+
result_for_find = self.find(name)
|
261
|
+
self.create({:format => :markdown, :name => name, :content => ".", :commit => commit })
|
262
|
+
end
|
263
|
+
|
264
|
+
def self.format_supported?(format)
|
265
|
+
supported = ['ascii', 'github-markdown','markdown', 'creole', 'org', 'pod', 'rdoc']
|
266
|
+
format.in?(supported)
|
267
|
+
end
|
268
|
+
|
269
|
+
private
|
270
|
+
|
271
|
+
# Get the right commit out of 2 commits
|
272
|
+
#
|
273
|
+
# commit_local - local commit Hash
|
274
|
+
#
|
275
|
+
# Returns local_commit > class_commit
|
276
|
+
def get_right_commit(commit_local)
|
277
|
+
com = commit if commit_local.nil?
|
278
|
+
com = commit_local if !commit_local.nil?
|
279
|
+
return com
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
end
|