gollum_rails 0.0.2.4 → 0.0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/HISTORY.md +5 -0
- data/LICENSE.md +7 -0
- data/README.md +1 -10
- data/Rakefile +1 -1
- data/gollum_rails.gemspec +34 -27
- data/lib/gollum_rails.rb +1 -1
- data/lib/gollum_rails/config.rb +1 -1
- data/lib/gollum_rails/dependency_injector.rb +18 -22
- data/lib/gollum_rails/file.rb +0 -0
- data/lib/gollum_rails/hash.rb +13 -0
- data/lib/gollum_rails/messages.yml +2 -1
- data/lib/gollum_rails/page.rb +368 -251
- data/lib/gollum_rails/versions.rb +0 -0
- data/lib/gollum_rails/wiki.rb +1 -1
- metadata +7 -4
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
data/LICENSE.md
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
## LICENSE
|
2
|
+
Copyright � 2013 Florian Kasper
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the �Software�), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED �AS IS�, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -151,13 +151,4 @@ To run tests just use the `rake` command:
|
|
151
151
|
BE CAREFUL! THE FIRST TEST WILL FAIL BECAUSE THE NECESSARY STATIC FILES ARE NOT EXISTING
|
152
152
|
|
153
153
|
|
154
|
-
## EXAMPLE
|
155
|
-
## LICENSE
|
156
|
-
Copyright � 2013 Florian Kasper
|
157
|
-
|
158
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the �Software�), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
159
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
160
|
-
|
161
|
-
THE SOFTWARE IS PROVIDED �AS IS�, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
162
|
-
|
163
|
-
|
154
|
+
## EXAMPLE
|
data/Rakefile
CHANGED
@@ -138,7 +138,7 @@ task :gemspec => :validate do
|
|
138
138
|
split("\n").
|
139
139
|
sort.
|
140
140
|
reject { |file| file =~ /^\./ }.
|
141
|
-
reject { |file| file =~ /^(
|
141
|
+
reject { |file| file =~ /^(doc|pkg|test|Home\.md|\.gitattributes)/ }.
|
142
142
|
map { |file| " #{file}" }.
|
143
143
|
join("\n")
|
144
144
|
|
data/gollum_rails.gemspec
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
2
|
+
s.rubygems_version = '1.3.5'
|
3
|
+
s.name = 'gollum_rails'
|
4
|
+
s.version = '0.0.2.5'
|
5
|
+
|
6
|
+
s.summary = 'Combines the benefits from Gollum with Rails'
|
7
|
+
s.description= 'use templating, authentication and so on'
|
8
|
+
#File.read(File.join(File.dirname(__FILE__), 'README.md'))
|
9
|
+
|
10
|
+
s.add_dependency('activemodel', '~> 3.2.11')
|
11
|
+
s.add_dependency('gollum', '~> 2.4.11')
|
12
|
+
s.add_dependency('grit', '~> 2.5.0')
|
13
|
+
s.add_dependency('builder', '~> 3.0.0')
|
14
|
+
s.add_dependency('rack', '~> 1.4.0')
|
15
|
+
s.add_development_dependency('org-ruby', '~> 0.7.2')
|
16
|
+
s.add_development_dependency('shoulda', '~> 3.3.2')
|
17
|
+
s.add_development_dependency('rack-test', '~> 0.6.2')
|
18
|
+
s.add_development_dependency('rake', '~> 10.0.2')
|
19
|
+
s.add_development_dependency('rails', '~> 3.2.11')
|
20
|
+
|
21
|
+
s.author = 'Florian Kasper'
|
22
|
+
s.email = 'nirnanaaa@khnetworks.com'
|
23
|
+
s.homepage = 'https://github.com/nirnanaaa/gollum_rails'
|
24
|
+
s.platform = Gem::Platform::RUBY
|
25
|
+
s.required_ruby_version = '>=1.9'
|
26
|
+
|
25
27
|
# = MANIFEST =
|
26
28
|
s.files = %w[
|
27
29
|
Gemfile
|
@@ -35,15 +37,20 @@ Gem::Specification.new do |s|
|
|
35
37
|
lib/gollum_rails/config.rb
|
36
38
|
lib/gollum_rails/dependency_injector.rb
|
37
39
|
lib/gollum_rails/engine.rb
|
40
|
+
lib/gollum_rails/file.rb
|
38
41
|
lib/gollum_rails/gollum_rails.rb
|
39
42
|
lib/gollum_rails/hash.rb
|
40
43
|
lib/gollum_rails/messages.yml
|
41
44
|
lib/gollum_rails/page.rb
|
42
45
|
lib/gollum_rails/validations.rb
|
46
|
+
lib/gollum_rails/versions.rb
|
43
47
|
lib/gollum_rails/wiki.rb
|
44
48
|
]
|
45
49
|
# = MANIFEST =
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
|
51
|
+
|
52
|
+
s.require_paths = %w[lib]
|
53
|
+
s.has_rdoc = true
|
54
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
55
|
+
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
56
|
+
end
|
data/lib/gollum_rails.rb
CHANGED
data/lib/gollum_rails/config.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
1
|
module GollumRails
|
2
|
-
|
3
|
-
|
2
|
+
## simple DI component
|
3
|
+
class DependencyInjector
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
self.initialize
|
16
|
-
end
|
17
|
-
@storage[name] = value
|
18
|
-
end
|
5
|
+
@storage = {}
|
6
|
+
|
7
|
+
#sets a storage Hash
|
8
|
+
def self.register(&block)
|
9
|
+
block.call(self)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.set(arguments = {})
|
13
|
+
arguments.each{ |key, value| @storage[key] = value}
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@storage[name]
|
16
|
+
def self.method_missing(method, *arguments, &block)
|
17
|
+
if @storage[method]
|
18
|
+
return @storage[method]
|
19
|
+
else
|
20
|
+
return false
|
26
21
|
end
|
27
22
|
end
|
23
|
+
end
|
28
24
|
end
|
File without changes
|
data/lib/gollum_rails/hash.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
+
# Public: Extend Hash class by a method missing call
|
1
2
|
class ::Hash
|
3
|
+
|
4
|
+
# Public: Converts a method . into an Hash element
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
# hash = {a: "b", b: "c", c: "d"}
|
8
|
+
# hash.a
|
9
|
+
# # => "b"
|
10
|
+
# hash.b
|
11
|
+
# # => "c"
|
12
|
+
#
|
13
|
+
# Returns an instance of Hash if the name is the key of a new hash
|
14
|
+
# otherwise it will return the value of the key
|
2
15
|
def method_missing(name)
|
3
16
|
return self[name] if key? name
|
4
17
|
self.each { |k,v| return v if k.to_s.to_sym == name }
|
@@ -4,4 +4,5 @@ messages:
|
|
4
4
|
commit_must_be_given: Commit must not be empty or nil
|
5
5
|
no_page_fetched: No page was fetched
|
6
6
|
no_page_found: The page was not found
|
7
|
-
format_not_set: The format was not set
|
7
|
+
format_not_set: The format was not set
|
8
|
+
wiki_could_not_be_loaded: The wiki instance in ::Page is not an Instance of GollumRails::Wiki or is empty
|
data/lib/gollum_rails/page.rb
CHANGED
@@ -1,281 +1,398 @@
|
|
1
1
|
# ~*~ encoding: utf-8 ~*~
|
2
2
|
require "gollum_rails/hash"
|
3
|
+
|
3
4
|
module GollumRails
|
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
|
-
|
5
|
+
class Page
|
6
|
+
include ActiveModel::Conversion
|
7
|
+
include ActiveModel::Validations
|
8
|
+
extend ActiveModel::Naming
|
9
|
+
|
10
|
+
|
11
|
+
# Public: Gets/Sets the name of the document
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
# Public: Gets/Sets the content of the document
|
15
|
+
attr_accessor :content
|
16
|
+
|
17
|
+
# Public: Gets/Sets the format of the document
|
18
|
+
#
|
19
|
+
# Examples
|
20
|
+
# Page.format = :creole
|
21
|
+
# #or
|
22
|
+
# Page.format = :markdown
|
23
|
+
#
|
24
|
+
# Possible formats are
|
25
|
+
# - :asciidoc
|
26
|
+
# - :creole
|
27
|
+
# - :markdown
|
28
|
+
# - :org
|
29
|
+
# - :pod
|
30
|
+
# - :rdoc
|
31
|
+
# - :rst
|
32
|
+
# - :tex
|
33
|
+
# - :wiki
|
34
|
+
attr_accessor :format
|
35
|
+
|
36
|
+
# Public: Gets/Sets the commiters credentials
|
37
|
+
#
|
38
|
+
# commit - The commit Hash details:
|
39
|
+
# :message - The String commit message.
|
40
|
+
# :name - The String author full name.
|
41
|
+
# :email - The String email address.
|
42
|
+
# :parent - Optional Grit::Commit parent to this update.
|
43
|
+
# :tree - Optional String SHA of the tree to create the
|
44
|
+
# index from.
|
45
|
+
# :committer - Optional Gollum::Committer instance. If provided,
|
46
|
+
# assume that this operation is part of batch of
|
47
|
+
# updates and the commit happens later.
|
48
|
+
#
|
49
|
+
# Examples:
|
50
|
+
# commit = {
|
51
|
+
# message: 'page created',
|
52
|
+
# name: 'Florian Kasper',
|
53
|
+
# email: 'nirnanaaa@khnetworks.com'
|
54
|
+
# }
|
55
|
+
#
|
56
|
+
attr_accessor :commit
|
57
|
+
|
58
|
+
#########
|
59
|
+
# READERs
|
60
|
+
#########
|
61
|
+
|
62
|
+
# Public: Gets the options
|
63
|
+
attr_reader :options
|
64
|
+
|
65
|
+
# Public: Gets the persistance of objects by save(), update(), delete() methods
|
66
|
+
attr_reader :persisted
|
67
|
+
|
68
|
+
# Public: Gets the error messages
|
69
|
+
attr_reader :error
|
70
|
+
|
71
|
+
# Public: Gets the instance of Gollum::Wiki
|
72
|
+
attr_reader :wiki
|
73
|
+
|
74
|
+
# Public: Gets ?!
|
75
|
+
attr_reader :class
|
76
|
+
# Public: Initializes a new Page instance
|
77
|
+
#
|
78
|
+
# attributes - A hash of attributes. See example
|
79
|
+
# options - Will be merged with the configuration
|
80
|
+
#
|
81
|
+
# Examples
|
82
|
+
# GollumRails::Page.new({name: '', content: '', format: '', commit: {}})
|
83
|
+
#
|
84
|
+
#
|
85
|
+
# Explanation:
|
86
|
+
# name must be a string.
|
87
|
+
# content should be a text/String
|
88
|
+
# format must be eighter :markdown, :latex, :rdoc, ...
|
89
|
+
# commit must be a hash for example:
|
90
|
+
#
|
91
|
+
# Raises RuntimeError if the wiki was not initialized
|
92
|
+
# Raises RuntimeError if no configuration was provided
|
93
|
+
#
|
94
|
+
# Returns an instance of this class
|
95
|
+
def initialize(attributes = {}, options = {})
|
96
|
+
wiki = DependencyInjector.wiki
|
97
|
+
config = DependencyInjector.config
|
98
|
+
if wiki && wiki.is_a?(Wiki) && wiki_loaded?(wiki.wiki)
|
99
|
+
@wiki = wiki
|
100
|
+
else
|
101
|
+
#must be hardcoded, cause no options are loaded
|
102
|
+
raise RuntimeError, "No wiki loaded"
|
103
|
+
end
|
104
|
+
if config && config.is_a?(Hash)
|
105
|
+
@options = config
|
106
|
+
options.each{|k,v| @options[k] = v}
|
107
|
+
else
|
108
|
+
raise RuntimeError, "No configuration provided"
|
109
|
+
end
|
110
|
+
if !Validations.is_boolean?(@persisted)
|
111
|
+
@persisted = false
|
112
|
+
end
|
113
|
+
if !@error
|
114
|
+
@error = nil
|
115
|
+
end
|
116
|
+
attributes.each do |name, value|
|
117
|
+
send("#{name}=", value)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
# Public: Checks if the given Instance is an Instance of the Gollum Wiki
|
123
|
+
#
|
124
|
+
# wiki - An instance of a class
|
125
|
+
#
|
126
|
+
# Examples
|
127
|
+
# wiki_loaded?(Gollum::Wiki)
|
128
|
+
# # => true
|
129
|
+
#
|
130
|
+
# Returns if the given instance is an instance of Gollum::Wiki
|
131
|
+
def wiki_loaded?(wiki)
|
132
|
+
wiki.is_a?(Gollum::Wiki)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Public: Gets the @error message
|
136
|
+
#
|
137
|
+
# Examples:
|
138
|
+
# puts get_error_message
|
139
|
+
# # => 'An Error Occured'
|
140
|
+
#
|
141
|
+
# Returns an Error message
|
142
|
+
def get_error_message
|
143
|
+
@error
|
144
|
+
end
|
145
|
+
|
146
|
+
# Public: saves this instance
|
147
|
+
|
148
|
+
def save
|
149
|
+
if valid?
|
150
|
+
begin
|
151
|
+
@wiki.wiki.write_page(@name, @format, @content, @commit)
|
152
|
+
@persisted = true
|
153
|
+
rescue Gollum::DuplicatePageError => e
|
154
|
+
@error = e
|
155
|
+
return false
|
86
156
|
end
|
87
|
-
|
88
157
|
end
|
158
|
+
return true
|
159
|
+
end
|
89
160
|
|
90
|
-
|
91
|
-
|
92
|
-
|
161
|
+
#rewrite for save() method with raising exceptions as well
|
162
|
+
def save!
|
163
|
+
saves = save
|
164
|
+
if @error
|
165
|
+
raise RuntimeError, @error
|
166
|
+
else
|
167
|
+
return saves
|
93
168
|
end
|
94
169
|
|
95
|
-
|
96
|
-
|
97
|
-
|
170
|
+
end
|
171
|
+
|
172
|
+
# Updates an existing page
|
173
|
+
# usage:
|
174
|
+
#
|
175
|
+
#
|
176
|
+
# wiki = GollumRails::Wiki.new(PATH)
|
177
|
+
#
|
178
|
+
# page = GollumRails::Page.new
|
179
|
+
# cnt = page.find(PAGENAME)
|
180
|
+
#
|
181
|
+
# commit = {
|
182
|
+
# :message => "production test update",
|
183
|
+
# :name => 'Florian Kasper',
|
184
|
+
# :email => 'nirnanaaa@khnetworks.com'
|
185
|
+
# }
|
186
|
+
# update = page.update("content", commit)
|
187
|
+
|
188
|
+
def update(content, commit, name=nil, format=nil)
|
189
|
+
if !name.nil?
|
190
|
+
@name = name
|
191
|
+
end
|
192
|
+
if !format.nil?
|
193
|
+
@format = format
|
194
|
+
end
|
195
|
+
if commit.nil? || content.nil?
|
196
|
+
@error = @options.messages.commit_not_empty_and_content_not_empty
|
197
|
+
return false
|
98
198
|
end
|
199
|
+
return @wiki.wiki.update_page(@page, @name, @format, content, commit)
|
200
|
+
end
|
99
201
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
@error = e
|
108
|
-
return false
|
109
|
-
end
|
110
|
-
end
|
111
|
-
return true
|
202
|
+
#Public: alias for update with exceptions
|
203
|
+
def update!(content, commit, name=nil, format=nil)
|
204
|
+
updates = update(content, commit, name=nil, format=nil)
|
205
|
+
if @error
|
206
|
+
raise RuntimeError, @error
|
207
|
+
else
|
208
|
+
return updates
|
112
209
|
end
|
210
|
+
end
|
113
211
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
else
|
120
|
-
return saves
|
121
|
-
end
|
122
|
-
|
212
|
+
#Public: Deletes page fetched by find()
|
213
|
+
def delete(commit)
|
214
|
+
if commit.nil?
|
215
|
+
@error = @options.messages.commit_must_be_given
|
216
|
+
return false
|
123
217
|
end
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
# :name => 'Florian Kasper',
|
136
|
-
# :email => 'nirnanaaa@khnetworks.com'
|
137
|
-
# }
|
138
|
-
# update = page.update("content", commit)
|
139
|
-
|
140
|
-
def update(content, commit, name=nil, format=nil)
|
141
|
-
if !name.nil?
|
142
|
-
@name = name
|
143
|
-
end
|
144
|
-
if !format.nil?
|
145
|
-
@format = format
|
146
|
-
end
|
147
|
-
if commit.nil? || content.nil?
|
148
|
-
@error = @options.messages.commit_not_empty_and_content_not_empty
|
149
|
-
return false
|
150
|
-
end
|
151
|
-
return @wiki.wiki.update_page(@page, @name, @format, content, commit)
|
218
|
+
return @wiki.wiki.delete_page(@page, commit)
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
#Public: alias for delete with exceptions
|
223
|
+
def delete!(commit)
|
224
|
+
deletes = delete(commit)
|
225
|
+
if @error
|
226
|
+
raise RuntimeError, @error
|
227
|
+
else
|
228
|
+
return deletes
|
152
229
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
230
|
+
end
|
231
|
+
|
232
|
+
#Public: For outputting all pages
|
233
|
+
def all
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
# Public: Renders a preview (usable e.g. with ajax)
|
238
|
+
#
|
239
|
+
#
|
240
|
+
# Returns rendered HTML
|
241
|
+
def preview(name = nil, content = nil, format = :markdown)
|
242
|
+
if !name or name == nil
|
243
|
+
name = @name
|
161
244
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
def delete!(commit)
|
166
|
-
deletes = delete(commit)
|
167
|
-
if @error
|
168
|
-
raise RuntimeError, @error
|
169
|
-
else
|
170
|
-
return deletes
|
171
|
-
end
|
245
|
+
if !content or content == nil
|
246
|
+
content = @content
|
172
247
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
248
|
+
return @wiki.wiki.preview_page(name, content, format).formatted_data
|
249
|
+
end
|
250
|
+
|
251
|
+
# Public: Validates class variables
|
252
|
+
#
|
253
|
+
#
|
254
|
+
# Returns either true or false
|
255
|
+
def valid?
|
256
|
+
if !@name || @name.nil?
|
257
|
+
@error = @options.messages.name_not_set_or_nil
|
258
|
+
return false
|
182
259
|
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
if @page
|
187
|
-
@page.formatted_data
|
188
|
-
else
|
189
|
-
@error = @options.messages.no_page_fetched
|
190
|
-
return false
|
191
|
-
end
|
260
|
+
if !@commit || !@commit.is_a?(Hash)
|
261
|
+
@error = @options.messages.commit_must_be_given
|
262
|
+
return false
|
192
263
|
end
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
# Page.version.first.authored_data
|
197
|
-
#
|
198
|
-
#
|
199
|
-
# see Active Model documentation
|
200
|
-
def version
|
201
|
-
if @page
|
202
|
-
@page.versions
|
203
|
-
else
|
204
|
-
@error = @options.messages.no_page_fetched
|
205
|
-
return false
|
206
|
-
end
|
264
|
+
if !@format
|
265
|
+
@error = @options.messages.format_not_set
|
266
|
+
return false
|
207
267
|
end
|
208
268
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
@error = @options.messages.name_not_set_or_nil
|
219
|
-
return false
|
220
|
-
end
|
221
|
-
if !@commit || !@commit.is_a?(Hash)
|
222
|
-
@error = @options.messages.commit_must_be_given
|
223
|
-
return false
|
224
|
-
end
|
225
|
-
if !@format
|
226
|
-
@error = @options.messages.format_not_set
|
227
|
-
return false
|
228
|
-
end
|
229
|
-
|
230
|
-
#super #doesn't work atm
|
231
|
-
|
232
|
-
return true
|
233
|
-
end
|
269
|
+
return true
|
270
|
+
end
|
271
|
+
|
272
|
+
# Public: Gets an instance of Gollum::Page
|
273
|
+
#
|
274
|
+
# name - Search string
|
275
|
+
#
|
276
|
+
# Returns nil if no result was found or no name was given
|
277
|
+
attr_reader :page
|
234
278
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
@page = page
|
250
|
-
@name = page.name
|
251
|
-
@format = page.format
|
252
|
-
|
253
|
-
return page
|
254
|
-
else
|
279
|
+
# Public: Finds a page based on given search string
|
280
|
+
#
|
281
|
+
# Be careful: At the moment you must initialize the class by .new
|
282
|
+
#
|
283
|
+
# Examples
|
284
|
+
# page = Page.new attributes
|
285
|
+
# page.find('static')
|
286
|
+
#
|
287
|
+
# Returns either nil or an instance of Gollum::Page
|
288
|
+
def find(name = nil)
|
289
|
+
if !name.nil?
|
290
|
+
page = @wiki.wiki.page(name)
|
291
|
+
if page.nil?
|
292
|
+
@error = @options.messages.no_page_found
|
255
293
|
return nil
|
256
294
|
end
|
295
|
+
|
296
|
+
#need a better solution. Thats fu***** bull*****
|
297
|
+
@page = page
|
298
|
+
@name = page.name
|
299
|
+
@format = page.format
|
300
|
+
|
301
|
+
return page
|
302
|
+
else
|
303
|
+
@error = @options.messages.name_not_set_or_nil
|
304
|
+
return nil
|
257
305
|
end
|
306
|
+
end
|
258
307
|
|
259
|
-
|
260
|
-
|
308
|
+
# Public: Checks if the object is already persisted
|
309
|
+
#
|
310
|
+
# Examples
|
311
|
+
# page = Page.new
|
312
|
+
# page.persisted?
|
313
|
+
# # => false
|
314
|
+
# page.save
|
315
|
+
# page.persisted?
|
316
|
+
# # => false
|
317
|
+
#
|
318
|
+
# @commit = {
|
319
|
+
# :message => "test creation of page",
|
320
|
+
# :name => 'Florian Kasper',
|
321
|
+
# :email => 'nirnanaaa@khnetworks.com'
|
322
|
+
# }
|
323
|
+
# attributes = {
|
324
|
+
# name: 'TestPage',
|
325
|
+
# content: 'content',
|
326
|
+
# format: :markdown,
|
327
|
+
# commit: @commit
|
328
|
+
# }
|
329
|
+
# page.save
|
330
|
+
# page.persisted?
|
331
|
+
# # => true
|
332
|
+
#
|
333
|
+
# Returns a Boolean(false|true)
|
334
|
+
def persisted?
|
335
|
+
@persisted
|
336
|
+
end
|
337
|
+
|
338
|
+
# Public: Magic method ( static )
|
339
|
+
#
|
340
|
+
# name - The functions name
|
341
|
+
# args - Pointer of arguments
|
342
|
+
#
|
343
|
+
# Static into non static converter
|
344
|
+
def self.method_missing(name, *args)
|
345
|
+
klass = self.new
|
346
|
+
return klass.find(args) if name.to_s == 'find'
|
347
|
+
end
|
348
|
+
|
349
|
+
################################################
|
350
|
+
######### P A G E # L O A D E D ################
|
351
|
+
################################################
|
352
|
+
|
353
|
+
# Public: A simple wrapper for Gollum::Page.raw_data
|
354
|
+
#
|
355
|
+
# Page needs to be loaded!
|
356
|
+
#
|
357
|
+
# Returns raw data
|
358
|
+
def raw_data
|
359
|
+
if @page
|
360
|
+
@page.raw_data
|
361
|
+
else
|
362
|
+
@error = @options.messages.no_page_fetched
|
363
|
+
return false
|
261
364
|
end
|
365
|
+
end
|
262
366
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
367
|
+
# Public: A simple wrapper for Gollum::Page.formatted_data
|
368
|
+
#
|
369
|
+
# Page needs to be loaded!
|
370
|
+
#
|
371
|
+
# Returns formatted html
|
372
|
+
def formatted_data
|
373
|
+
if @page
|
374
|
+
@page.formatted_data
|
375
|
+
else
|
376
|
+
@error = @options.messages.no_page_fetched
|
377
|
+
return false
|
267
378
|
end
|
268
|
-
|
269
|
-
# meth = name.to_s.index("find_by_")
|
270
|
-
# if meth.nil?
|
271
|
-
# @error = "method not found"
|
272
|
-
# raise RuntimeError
|
273
|
-
# end
|
274
|
-
# finder = name[8 .. name.length]
|
275
|
-
# if finder == "name"
|
276
|
-
# find(args)
|
277
|
-
# end
|
278
|
-
# end
|
379
|
+
end
|
279
380
|
|
381
|
+
# Public: Active Record like
|
382
|
+
#
|
383
|
+
# Page.version.first.id
|
384
|
+
# Page.version.first.authored_data
|
385
|
+
#
|
386
|
+
#
|
387
|
+
# see Active Model documentation
|
388
|
+
def version
|
389
|
+
if @page
|
390
|
+
@page.versions
|
391
|
+
else
|
392
|
+
@error = @options.messages.no_page_fetched
|
393
|
+
return false
|
394
|
+
end
|
280
395
|
end
|
281
|
-
|
396
|
+
|
397
|
+
end
|
398
|
+
end
|
File without changes
|
data/lib/gollum_rails/wiki.rb
CHANGED
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gollum_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Florian Kasper
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
@@ -188,16 +188,19 @@ files:
|
|
188
188
|
- lib/gollum_rails/config.rb
|
189
189
|
- lib/gollum_rails/dependency_injector.rb
|
190
190
|
- lib/gollum_rails/engine.rb
|
191
|
+
- lib/gollum_rails/file.rb
|
191
192
|
- lib/gollum_rails/gollum_rails.rb
|
192
193
|
- lib/gollum_rails/hash.rb
|
193
194
|
- lib/gollum_rails/messages.yml
|
194
195
|
- lib/gollum_rails/page.rb
|
195
196
|
- lib/gollum_rails/validations.rb
|
197
|
+
- lib/gollum_rails/versions.rb
|
196
198
|
- lib/gollum_rails/wiki.rb
|
197
199
|
homepage: https://github.com/nirnanaaa/gollum_rails
|
198
200
|
licenses: []
|
199
201
|
post_install_message:
|
200
|
-
rdoc_options:
|
202
|
+
rdoc_options:
|
203
|
+
- --charset=UTF-8
|
201
204
|
require_paths:
|
202
205
|
- lib
|
203
206
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -214,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
217
|
version: '0'
|
215
218
|
segments:
|
216
219
|
- 0
|
217
|
-
hash:
|
220
|
+
hash: 658049395
|
218
221
|
requirements: []
|
219
222
|
rubyforge_project:
|
220
223
|
rubygems_version: 1.8.23
|