gollum_rails 1.4.1 → 1.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9baab7df51ee264f15748a5a0545fb5b9b8260e
4
- data.tar.gz: 102049591d936c7daf3aaa2fbc38c1cb88be46ef
3
+ metadata.gz: ac973e7abd2f4b27cdc5568448bc2b604a8a43bc
4
+ data.tar.gz: b8dbaa9689b6ac1ada39efc362dea305a3fe00ef
5
5
  SHA512:
6
- metadata.gz: 5b6803db7979639b77e5a1b676427b45072c1ae8e990ec425e074bacc2c50b3be55e12709c5427124635fc72272606e6c34377f47272dfbd99833d07b5cb6d55
7
- data.tar.gz: c449d6e1a6e6b48f814fe67e99e68b4b1d8e5bb37c791eb6febd35310e0f51074d2b1731ec5a28d104ac4e7692109d054c3d0df159533db5f7c92eb14a8d877e
6
+ metadata.gz: 02ce3f25360dd389980da220ec91ce2f8a08abccb56799933e705523da96beccf5031ead746a3f24495d713db7b64bb46287f3919e8963e1ac118da3fe75ff7e
7
+ data.tar.gz: d4a7a8b643cfbf61a6c57e3f48eadac25d6434978ba972a2e288cbeac6824198cc349bd272d38b05f6e7ec3ce71147c49ad5369beb1d27dde8e91413a7a83fbf
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gollum_rails (1.4.1)
4
+ gollum_rails (1.4.2)
5
5
  activemodel (>= 4.0.0)
6
- gollum-lib (~> 1.0.0)
6
+ gollum-lib (~> 1.0.4)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -46,14 +46,14 @@ GEM
46
46
  erubis (2.7.0)
47
47
  github-markdown (0.5.3)
48
48
  github-markup (0.7.5)
49
- gollum-lib (1.0.3)
49
+ gollum-lib (1.0.4)
50
50
  github-markdown (~> 0.5.3)
51
51
  github-markup (>= 0.7.5, < 1.0.0)
52
52
  grit (~> 2.5.0)
53
- nokogiri (~> 1.5.9, < 1.6.0)
54
- pygments.rb (~> 0.5.0)
55
- sanitize (~> 2.0.3, < 2.0.4)
56
- stringex (~> 1.5.1)
53
+ nokogiri (~> 1.6.0)
54
+ pygments.rb (~> 0.5.2)
55
+ sanitize (~> 2.0.6)
56
+ stringex (~> 2.0.5)
57
57
  grit (2.5.0)
58
58
  diff-lcs (~> 1.1)
59
59
  mime-types (~> 1.15)
@@ -64,12 +64,14 @@ GEM
64
64
  mime-types (~> 1.16)
65
65
  treetop (~> 1.4.8)
66
66
  mime-types (1.23)
67
+ mini_portile (0.5.1)
67
68
  minitest (4.7.5)
68
69
  multi_json (1.7.3)
69
- nokogiri (1.5.10)
70
+ nokogiri (1.6.0)
71
+ mini_portile (~> 0.5.0)
70
72
  polyglot (0.3.3)
71
73
  posix-spawn (0.3.6)
72
- pygments.rb (0.5.1)
74
+ pygments.rb (0.5.2)
73
75
  posix-spawn (~> 0.3.6)
74
76
  yajl-ruby (~> 1.1.0)
75
77
  rack (1.5.2)
@@ -100,8 +102,8 @@ GEM
100
102
  rspec-expectations (2.13.0)
101
103
  diff-lcs (>= 1.1.3, < 2.0)
102
104
  rspec-mocks (2.13.1)
103
- sanitize (2.0.3)
104
- nokogiri (>= 1.4.4, < 1.6)
105
+ sanitize (2.0.6)
106
+ nokogiri (>= 1.4.4)
105
107
  simplecov (0.7.1)
106
108
  multi_json (~> 1.0)
107
109
  simplecov-html (~> 0.7.1)
@@ -115,7 +117,7 @@ GEM
115
117
  actionpack (>= 3.0)
116
118
  activesupport (>= 3.0)
117
119
  sprockets (~> 2.8)
118
- stringex (1.5.1)
120
+ stringex (2.0.6)
119
121
  thor (0.18.1)
120
122
  thread_safe (0.1.0)
121
123
  atomic
data/HISTORY.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 1.4.2 1th August 2013
2
+ * Found an issue that the Wiki was not updating from external pushes
3
+ * Some helper methods implemented
4
+ * Improved code quality
5
+ * Should be threadsaver now
6
+ * Updated documentation
7
+
8
+ # 1.4.1 26th June 2013
9
+ * Rails4
1
10
 
2
11
  # 1.0.4 1th May 2013
3
12
  * removed mutex again
data/README.md CHANGED
@@ -6,7 +6,7 @@ Gollum for Rails
6
6
  [![Coverage Status](https://coveralls.io/repos/nirnanaaa/gollum_rails/badge.png?branch=master)](https://coveralls.io/r/nirnanaaa/gollum_rails)
7
7
 
8
8
 
9
- gollum_rails combines the git-powered wiki software gollum with the extremely popular webframework rails.
9
+ gollum_rails combines the git-powered wiki software gollum with the extreme popular webframework rails.
10
10
  It improves the lightweight "gollum" experience which is quite awesome.
11
11
 
12
12
  with gollum_rails you can:
@@ -4,13 +4,13 @@ Gem::Specification.new do |s|
4
4
  s.name = 'gollum_rails'
5
5
  s.rubyforge_project = s.name
6
6
 
7
- s.version = '1.4.1'
7
+ s.version = '1.4.2'
8
8
 
9
9
  s.summary = 'Combines Gollum and Rails'
10
10
  s.description= 'include Gollum into Rails with ease'
11
11
 
12
12
  s.add_dependency 'activemodel', '>= 4.0.0'
13
- s.add_dependency 'gollum-lib', '~> 1.0.0'
13
+ s.add_dependency 'gollum-lib', '~> 1.0.4'
14
14
 
15
15
  s.add_development_dependency 'rspec', '~> 2.13.0'
16
16
  s.add_development_dependency 'rr', '~> 1.1.1'
@@ -59,7 +59,7 @@ Gem::Specification.new do |s|
59
59
  spec/gollum_rails/adapters/gollum/connector_spec.rb
60
60
  spec/gollum_rails/adapters/gollum/error_spec.rb
61
61
  spec/gollum_rails/adapters/gollum/page_spec.rb
62
- spec/gollum_rails/adapters/gollum/wiki_spec.rb
62
+ spec/gollum_rails/adapters/gollum/wiki_spec_off.rb
63
63
  spec/gollum_rails/error_spec.rb
64
64
  spec/gollum_rails/page_spec.rb
65
65
  spec/gollum_rails/respository_spec.rb
@@ -23,7 +23,7 @@ module GollumRails
23
23
  autoload :Setup, 'gollum_rails/setup'
24
24
 
25
25
  # GollumRails version string
26
- VERSION = '1.4.1'
26
+ VERSION = '1.4.2'
27
27
 
28
28
  # Simplified error
29
29
  class Error < StandardError; end
@@ -20,7 +20,11 @@ module GollumRails
20
20
  attr_writer :page_class
21
21
 
22
22
  # Sets the wiki class used by all instances
23
- attr_writer :wiki_class
23
+ attr_writer :wiki_path
24
+
25
+ # Sets the wiki options
26
+ attr_writer :wiki_options
27
+
24
28
 
25
29
  # Sets the applications status
26
30
  attr_writer :enabled
@@ -38,13 +42,18 @@ module GollumRails
38
42
  def page_class
39
43
  @page_class || Page
40
44
  end
45
+
46
+ # Gets the wiki options
47
+ def wiki_options
48
+ @wiki_options || {}
49
+ end
41
50
 
42
51
  # Gets the Globally used Page class or use a new one if not defined
43
52
  #
44
53
  #
45
54
  # Returns the internal page class or a fresh ::Gollum::Page
46
- def wiki_class
47
- @wiki_class || Wiki
55
+ def wiki_path
56
+ @wiki_path || ""
48
57
  end
49
58
 
50
59
  end
@@ -18,70 +18,92 @@ module GollumRails
18
18
 
19
19
  Connector.page_class = self
20
20
 
21
- # Gets / Sets current page
22
- attr_accessor :page
23
-
24
- # Gets / Sets the wiki
25
- attr_accessor :wiki
26
-
27
21
  class << self
28
22
 
23
+ # == Parses a given filepath e.g. '/test/page'
24
+ # Name is page
25
+ # path is /test
26
+ #
27
+ # Returns a Hash
28
+ def parse_path(name)
29
+ path = '/'
30
+ name = name.to_s
31
+ if name.include?('/')
32
+ name = name[1..-1] if name[0] == "/"
33
+ content = name.split('/')
34
+ name = content.pop
35
+ path = '/'+content.join('/')
36
+ end
37
+ { path: path, name: name }
38
+ end
39
+
29
40
  # finds all versions of a page
30
41
  #
31
42
  # name - the pagename to search
43
+ # wiki - instance of Gollum::Wiki
32
44
  #
33
45
  # Returns the Gollum::Page class
34
- def find_page(name)
35
- Connector.wiki_class.page ::Gollum::Page.cname(name)
46
+ def find_page(name, wiki)
47
+ path_data = parse_path(name)
48
+ wiki.paged(path_data[:name], path_data[:path], exact = true)
36
49
  end
37
-
38
50
  end
39
51
 
40
- # creates a new Page
52
+ # == Creates a new page
41
53
  #
42
- # name - String
43
- # type - Symbol
44
- # content - Text
45
- # commit - Hash or instance of Committer
54
+ # name - The name of the page
55
+ # content - The content of the page
56
+ # wiki - An instance of Gollum::Wiki
57
+ # type - A filetype as symbol (optional)
58
+ # commit - Commit Hash
46
59
  #
47
- # Returns the commit id
48
- def new_page( name, content,type=:markdown, commit={} )
49
- Connector.wiki_class.write_page name.to_s, type, content, commit if name
50
- @page = Connector.wiki_class.page name
51
- @page
60
+ # Returns the page
61
+ def new_page( name, content, wiki, type=:markdown, commit={} )
62
+ path_data = self.class.parse_path(name)
63
+ wiki.write_page( path_data[:name], type, content, commit, path_data[:path].gsub!(/^\//, "").gsub!(/(\/)+$/,'') || "" )
64
+ self.class.find_page( name, wiki )
52
65
  end
53
66
 
54
- # updates an existing page
67
+ # == Updates an existing page
68
+ #
69
+ # page - An instance of Gollum::Page
70
+ # wiki - An instance of Gollum::Wiki
71
+ # content - New content
72
+ # commit - Commit Hash
73
+ # name - A new String (optional)
74
+ # format - A filetype as symbol (optional)
75
+ #
76
+ # Returns the page
77
+ def update_page( page, wiki, content=nil, commit={}, name=nil, format=nil)
78
+ return if !page || ((!content||page.raw_data == content) && page.format == format)
79
+ name ||= page.name
80
+ format = (format || page.format).to_sym
81
+ content ||= page.raw_data
82
+ wiki.update_page(page,name,format,content.to_s,commit)
83
+ self.class.find_page( mixin(page.url_path, name), wiki )
84
+ end
85
+
86
+ # == Preview page
55
87
  #
56
- # new - Hash with changed data
57
- # commit - Hash or instance of Committer
58
- # old - also an instance of self
88
+ # wiki - An instance of Gollum::Wiki
89
+ # content - New content
90
+ # name - A String
91
+ # format - A filetype as symbol (optional)
59
92
  #
60
- # Returns the commit id
61
- def update_page( new, commit={}, old=nil)
62
- if new.is_a?(Hash)
63
- commit_id = Connector.wiki_class.update_page (old||@page),
64
- new[:name]||@page.name,
65
- new[:format]||@page.format,
66
- new[:content]||@page.raw_data,
67
- commit
68
- else
69
- raise Error.new "commit must be a Hash. #{new.class} given", :crit
70
- end
71
-
72
- # this is very ugly. Shouldn't gollum return the new page?
73
- @page = @page.find(new[:name]||@page.name, commit_id)
74
- @page
93
+ def preview_page(wiki, name, content, format=:markdown)
94
+ page = wiki.preview_page(name,content,format)
95
+ page.formatted_data
75
96
  end
76
97
 
77
- # deletes an existing page
98
+ # == Deletes an existing page
78
99
  #
79
- # page - instance of self
80
- # commit - Hash or instance of Committer
100
+ # page - Gollum::Page
101
+ # wiki - Gollum::Wiki
102
+ # commit - Commit Hash
81
103
  #
82
104
  # Returns the commit id
83
- def delete_page( commit={}, page = nil )
84
- Connector.wiki_class.delete_page (page||@page), commit
105
+ def delete_page( page,wiki,commit={} )
106
+ wiki.delete_page(page, commit)
85
107
  end
86
108
 
87
109
  # renames an existing page
@@ -101,7 +123,6 @@ module GollumRails
101
123
  #
102
124
  # Returns the Gollum::Page class
103
125
  def find_page(name)
104
- puts "DEPRECATED! Use Page.find_page instead"
105
126
  self.class.find_page(name)
106
127
  end
107
128
 
@@ -178,6 +199,16 @@ module GollumRails
178
199
  raise Error.new "page cannot be empty for #{__method__}", :high
179
200
  end
180
201
  end
202
+
203
+ private
204
+
205
+ # replaces old filename with new
206
+ def mixin(old_url, new_name)
207
+ url = old_url.split("/")
208
+ url.pop
209
+ url << new_name
210
+ url.join("/")
211
+ end
181
212
 
182
213
  end
183
214
  end
@@ -6,27 +6,28 @@ module GollumRails
6
6
  # TODO: doc
7
7
  class Wiki
8
8
 
9
- # Gets / Sets the git path or object
10
- attr_accessor :git
11
-
12
9
  # Initializes the class
13
10
  #
14
11
  # location - String or Grit::Repo
15
- def initialize(location)
16
- @git = location
17
- if location.is_a? ::String
18
- con = ::Gollum::Wiki.new @git
12
+ def initialize(location, options={})
13
+
14
+ Connector.wiki_options = options
15
+
16
+ if location.is_a?(::String)
17
+ con = location
19
18
  else
20
- con= ::Gollum::Wiki.new @git.path
19
+ con = location.path
21
20
  end
22
- Connector.wiki_class = con
21
+
22
+ Connector.wiki_path = con
23
+
23
24
  end
24
25
 
25
26
  # Static call from within any other class
26
27
  #
27
28
  # Returns a new instance of this class
28
- def self.wiki(location)
29
- Wiki.new(location)
29
+ def self.wiki(location, options={})
30
+ Wiki.new(location, options)
30
31
  end
31
32
 
32
33
  # Forwards unknown methods to Gollum::Wiki
@@ -15,10 +15,6 @@ module GollumRails
15
15
  # * find_or_initialize_by_name
16
16
  #
17
17
  class Page
18
- # extend ::ActiveModel::Callbacks
19
- # include ::ActiveModel::Validations
20
- # include ::ActiveModel::Conversion
21
- # extend ::ActiveModel::Naming
22
18
  include ::ActiveModel::Model
23
19
 
24
20
 
@@ -30,16 +26,19 @@ module GollumRails
30
26
 
31
27
  # Callback for delete
32
28
  define_model_callbacks :delete
33
-
29
+
30
+ # Callback for initialize
31
+ define_model_callbacks :initialize
32
+
33
+ # Callback for create
34
+ define_model_callbacks :create
35
+
36
+ # Callback for commit
37
+ define_model_callbacks :commit
38
+
34
39
  # static
35
40
  class << self
36
- # Gets / Sets the gollum page
37
- #
38
- attr_accessor :gollum_page
39
-
40
- # Sets the validator
41
- attr_writer :validator
42
-
41
+
43
42
  # Finds an existing page or creates it
44
43
  #
45
44
  # name - The name
@@ -63,24 +62,26 @@ module GollumRails
63
62
 
64
63
  # first creates an instance of itself and executes the save function.
65
64
  #
66
- # hash - Hash containing the page data
65
+ # data - Hash containing the page data
67
66
  #
68
67
  #
69
68
  # Returns an instance of Gollum::Page or false
70
- def create(hash)
71
- page = Page.new hash
69
+ def create(data)
70
+ page = Page.new(data)
72
71
  page.save
73
72
  end
74
73
 
75
74
 
76
75
  # calls `create` on current class. If returned value is nil an exception will be thrown
77
76
  #
78
- # hash - Hash containing the page data
77
+ # data - Hash of Data containing all necessary stuff
78
+ # TODO write this stuff
79
79
  #
80
80
  #
81
81
  # Returns an instance of Gollum::Page
82
- def create!(hash)
83
- create(hash)
82
+ def create!(data)
83
+ page = Page.new(data)
84
+ page.save!
84
85
  end
85
86
 
86
87
  # Finds a page based on the name and specified version
@@ -89,23 +90,37 @@ module GollumRails
89
90
  #
90
91
  # Return an instance of Gollum::Page
91
92
  def find(name)
92
- GollumRails::Adapters::Gollum::Page.find_page name
93
+ self.new(gollum_page: Adapters::Gollum::Page.find_page(name, wiki))
93
94
  end
94
95
 
95
96
  # Gets all pages in the wiki
96
97
  def all
97
98
  wiki.pages
98
99
  end
100
+
99
101
  alias_method :find_all, :all
100
102
 
101
103
  # Gets the wiki instance
102
104
  def wiki
103
- @wiki || Adapters::Gollum::Connector.wiki_class
105
+ @wiki ||= ::Gollum::Wiki.new(Adapters::Gollum::Connector.wiki_path, Adapters::Gollum::Connector.wiki_options)
106
+ end
107
+
108
+ # TODO: implement more of this (format, etc)
109
+ #
110
+ def method_missing(name, *args)
111
+ if name =~ /^find_by_(name)$/
112
+ self.find(args.first)
113
+ else
114
+ raise NoMethodError, "Method #{name} was not found"
115
+ end
104
116
  end
105
117
 
106
118
  end
107
119
 
108
-
120
+ # Gets / Sets the gollum page
121
+ #
122
+ attr_accessor :gollum_page
123
+
109
124
  # Initializes a new Page
110
125
  #
111
126
  # attrs - Hash of attributes
@@ -114,6 +129,7 @@ module GollumRails
114
129
  def initialize(attrs = {})
115
130
  if Adapters::Gollum::Connector.enabled
116
131
  attrs.each{|k,v| self.public_send("#{k}=",v)} if attrs
132
+ update_attrs if attrs[:gollum_page]
117
133
  else
118
134
  raise GollumInternalError, 'gollum_rails is not enabled!'
119
135
  end
@@ -150,8 +166,11 @@ module GollumRails
150
166
 
151
167
  # Gets the page class
152
168
  def page
153
- @page ||= Adapters::Gollum::Connector.page_class.new
169
+ Adapters::Gollum::Page.new
154
170
  end
171
+
172
+ # Gollum Page
173
+ attr_accessor :gollum_page
155
174
 
156
175
  #############
157
176
  # activemodel
@@ -180,37 +199,45 @@ module GollumRails
180
199
  # Returns an instance of Gollum::Page or false
181
200
  def save
182
201
  run_callbacks :save do
183
- return false unless valid?
202
+ return nil unless valid?
184
203
  begin
185
- page.new_page(name,content,format,commit)
204
+ @gollum_page = page.new_page(name,content,wiki,format,commit)
186
205
  rescue ::Gollum::DuplicatePageError => e
187
- page.page = Adapters::Gollum::Connector.page_class.find_page(name)
206
+ @gollum_page = Adapters::Gollum::Page.find_page(name, wiki)
188
207
  end
189
- return page.page
208
+ return self
190
209
  end
191
210
  end
192
211
 
193
- # aliasing save
212
+ # == Save without exception handling
213
+ # raises errors everytime something is wrong
194
214
  #
195
- # TODO:
196
- # * implement full method!
197
- alias_method :save!, :save
215
+ def save!
216
+ run_callbacks :save do
217
+ raise StandardError, "record is not valid" unless valid?
218
+ raise StandardError, "commit could not be empty" if commit == {}
219
+ @gollum_page = page.new_page(name,content,wiki,format,commit)
220
+ return self
221
+ end
222
+ end
198
223
 
199
- # Updates an existing page (or created)
224
+ # == Updates an existing page (or created)
200
225
  #
201
- # hash - Hash containing the attributes, you want to update
226
+ # content - optional. If given the content of the gollum_page will be updated
227
+ # name - optional. If given the name of gollum_page will be updated
228
+ # format - optional. Updates the format. Uses markdown as default
202
229
  # commit - optional. If given this commit will be used instead of that one, used
203
230
  # to initialize the instance
204
231
  #
205
232
  #
206
- # Returns an instance of Gollum::Page
207
- def update_attributes(hash, commit=nil)
233
+ # Returns an instance of GollumRails::Page
234
+ def update_attributes(content=nil,name=nil,format=:markdown, commit=nil)
208
235
  run_callbacks :update do
209
- page.update_page hash, get_right_commit(commit)
236
+ @gollum_page = page.update_page(gollum_page, wiki, content, get_right_commit(commit), name, format)
210
237
  end
211
238
  end
212
239
 
213
- # Deletes current page (also available static. See below)
240
+ # == Deletes current page (also available static. See below)
214
241
  #
215
242
  # commit - optional. If given this commit will be used instead of that one, used
216
243
  # to initialize the instance
@@ -218,7 +245,7 @@ module GollumRails
218
245
  # Returns the commit id of the current action as String
219
246
  def delete(commit=nil)
220
247
  run_callbacks :delete do
221
- page.delete_page get_right_commit(commit)
248
+ page.delete_page(gollum_page, wiki, get_right_commit(commit))
222
249
  end
223
250
  end
224
251
 
@@ -226,12 +253,13 @@ module GollumRails
226
253
  #
227
254
  #
228
255
  def persisted?
229
- return true if page.page.instance_of?(::Gollum::Page)
256
+ return true if gollum_page
230
257
  return false
231
258
  end
232
- # Previews the page - Mostly used if you want to see what you do before saving
259
+
260
+ # == Previews the page - Mostly used if you want to see what you do before saving
233
261
  #
234
- # This is an extremely performant method!
262
+ # This is an extremely fast method!
235
263
  # 1 rendering attempt take depending on the content about 0.001 (simple markdown)
236
264
  # upto 0.004 (1000 chars markdown) seconds, which is quite good
237
265
  #
@@ -241,16 +269,63 @@ module GollumRails
241
269
  #
242
270
  # Returns a String
243
271
  def preview(format=:markdown)
244
- preview = self.class.wiki.preview_page @name, @content, format
245
- preview.formatted_data
272
+ page.preview_page( wiki, name, content, format )
246
273
  end
247
274
 
248
-
275
+ # == Gets the url for current page from Gollum::Page
276
+ #
277
+ # Returns a String
278
+ def url
279
+ gollum_page.url_path
280
+ end
281
+
282
+ # == Gets the title for current Gollum::Page
283
+ #
284
+ # Returns a String
285
+ def title
286
+ gollum_page.title
287
+ end
288
+
289
+ # == Gets formatted_data for current Gollum::Page
290
+ #
291
+ # Returns a String
292
+ def html_data
293
+ gollum_page.formatted_data
294
+ end
295
+
296
+
297
+ # == Gets raw_data for current Gollum::Page
298
+ #
299
+ # Returns a String
300
+ def raw_data
301
+ gollum_page.raw_data
302
+ end
303
+
304
+ # == Gets the history of current gollum_page
305
+ #
306
+ # Returns an Array
307
+ def history
308
+ gollum_page.versions
309
+ end
310
+
311
+ # == Gets the last modified by Gollum::Committer
312
+ #
313
+ # Returns a String
314
+ def last_changed_by
315
+ "%s <%s>" % [history.last.author.name, history.last.author.email]
316
+ end
317
+
318
+
319
+ def compare_commits(sha1,sha2)
320
+ puts "NOT YET IMPLEMENTED"
321
+ end
322
+
323
+
249
324
  #######
250
325
  private
251
326
  #######
252
327
 
253
- # Get the right commit out of 2 commits
328
+ # == Gets the right commit out of 2 commits
254
329
  #
255
330
  # commit_local - local commit Hash
256
331
  #
@@ -260,6 +335,19 @@ module GollumRails
260
335
  com = commit_local if !commit_local.nil?
261
336
  return com
262
337
  end
263
-
338
+
339
+ # == Updates local attributes from gollum_page class
340
+ #
341
+ def update_attrs
342
+ @name = gollum_page.name
343
+ @content= gollum_page.raw_data
344
+ @format = gollum_page.format
345
+ end
346
+
347
+ # == To static
348
+ def wiki
349
+ self.class.wiki
350
+ end
351
+
264
352
  end
265
353
  end
@@ -27,6 +27,9 @@ module GollumRails
27
27
  # Gets / Sets the repository
28
28
  attr_accessor :repository
29
29
 
30
+ # Gets / Sets the init options
31
+ attr_accessor :options
32
+
30
33
  # Startup action for building wiki components
31
34
  #
32
35
  # Returns true or throws an exception if the path is invalid
@@ -39,7 +42,11 @@ module GollumRails
39
42
  initialize_wiki @repository
40
43
  end
41
44
  end
42
-
45
+ end
46
+
47
+ # Wiki startup options
48
+ def options=(options)
49
+ @options = options
43
50
  end
44
51
 
45
52
  # defines block builder for Rails initializer.
@@ -68,7 +75,7 @@ module GollumRails
68
75
  def initialize_wiki(path)
69
76
  if path_valid? path
70
77
  repository = Grit::Repo.new path.to_s
71
- GollumRails::Adapters::Gollum::Wiki.new repository
78
+ GollumRails::Adapters::Gollum::Wiki.new(repository, options || {})
72
79
  true
73
80
  else
74
81
  raise GollumInternalError, 'no repository path specified'
@@ -5,9 +5,15 @@ describe GollumRails::Adapters::Gollum::Connector do
5
5
  @class = GollumRails::Adapters::Gollum::Connector
6
6
  end
7
7
 
8
- it "should test the Wiki class connector" do
9
- @class.wiki_class.should == GollumRails::Adapters::Gollum::Wiki
8
+ it "should test the Wiki path connector" do
9
+ @class.wiki_path.should be_a String
10
10
  end
11
+ it "should test the Wiki options connector" do
12
+ @class.wiki_options.should be_a Hash
13
+ end
14
+ it "should test the Wiki options content" do
15
+ @class.wiki_options.should == {}
16
+ end
11
17
  it "should test the Page class connector" do
12
18
  @class.page_class.should == GollumRails::Adapters::Gollum::Page
13
19
  end
@@ -6,83 +6,24 @@ describe GollumRails::Adapters::Gollum::Page do
6
6
  :name => 'The Mosny',
7
7
  :email => 'mosny@zyg.li'
8
8
  }
9
-
10
- @location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
11
- @repo = Grit::Repo.init_bare @location
12
- @wiki = GollumRails::Adapters::Gollum::Wiki.new @repo
13
- @page = GollumRails::Adapters::Gollum::Page.new
14
9
  end
15
- it "should initialize the correct wiki" do
16
- location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
17
- repo = Grit::Repo.init_bare location
18
- wiki = GollumRails::Adapters::Gollum::Wiki.new repo
19
- page = GollumRails::Adapters::Gollum::Page.new
20
- end
21
- it "should create a new page" do
22
- location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
23
- repo = Grit::Repo.init_bare location
24
- wiki = GollumRails::Adapters::Gollum::Wiki.new repo
25
- page = GollumRails::Adapters::Gollum::Page.new
26
- page.new_page("testpage", "content",:markdown, @commit ).should be_instance_of Gollum::Page
27
- page.delete_page(@commit)
28
- end
29
-
30
- it "should delete an existing page" do
31
- page = @page.new_page 'testpage', 'content', :markdown, @commit
32
- @page.delete_page(@commit,page).should be_instance_of String
33
-
34
- @page.new_page 'testpage', 'content', :markdown, @commit
35
- @page.delete_page(@commit).should be_instance_of String
36
- end
37
- it "should update an existing page" do
38
- @page.new_page 'testpage', 'content', :markdown, @commit
39
- page = {}
40
- page[:name] = 'test'
41
- page[:format] = :markdown
42
- page[:content] = "content"
43
- @page.update_page(page, @commit)
44
-
45
- page = []
46
- expect{@page.update_page(page, @commit)}.to raise_error GollumRails::Adapters::Gollum::Error
47
-
48
- page = {}
49
- page[:content] = "test"
50
- @page.update_page(page, @commit).raw_data.should == page[:content]
51
-
52
- page = {}
53
- page[:name] = "test"
54
- @page.update_page(page, @commit).name.should == page[:name]
55
-
56
- page = {}
57
- page[:format] = :wiki
58
- @page.update_page(page, @commit).format.should == :mediawiki
59
-
60
-
61
-
62
- @page.delete_page(@commit)
63
- end
64
- it "should find a page" do
65
- @page.new_page 'content_page', 'content', :markdown, @commit
66
-
67
- GollumRails::Adapters::Gollum::Page.find_page("content_page")
68
- @page.delete_page(@commit)
69
- end
70
- it "should test the commit methods" do
71
- @page.new_page 'content_page', 'content', :markdown, @commit
72
- @page.page_last_edited_date.should be_instance_of Time
73
- @page.page_created.should be_instance_of Time
74
- @page.page_last_commit.should be_instance_of Grit::Commit
75
- @page.page_commit(@page.page.versions.first.id).should be_instance_of Grit::Commit
76
- @page.page_commit_date(@page.page.versions.first.id).should be_instance_of Time
77
- @page.page_first_commit.should be_instance_of Grit::Commit
78
- @page.delete_page(@commit)
79
- end
80
- it "should test the error throwing" do
81
- expect{@page.page_last_commit}.to raise_error GollumRails::Adapters::Gollum::Error
82
- expect{@page.page_first_commit}.to raise_error GollumRails::Adapters::Gollum::Error
83
- expect{@page.page_last_edited_date}.to raise_error GollumRails::Adapters::Gollum::Error
84
- expect{@page.page_created}.to raise_error GollumRails::Adapters::Gollum::Error
85
- expect{@page.page_commit(1)}.to raise_error GollumRails::Adapters::Gollum::Error
86
- expect{@page.page_commit_date(1)}.to raise_error GollumRails::Adapters::Gollum::Error
10
+ describe "Connector stuff" do
11
+ it "should have updated the page_class on initialize" do
12
+ adapter = GollumRails::Adapters::Gollum::Page.new
13
+ GollumRails::Adapters::Gollum::Connector.page_class.should == GollumRails::Adapters::Gollum::Page
14
+ end
15
+ end
16
+ describe "statically methods" do
17
+ it "is a hash" do
18
+ GollumRails::Adapters::Gollum::Page.parse_path('google/de').should be_a Hash
19
+ end
20
+ it "should equal" do
21
+ path1 = GollumRails::Adapters::Gollum::Page.parse_path('google/de')
22
+ path2 = GollumRails::Adapters::Gollum::Page.parse_path('/google/de')
23
+ path1.should == path2
24
+ end
25
+ it "adds a leading slash" do
26
+ GollumRails::Adapters::Gollum::Page.parse_path('google/de')[:path][0].should == '/'
27
+ end
87
28
  end
88
29
  end
@@ -2,58 +2,139 @@ require 'spec_helper'
2
2
 
3
3
  describe "Gollum Page" do
4
4
  before(:each) do
5
+ GollumRails::Setup.build do |config|
6
+ config.repository = File.join(File.dirname(__FILE__),'..','utils','wiki.git')
7
+ config.options={}
8
+ config.startup = true
9
+ end
10
+
5
11
  @commit = {
6
- :name => "flo",
7
- :message => "commit",
8
- :email => "mosny@zyg.li"
12
+ name: "flo",
13
+ message: "commit",
14
+ email: "mosny@zyg.li"
9
15
  }
10
16
  @call = {
11
- :name => "Goole",
12
- :content => "content data",
13
- :commit => @commit,
14
- :format => :markdown
17
+ name: "Goole",
18
+ content: "content data",
19
+ commit: @commit,
20
+ format: :markdown
15
21
  }
16
22
  end
23
+
17
24
  describe GollumRails::Page do
18
- class RailsModel < GollumRails::Page
25
+ class RailsModel < GollumRails::Page; end
19
26
 
27
+ describe "the creation of a page" do
28
+
29
+ before :each do
30
+ @rr = RailsModel.new(@call)
31
+ end
32
+
33
+ it "saves via .save" do
34
+ @rr.save.should be_a GollumRails::Page
35
+ end
36
+
20
37
 
21
- end
38
+ it "saves via .create" do
39
+ RailsModel.create(@call).should be_a GollumRails::Page
40
+ end
41
+
42
+
43
+ it "fails if invalid arguments are supplied via the ! create" do
44
+ args = {
45
+ name: "Gaming",
46
+ content: "content data",
47
+ commit: {},
48
+ format: :markdown
49
+ }
50
+ expect{RailsModel.create!(args)}.to raise_error StandardError #change this
51
+ end
52
+ it "has a history now" do
53
+ @rr.save
54
+ @rr.history.should be_a Array
55
+ end
56
+ it "outputs the raw_data" do
57
+ @rr.save
58
+ @rr.raw_data.should == @call[:content]
59
+ end
60
+ it "has the formatted data" do
61
+ @rr.save
62
+ @rr.html_data.should == '<p>content data</p>'
63
+ end
64
+ it "was last changed by me" do
65
+ @rr.save
66
+ @rr.last_changed_by.should == 'flo <mosny@zyg.li>'
67
+ end
68
+ it "has a title" do
69
+ @rr.save
70
+ @rr.title.should == "Goole"
71
+ end
72
+ it "has a url" do
73
+ @rr.save
74
+ @rr.url.should =="Goole"
75
+ end
22
76
 
23
- it "should test the creation of a page" do
24
- rr = RailsModel.new(@call)
25
- rr.save.should be_instance_of Gollum::Page
26
- rr.save!.should be_instance_of Gollum::Page
27
- RailsModel.create(@call)
28
77
  end
29
78
 
30
- it "should test the update of a page" do
31
- rr = RailsModel.new @call
32
- cc = rr.save.should be_instance_of Gollum::Page
33
- rr.update_attributes({:name => "google", :format => :wiki}).should be_instance_of Gollum::Page
79
+ describe "the update of a page" do
80
+ before :each do
81
+ @rr = RailsModel.new(@call)
82
+ @rr.save
83
+ end
84
+
85
+ it { @rr.update_attributes({:name => "google", :format => :wiki}).should be_a Gollum::Page }
86
+
34
87
  end
35
-
36
- it "should test the deletion of a page" do
37
- rr = RailsModel.new @call
38
- cc = rr.save.should be_instance_of Gollum::Page
39
- rr.delete.should be_instance_of String
88
+ describe "method missings" do
89
+
90
+ it "should perform a normal find" do
91
+ RailsModel.find_by_name('Goole').should be_a GollumRails::Page
92
+
93
+
94
+ end
95
+
40
96
  end
41
97
 
42
- it "should test the finding of a page" do
43
- RailsModel.find('google').should be_instance_of Gollum::Page
44
-
45
- #invalid input
46
- RailsModel.find('<script type="text/javascript">alert(123);</script>').should be_nil
47
- end
48
- it "should test the preview" do
49
- rr = RailsModel.new :content => "# content", :name => "somepage"
50
- 100.times do
51
- rr.preview.should include("<h1>content<a class=\"anchor\" id=\"content\" href=\"#content\"></a></h1>")
98
+ describe "should test the deletion of a page" do
99
+ before :each do
100
+ @rr = RailsModel.new @call
101
+ @cc = @rr.save
102
+ end
103
+
104
+ it "should return a string" do
105
+ delete = @rr.delete
106
+ delete.should be_a String
107
+ end
108
+
109
+ it "should return a SHA1 hash" do
110
+ delete = @rr.delete
111
+ delete.length.should == 40
112
+ end
113
+
114
+ it "should also work was result from save" do
115
+ delete = @cc.delete
116
+ delete.should be_a String
117
+ end
118
+
119
+ it "should test the recreation" do
120
+ delete = @rr.delete
121
+ @rr.save.should be_a GollumRails::Page
122
+ @rr.delete.should be_a String
123
+
52
124
  end
53
125
  end
54
126
 
127
+
128
+ 100.times do
129
+ it "should test the preview" do
130
+ rr = RailsModel.new :content => "# content", :name => "somepage"
131
+ rr.preview.should include("<h1>content<a class=\"anchor\" id=\"content\" href=\"#content\"></a></h1>")
132
+ end
133
+ end
134
+
55
135
  it "should test exception methods" do
56
- create = RailsModel.create! @call
136
+ RailsModel.create @call
137
+ expect{RailsModel.create! @call}.to raise_error Gollum::DuplicatePageError
57
138
  end
58
139
 
59
140
  it "should test the supported formats" do
@@ -69,11 +150,11 @@ describe "Gollum Page" do
69
150
  rr = RailsModel.new @call
70
151
  rr.name.should == "Goole"
71
152
  rr.content.should == "content data"
72
- rr.commit.should be_instance_of Hash
153
+ rr.commit.should be_a Hash
73
154
  rr.commit.should == @commit
74
155
  rr.format.should == :markdown
75
156
  rr.save
76
- rr.page.should be_instance_of GollumRails::Adapters::Gollum::Page
157
+ rr.page.should be_a GollumRails::Adapters::Gollum::Page
77
158
  end
78
159
  it "should test setters" do
79
160
  rr = RailsModel.new
@@ -87,7 +168,7 @@ describe "Gollum Page" do
87
168
  it "should test find or initialize" do
88
169
  rr = RailsModel.new @call
89
170
  rr.save
90
- RailsModel.find_or_initialize_by_name(@call[:name], @commit).should be_instance_of Gollum::Page
171
+ RailsModel.find_or_initialize_by_name(@call[:name], @commit).should be_a GollumRails::Page
91
172
  end
92
173
  end
93
174
  describe "callbacks" do
@@ -136,16 +217,15 @@ describe "Gollum Page" do
136
217
  test = CallbackTest.new @call
137
218
  test.persisted?.should be_false
138
219
  test.save
139
- test.delete @commit
140
- test.save
141
- test.update_attributes @call
142
- test.persisted?.should be_true
143
220
  end
144
221
  end
145
222
  describe "rails extension" do
223
+
146
224
  it "should test fetch_all" do
147
- GollumRails::Page.all.length.should == 2
148
- GollumRails::Page.find_all.length.should == 2
225
+ GollumRails::Page.all.length.should == 1
226
+ end
227
+ it "should test all" do
228
+ GollumRails::Page.find_all.length.should == 1
149
229
  end
150
230
 
151
231
  end
@@ -195,7 +275,7 @@ describe "Gollum Page" do
195
275
  100.times do |time|
196
276
  Thread.new do
197
277
  ThreadModel.new(@call)
198
- ThreadModel.save.should be_instance_of(Gollum::Page)
278
+ ThreadModel.save.should be_a(GollumRails::Page)
199
279
  ThreadModel.delete(@commit).length.should == 40
200
280
  end
201
281
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Kasper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0
33
+ version: 1.0.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0
40
+ version: 1.0.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +119,7 @@ files:
119
119
  - spec/gollum_rails/adapters/gollum/connector_spec.rb
120
120
  - spec/gollum_rails/adapters/gollum/error_spec.rb
121
121
  - spec/gollum_rails/adapters/gollum/page_spec.rb
122
- - spec/gollum_rails/adapters/gollum/wiki_spec.rb
122
+ - spec/gollum_rails/adapters/gollum/wiki_spec_off.rb
123
123
  - spec/gollum_rails/error_spec.rb
124
124
  - spec/gollum_rails/page_spec.rb
125
125
  - spec/gollum_rails/respository_spec.rb
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project: gollum_rails
153
- rubygems_version: 2.0.3
153
+ rubygems_version: 2.0.5
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Combines Gollum and Rails