gollum_rails 1.4.0.rc1 → 1.4.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -6
- data/Gemfile.lock +2 -1
- data/HISTORY.md +91 -91
- data/LICENSE +661 -661
- data/README.md +74 -74
- data/Rakefile +170 -170
- data/gollum_rails.gemspec +1 -1
- data/lib/core_ext/string.rb +7 -10
- data/lib/generators/gollum_rails/install/install_generator.rb +27 -27
- data/lib/generators/gollum_rails/install/templates/gollum_initializer.rb +22 -22
- data/lib/generators/gollum_rails/language/language_generator.rb +81 -81
- data/lib/generators/gollum_rails/model/model_generator.rb +51 -51
- data/lib/generators/gollum_rails/model/templates/model_template.erb +13 -13
- data/lib/gollum_rails.rb +1 -1
- data/lib/gollum_rails/adapters/activemodel.rb +36 -36
- data/lib/gollum_rails/adapters/activemodel/boolean.rb +15 -15
- data/lib/gollum_rails/adapters/activemodel/error.rb +27 -27
- data/lib/gollum_rails/adapters/activemodel/naming.rb +42 -42
- data/lib/gollum_rails/adapters/gollum.rb +54 -54
- data/lib/gollum_rails/adapters/gollum/.gitkeep +0 -0
- data/lib/gollum_rails/adapters/gollum/error.rb +19 -19
- data/lib/gollum_rails/adapters/gollum/page.rb +177 -177
- data/lib/gollum_rails/adapters/gollum/wiki.rb +42 -42
- data/lib/gollum_rails/modules/hash.rb +33 -33
- data/lib/gollum_rails/modules/loader.rb +5 -5
- data/lib/gollum_rails/page.rb +266 -266
- data/lib/gollum_rails/setup.rb +81 -81
- data/lib/grit/git-ruby/internal/pack.rb +397 -397
- data/spec/gollum_rails/adapters/activemodel/error_spec.rb +11 -11
- data/spec/gollum_rails/adapters/activemodel/naming_spec.rb +27 -27
- data/spec/gollum_rails/adapters/activemodel/validation_unused.rb +102 -102
- data/spec/gollum_rails/adapters/gollum/committer_spec.rb +0 -0
- data/spec/gollum_rails/adapters/gollum/connector_spec.rb +15 -15
- data/spec/gollum_rails/adapters/gollum/error_spec.rb +7 -7
- data/spec/gollum_rails/adapters/gollum/page_spec.rb +89 -89
- data/spec/gollum_rails/adapters/gollum/wiki_spec.rb +27 -27
- data/spec/gollum_rails/modules/hash_spec.rb +31 -31
- data/spec/gollum_rails/page_spec.rb +207 -207
- data/spec/gollum_rails/respository_spec.rb +0 -0
- data/spec/gollum_rails/setup_spec.rb +44 -44
- data/spec/gollum_rails/wiki_spec.rb +0 -0
- data/spec/spec.opts +3 -3
- data/spec/spec_helper.rb +43 -43
- metadata +2 -2
@@ -1,42 +1,42 @@
|
|
1
|
-
require 'grit'
|
2
|
-
module GollumRails
|
3
|
-
module Adapters
|
4
|
-
module Gollum
|
5
|
-
|
6
|
-
# TODO: doc
|
7
|
-
class Wiki
|
8
|
-
|
9
|
-
# Gets / Sets the git path or object
|
10
|
-
attr_accessor :git
|
11
|
-
|
12
|
-
# Initializes the class
|
13
|
-
#
|
14
|
-
# location - String or Grit::Repo
|
15
|
-
def initialize(location)
|
16
|
-
@git = location
|
17
|
-
if location.is_a? ::String
|
18
|
-
con = ::Gollum::Wiki.new @git
|
19
|
-
else
|
20
|
-
con= ::Gollum::Wiki.new @git.path
|
21
|
-
end
|
22
|
-
Connector.wiki_class = con
|
23
|
-
end
|
24
|
-
|
25
|
-
# Static call from within any other class
|
26
|
-
#
|
27
|
-
# Returns a new instance of this class
|
28
|
-
def self.wiki(location)
|
29
|
-
Wiki.new(location)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Forwards unknown methods to Gollum::Wiki
|
33
|
-
#
|
34
|
-
# may throw an Argument error or method missing
|
35
|
-
def self.method_missing(name, *args)
|
36
|
-
Connector.wiki_class.send(name, *args)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
require 'grit'
|
2
|
+
module GollumRails
|
3
|
+
module Adapters
|
4
|
+
module Gollum
|
5
|
+
|
6
|
+
# TODO: doc
|
7
|
+
class Wiki
|
8
|
+
|
9
|
+
# Gets / Sets the git path or object
|
10
|
+
attr_accessor :git
|
11
|
+
|
12
|
+
# Initializes the class
|
13
|
+
#
|
14
|
+
# location - String or Grit::Repo
|
15
|
+
def initialize(location)
|
16
|
+
@git = location
|
17
|
+
if location.is_a? ::String
|
18
|
+
con = ::Gollum::Wiki.new @git
|
19
|
+
else
|
20
|
+
con= ::Gollum::Wiki.new @git.path
|
21
|
+
end
|
22
|
+
Connector.wiki_class = con
|
23
|
+
end
|
24
|
+
|
25
|
+
# Static call from within any other class
|
26
|
+
#
|
27
|
+
# Returns a new instance of this class
|
28
|
+
def self.wiki(location)
|
29
|
+
Wiki.new(location)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Forwards unknown methods to Gollum::Wiki
|
33
|
+
#
|
34
|
+
# may throw an Argument error or method missing
|
35
|
+
def self.method_missing(name, *args)
|
36
|
+
Connector.wiki_class.send(name, *args)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,33 +1,33 @@
|
|
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
|
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
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module GollumRails
|
2
|
-
::Dir.glob(::File.expand_path(::File.dirname(__FILE__)) + '/*.rb') do |file|
|
3
|
-
require file if file != __FILE__
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module GollumRails
|
2
|
+
::Dir.glob(::File.expand_path(::File.dirname(__FILE__)) + '/*.rb') do |file|
|
3
|
+
require file if file != __FILE__
|
4
|
+
end
|
5
|
+
end
|
data/lib/gollum_rails/page.rb
CHANGED
@@ -1,266 +1,266 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
|
-
module GollumRails
|
4
|
-
|
5
|
-
# Main class, used to interact with rails.
|
6
|
-
#
|
7
|
-
# Methods, which are available:
|
8
|
-
# * find
|
9
|
-
# * update_attributes
|
10
|
-
# * find_by_*
|
11
|
-
# * create
|
12
|
-
# * new
|
13
|
-
# * save
|
14
|
-
# * delete
|
15
|
-
# * find_or_initialize_by_naname
|
16
|
-
#
|
17
|
-
class Page
|
18
|
-
extend ::ActiveModel::Callbacks
|
19
|
-
include ::ActiveModel::Validations
|
20
|
-
include ::ActiveModel::Conversion
|
21
|
-
extend ::ActiveModel::Naming
|
22
|
-
|
23
|
-
|
24
|
-
# Callback for save
|
25
|
-
define_model_callbacks :save
|
26
|
-
|
27
|
-
# Callback for update
|
28
|
-
define_model_callbacks :update
|
29
|
-
|
30
|
-
# Callback for delete
|
31
|
-
define_model_callbacks :delete
|
32
|
-
|
33
|
-
# static
|
34
|
-
class << self
|
35
|
-
# Gets / Sets the gollum page
|
36
|
-
#
|
37
|
-
attr_accessor :gollum_page
|
38
|
-
|
39
|
-
# Sets the validator
|
40
|
-
attr_writer :validator
|
41
|
-
|
42
|
-
# Finds an existing page or creates it
|
43
|
-
#
|
44
|
-
# name - The name
|
45
|
-
# commit - Hash
|
46
|
-
#
|
47
|
-
# Returns self
|
48
|
-
def find_or_initialize_by_name(name, commit)
|
49
|
-
result_for_find = self.find(name)
|
50
|
-
self.create({:format => :markdown, :name => name, :content => ".", :commit => commit })
|
51
|
-
end
|
52
|
-
|
53
|
-
# Checks if the fileformat is supported
|
54
|
-
#
|
55
|
-
# format - String
|
56
|
-
#
|
57
|
-
# Returns true or false
|
58
|
-
def format_supported?(format)
|
59
|
-
supported = ['ascii', 'github-markdown','markdown', 'creole', 'org', 'pod', 'rdoc']
|
60
|
-
format.in?(supported)
|
61
|
-
end
|
62
|
-
|
63
|
-
# first creates an instance of itself and executes the save function.
|
64
|
-
#
|
65
|
-
# hash - Hash containing the page data
|
66
|
-
#
|
67
|
-
#
|
68
|
-
# Returns an instance of Gollum::Page or false
|
69
|
-
def create(hash)
|
70
|
-
page = Page.new hash
|
71
|
-
page.save
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
# calls `create` on current class. If returned value is nil an exception will be thrown
|
76
|
-
#
|
77
|
-
# hash - Hash containing the page data
|
78
|
-
#
|
79
|
-
#
|
80
|
-
# Returns an instance of Gollum::Page
|
81
|
-
def create!(hash)
|
82
|
-
action = self.create(hash)
|
83
|
-
action
|
84
|
-
end
|
85
|
-
|
86
|
-
# Finds a page based on the name and specified version
|
87
|
-
#
|
88
|
-
# name - the name of the page
|
89
|
-
#
|
90
|
-
# Return an instance of Gollum::Page
|
91
|
-
def find(name)
|
92
|
-
page = GollumRails::Adapters::Gollum::Page.new
|
93
|
-
page.find_page name
|
94
|
-
end
|
95
|
-
|
96
|
-
# Gets all pages in the wiki
|
97
|
-
def all
|
98
|
-
self.wiki.pages
|
99
|
-
end
|
100
|
-
alias_method :find_all, :all
|
101
|
-
|
102
|
-
# Gets the wiki instance
|
103
|
-
def wiki
|
104
|
-
@wiki || Adapters::Gollum::Connector.wiki_class
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
# Initializes a new Page
|
111
|
-
#
|
112
|
-
# attrs - Hash of attributes
|
113
|
-
#
|
114
|
-
# commit must be given to perform any page action!
|
115
|
-
def initialize(attrs = {})
|
116
|
-
if Adapters::Gollum::Connector.enabled
|
117
|
-
attrs.each{|k,v| self.public_send("#{k}=",v)} if attrs
|
118
|
-
else
|
119
|
-
raise GollumInternalError, 'gollum_rails is not enabled!'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
#########
|
124
|
-
# Setters
|
125
|
-
#########
|
126
|
-
|
127
|
-
|
128
|
-
# Gets / Sets the pages name
|
129
|
-
attr_accessor :name
|
130
|
-
|
131
|
-
# Gets / Sets the contents content
|
132
|
-
attr_accessor :content
|
133
|
-
|
134
|
-
# Gets / Sets the commit Hash
|
135
|
-
attr_accessor :commit
|
136
|
-
|
137
|
-
# Sets the format
|
138
|
-
attr_writer :format
|
139
|
-
|
140
|
-
|
141
|
-
#########
|
142
|
-
# Getters
|
143
|
-
#########
|
144
|
-
|
145
|
-
|
146
|
-
# Gets the pages format
|
147
|
-
def format
|
148
|
-
@format.to_sym
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
# Gets the page class
|
153
|
-
def page
|
154
|
-
@page ||= Adapters::Gollum::Connector.page_class.new
|
155
|
-
end
|
156
|
-
|
157
|
-
#############
|
158
|
-
# activemodel
|
159
|
-
#############
|
160
|
-
|
161
|
-
# Handles the connection betweet plain activemodel and Gollum
|
162
|
-
# Saves current page in GIT wiki
|
163
|
-
# If another page with the same name is existing, gollum_rails
|
164
|
-
# will detect it and returns that page instead.
|
165
|
-
#
|
166
|
-
# Examples:
|
167
|
-
#
|
168
|
-
# obj = GollumRails::Page.new <params>
|
169
|
-
# @article = obj.save
|
170
|
-
# # => Gollum::Page
|
171
|
-
#
|
172
|
-
# @article.name
|
173
|
-
# whatever name you have entered OR the name of the previous
|
174
|
-
# created page
|
175
|
-
#
|
176
|
-
#
|
177
|
-
# TODO:
|
178
|
-
# * overriding for creation(duplicates)
|
179
|
-
# * do not alias save! on save
|
180
|
-
#
|
181
|
-
# Returns an instance of Gollum::Page or false
|
182
|
-
def save
|
183
|
-
run_callbacks :save do
|
184
|
-
return false unless valid?
|
185
|
-
begin
|
186
|
-
page.new_page(name,content,format,commit)
|
187
|
-
rescue ::Gollum::DuplicatePageError => e
|
188
|
-
page.page = page.find_page(name)
|
189
|
-
end
|
190
|
-
return page.page
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
# aliasing save
|
195
|
-
#
|
196
|
-
# TODO:
|
197
|
-
# * implement full method!
|
198
|
-
alias_method :save!, :save
|
199
|
-
|
200
|
-
# Updates an existing page (or created)
|
201
|
-
#
|
202
|
-
# hash - Hash containing the attributes, you want to update
|
203
|
-
# commit - optional. If given this commit will be used instead of that one, used
|
204
|
-
# to initialize the instance
|
205
|
-
#
|
206
|
-
#
|
207
|
-
# Returns an instance of Gollum::Page
|
208
|
-
def update_attributes(hash, commit=nil)
|
209
|
-
run_callbacks :update do
|
210
|
-
page.update_page hash, get_right_commit(commit)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# Deletes current page (also available static. See below)
|
215
|
-
#
|
216
|
-
# commit - optional. If given this commit will be used instead of that one, used
|
217
|
-
# to initialize the instance
|
218
|
-
#
|
219
|
-
# Returns the commit id of the current action as String
|
220
|
-
def delete(commit=nil)
|
221
|
-
run_callbacks :delete do
|
222
|
-
page.delete_page get_right_commit(commit)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
# checks if entry already has been saved
|
227
|
-
#
|
228
|
-
#
|
229
|
-
def persisted?
|
230
|
-
return true if page.page.instance_of?(::Gollum::Page)
|
231
|
-
return false
|
232
|
-
end
|
233
|
-
# Previews the page - Mostly used if you want to see what you do before saving
|
234
|
-
#
|
235
|
-
# This is an extremely performant method!
|
236
|
-
# 1 rendering attempt take depending on the content about 0.001 (simple markdown)
|
237
|
-
# upto 0.004 (1000 chars markdown) seconds, which is quite good
|
238
|
-
#
|
239
|
-
#
|
240
|
-
# format - Specify the format you want to render with see {self.format_supported?}
|
241
|
-
# for formats
|
242
|
-
#
|
243
|
-
# Returns a String
|
244
|
-
def preview(format=:markdown)
|
245
|
-
preview = self.class.wiki.preview_page @name, @content, format
|
246
|
-
preview.formatted_data
|
247
|
-
end
|
248
|
-
|
249
|
-
|
250
|
-
#######
|
251
|
-
private
|
252
|
-
#######
|
253
|
-
|
254
|
-
# Get the right commit out of 2 commits
|
255
|
-
#
|
256
|
-
# commit_local - local commit Hash
|
257
|
-
#
|
258
|
-
# Returns local_commit > class_commit
|
259
|
-
def get_right_commit(commit_local)
|
260
|
-
com = commit if commit_local.nil?
|
261
|
-
com = commit_local if !commit_local.nil?
|
262
|
-
return com
|
263
|
-
end
|
264
|
-
|
265
|
-
end
|
266
|
-
end
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module GollumRails
|
4
|
+
|
5
|
+
# Main class, used to interact with rails.
|
6
|
+
#
|
7
|
+
# Methods, which are available:
|
8
|
+
# * find
|
9
|
+
# * update_attributes
|
10
|
+
# * find_by_*
|
11
|
+
# * create
|
12
|
+
# * new
|
13
|
+
# * save
|
14
|
+
# * delete
|
15
|
+
# * find_or_initialize_by_naname
|
16
|
+
#
|
17
|
+
class Page
|
18
|
+
extend ::ActiveModel::Callbacks
|
19
|
+
include ::ActiveModel::Validations
|
20
|
+
include ::ActiveModel::Conversion
|
21
|
+
extend ::ActiveModel::Naming
|
22
|
+
|
23
|
+
|
24
|
+
# Callback for save
|
25
|
+
define_model_callbacks :save
|
26
|
+
|
27
|
+
# Callback for update
|
28
|
+
define_model_callbacks :update
|
29
|
+
|
30
|
+
# Callback for delete
|
31
|
+
define_model_callbacks :delete
|
32
|
+
|
33
|
+
# static
|
34
|
+
class << self
|
35
|
+
# Gets / Sets the gollum page
|
36
|
+
#
|
37
|
+
attr_accessor :gollum_page
|
38
|
+
|
39
|
+
# Sets the validator
|
40
|
+
attr_writer :validator
|
41
|
+
|
42
|
+
# Finds an existing page or creates it
|
43
|
+
#
|
44
|
+
# name - The name
|
45
|
+
# commit - Hash
|
46
|
+
#
|
47
|
+
# Returns self
|
48
|
+
def find_or_initialize_by_name(name, commit)
|
49
|
+
result_for_find = self.find(name)
|
50
|
+
self.create({:format => :markdown, :name => name, :content => ".", :commit => commit })
|
51
|
+
end
|
52
|
+
|
53
|
+
# Checks if the fileformat is supported
|
54
|
+
#
|
55
|
+
# format - String
|
56
|
+
#
|
57
|
+
# Returns true or false
|
58
|
+
def format_supported?(format)
|
59
|
+
supported = ['ascii', 'github-markdown','markdown', 'creole', 'org', 'pod', 'rdoc']
|
60
|
+
format.in?(supported)
|
61
|
+
end
|
62
|
+
|
63
|
+
# first creates an instance of itself and executes the save function.
|
64
|
+
#
|
65
|
+
# hash - Hash containing the page data
|
66
|
+
#
|
67
|
+
#
|
68
|
+
# Returns an instance of Gollum::Page or false
|
69
|
+
def create(hash)
|
70
|
+
page = Page.new hash
|
71
|
+
page.save
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# calls `create` on current class. If returned value is nil an exception will be thrown
|
76
|
+
#
|
77
|
+
# hash - Hash containing the page data
|
78
|
+
#
|
79
|
+
#
|
80
|
+
# Returns an instance of Gollum::Page
|
81
|
+
def create!(hash)
|
82
|
+
action = self.create(hash)
|
83
|
+
action
|
84
|
+
end
|
85
|
+
|
86
|
+
# Finds a page based on the name and specified version
|
87
|
+
#
|
88
|
+
# name - the name of the page
|
89
|
+
#
|
90
|
+
# Return an instance of Gollum::Page
|
91
|
+
def find(name)
|
92
|
+
page = GollumRails::Adapters::Gollum::Page.new
|
93
|
+
page.find_page name
|
94
|
+
end
|
95
|
+
|
96
|
+
# Gets all pages in the wiki
|
97
|
+
def all
|
98
|
+
self.wiki.pages
|
99
|
+
end
|
100
|
+
alias_method :find_all, :all
|
101
|
+
|
102
|
+
# Gets the wiki instance
|
103
|
+
def wiki
|
104
|
+
@wiki || Adapters::Gollum::Connector.wiki_class
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# Initializes a new Page
|
111
|
+
#
|
112
|
+
# attrs - Hash of attributes
|
113
|
+
#
|
114
|
+
# commit must be given to perform any page action!
|
115
|
+
def initialize(attrs = {})
|
116
|
+
if Adapters::Gollum::Connector.enabled
|
117
|
+
attrs.each{|k,v| self.public_send("#{k}=",v)} if attrs
|
118
|
+
else
|
119
|
+
raise GollumInternalError, 'gollum_rails is not enabled!'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#########
|
124
|
+
# Setters
|
125
|
+
#########
|
126
|
+
|
127
|
+
|
128
|
+
# Gets / Sets the pages name
|
129
|
+
attr_accessor :name
|
130
|
+
|
131
|
+
# Gets / Sets the contents content
|
132
|
+
attr_accessor :content
|
133
|
+
|
134
|
+
# Gets / Sets the commit Hash
|
135
|
+
attr_accessor :commit
|
136
|
+
|
137
|
+
# Sets the format
|
138
|
+
attr_writer :format
|
139
|
+
|
140
|
+
|
141
|
+
#########
|
142
|
+
# Getters
|
143
|
+
#########
|
144
|
+
|
145
|
+
|
146
|
+
# Gets the pages format
|
147
|
+
def format
|
148
|
+
@format.to_sym
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# Gets the page class
|
153
|
+
def page
|
154
|
+
@page ||= Adapters::Gollum::Connector.page_class.new
|
155
|
+
end
|
156
|
+
|
157
|
+
#############
|
158
|
+
# activemodel
|
159
|
+
#############
|
160
|
+
|
161
|
+
# Handles the connection betweet plain activemodel and Gollum
|
162
|
+
# Saves current page in GIT wiki
|
163
|
+
# If another page with the same name is existing, gollum_rails
|
164
|
+
# will detect it and returns that page instead.
|
165
|
+
#
|
166
|
+
# Examples:
|
167
|
+
#
|
168
|
+
# obj = GollumRails::Page.new <params>
|
169
|
+
# @article = obj.save
|
170
|
+
# # => Gollum::Page
|
171
|
+
#
|
172
|
+
# @article.name
|
173
|
+
# whatever name you have entered OR the name of the previous
|
174
|
+
# created page
|
175
|
+
#
|
176
|
+
#
|
177
|
+
# TODO:
|
178
|
+
# * overriding for creation(duplicates)
|
179
|
+
# * do not alias save! on save
|
180
|
+
#
|
181
|
+
# Returns an instance of Gollum::Page or false
|
182
|
+
def save
|
183
|
+
run_callbacks :save do
|
184
|
+
return false unless valid?
|
185
|
+
begin
|
186
|
+
page.new_page(name,content,format,commit)
|
187
|
+
rescue ::Gollum::DuplicatePageError => e
|
188
|
+
page.page = page.find_page(name)
|
189
|
+
end
|
190
|
+
return page.page
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# aliasing save
|
195
|
+
#
|
196
|
+
# TODO:
|
197
|
+
# * implement full method!
|
198
|
+
alias_method :save!, :save
|
199
|
+
|
200
|
+
# Updates an existing page (or created)
|
201
|
+
#
|
202
|
+
# hash - Hash containing the attributes, you want to update
|
203
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
204
|
+
# to initialize the instance
|
205
|
+
#
|
206
|
+
#
|
207
|
+
# Returns an instance of Gollum::Page
|
208
|
+
def update_attributes(hash, commit=nil)
|
209
|
+
run_callbacks :update do
|
210
|
+
page.update_page hash, get_right_commit(commit)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Deletes current page (also available static. See below)
|
215
|
+
#
|
216
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
217
|
+
# to initialize the instance
|
218
|
+
#
|
219
|
+
# Returns the commit id of the current action as String
|
220
|
+
def delete(commit=nil)
|
221
|
+
run_callbacks :delete do
|
222
|
+
page.delete_page get_right_commit(commit)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# checks if entry already has been saved
|
227
|
+
#
|
228
|
+
#
|
229
|
+
def persisted?
|
230
|
+
return true if page.page.instance_of?(::Gollum::Page)
|
231
|
+
return false
|
232
|
+
end
|
233
|
+
# Previews the page - Mostly used if you want to see what you do before saving
|
234
|
+
#
|
235
|
+
# This is an extremely performant method!
|
236
|
+
# 1 rendering attempt take depending on the content about 0.001 (simple markdown)
|
237
|
+
# upto 0.004 (1000 chars markdown) seconds, which is quite good
|
238
|
+
#
|
239
|
+
#
|
240
|
+
# format - Specify the format you want to render with see {self.format_supported?}
|
241
|
+
# for formats
|
242
|
+
#
|
243
|
+
# Returns a String
|
244
|
+
def preview(format=:markdown)
|
245
|
+
preview = self.class.wiki.preview_page @name, @content, format
|
246
|
+
preview.formatted_data
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
#######
|
251
|
+
private
|
252
|
+
#######
|
253
|
+
|
254
|
+
# Get the right commit out of 2 commits
|
255
|
+
#
|
256
|
+
# commit_local - local commit Hash
|
257
|
+
#
|
258
|
+
# Returns local_commit > class_commit
|
259
|
+
def get_right_commit(commit_local)
|
260
|
+
com = commit if commit_local.nil?
|
261
|
+
com = commit_local if !commit_local.nil?
|
262
|
+
return com
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
end
|