gollum_rails 1.4.6 → 1.4.7

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: 1f1d83fb2faa64453dcb5a65f5924a0c9964b031
4
- data.tar.gz: f0244385a600d80b43c9c854e34320e34eed0ebc
3
+ metadata.gz: 57c07d301c92ee9ae439361a45e1a0317508396f
4
+ data.tar.gz: 813634ee9e35af6a7392fa2fd1cef28e1b7eb308
5
5
  SHA512:
6
- metadata.gz: af72a2be4d4bd7727935b9272dd572230b432382ae542a9ecf4a79cd54050090b17f48485d3d43480261c375b75a780f1e04c8e14e852f534311014e82afc434
7
- data.tar.gz: 08892031c42725374caf6b80fb4652aae56a367d6416c429ec9f1f9a0d5ed42b37f5650cb4aa80e83863af20a60e41f308f80dbf210d989d0a4d50866b2f5e47
6
+ metadata.gz: 6aa595beec356b66b0ac41a368623a5fcd1074aa308e15ffdda2e9a9100ee305c84d874310004ecea7eed0d9ea2ca7be947486c88fc10a0f2f52631c2bd56208
7
+ data.tar.gz: d5115ae21d4c26bca9cd76b134c55e966528da4e4e2bdad675611bc18fe5504d413ae01b3a1d6fb44244e46f8294f0667c6f1250bbf1a89eba81b878858dd377
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'coveralls', require: false
4
- gem 'guard'
5
- gem 'guard-rspec'
4
+
6
5
 
7
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gollum_rails (1.4.6)
5
- activemodel (>= 4.0.0)
4
+ gollum_rails (1.4.7)
5
+ activemodel (>= 3.2.11)
6
+ activesupport (>= 3.2.11)
6
7
  gollum-lib (~> 1.0.9)
7
8
 
8
9
  GEM
@@ -86,7 +87,7 @@ GEM
86
87
  mini_portile (0.5.2)
87
88
  minitest (4.7.5)
88
89
  multi_json (1.8.2)
89
- nokogiri (1.6.0)
90
+ nokogiri (1.6.1)
90
91
  mini_portile (~> 0.5.0)
91
92
  polyglot (0.3.3)
92
93
  posix-spawn (0.3.8)
@@ -167,6 +168,7 @@ DEPENDENCIES
167
168
  gollum_rails!
168
169
  guard
169
170
  guard-rspec
170
- rails (>= 4.0.0)
171
+ rails (>= 3.2.11)
172
+ rb-fsevent
171
173
  rr (~> 1.1.1)
172
174
  rspec (~> 2.13.0)
data/Guardfile CHANGED
@@ -2,6 +2,7 @@ guard :rspec do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
+ watch(%r{^lib/(orm|core|finders|persistance|store|callbacks)\.rb$}) { |m| "spec/gollum_rails/page_spec.rb" }
5
6
 
6
7
  end
7
8
 
data/gollum_rails.gemspec CHANGED
@@ -4,18 +4,22 @@ 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.6'
7
+ s.version = '1.4.7'
8
8
 
9
9
  s.summary = 'Combines Gollum and Rails'
10
10
  s.description= 'include Gollum into Rails with ease'
11
11
 
12
- s.add_dependency 'activemodel', '>= 4.0.0'
12
+ s.add_dependency 'activemodel', '>= 3.2.11'
13
+ s.add_dependency 'activesupport', '>= 3.2.11'
14
+
13
15
  s.add_dependency 'gollum-lib', '~> 1.0.9'
14
16
 
15
17
  s.add_development_dependency 'rspec', '~> 2.13.0'
16
18
  s.add_development_dependency 'rr', '~> 1.1.1'
17
- s.add_development_dependency 'rails', '>= 4.0.0'
18
-
19
+ s.add_development_dependency 'rails', '>= 3.2.11'
20
+ s.add_development_dependency 'guard'
21
+ s.add_development_dependency 'guard-rspec'
22
+ s.add_development_dependency 'rb-fsevent'
19
23
  s.author = 'Florian Kasper'
20
24
  s.email = 'mosny@zyg.li'
21
25
  s.homepage = 'https://github.com/nirnanaaa/gollum_rails'
@@ -40,26 +44,26 @@ Gem::Specification.new do |s|
40
44
  lib/generators/gollum_rails/model/model_generator.rb
41
45
  lib/generators/gollum_rails/model/templates/model_template.erb
42
46
  lib/gollum_rails.rb
43
- lib/gollum_rails/adapters/activemodel.rb
44
- lib/gollum_rails/adapters/activemodel/boolean.rb
45
- lib/gollum_rails/adapters/activemodel/error.rb
46
- lib/gollum_rails/adapters/activemodel/naming.rb
47
47
  lib/gollum_rails/adapters/gollum.rb
48
48
  lib/gollum_rails/adapters/gollum/.gitkeep
49
49
  lib/gollum_rails/adapters/gollum/error.rb
50
50
  lib/gollum_rails/adapters/gollum/page.rb
51
51
  lib/gollum_rails/adapters/gollum/wiki.rb
52
+ lib/gollum_rails/callbacks.rb
53
+ lib/gollum_rails/core.rb
54
+ lib/gollum_rails/finders.rb
55
+ lib/gollum_rails/orm.rb
52
56
  lib/gollum_rails/page.rb
57
+ lib/gollum_rails/persistance.rb
53
58
  lib/gollum_rails/setup.rb
54
- spec/gollum_rails/adapters/activemodel/error_spec.rb
55
- spec/gollum_rails/adapters/activemodel/naming_spec.rb
56
- spec/gollum_rails/adapters/activemodel/validation_unused.rb
59
+ lib/gollum_rails/store.rb
60
+ lib/gollum_rails/validation.rb
57
61
  spec/gollum_rails/adapters/gollum/committer_spec.rb
58
62
  spec/gollum_rails/adapters/gollum/connector_spec.rb
59
- spec/gollum_rails/adapters/gollum/error_spec.rb
60
63
  spec/gollum_rails/adapters/gollum/page_spec.rb
61
64
  spec/gollum_rails/adapters/gollum/wiki_spec_off.rb
62
65
  spec/gollum_rails/error_spec.rb
66
+ spec/gollum_rails/orm_spec.rb
63
67
  spec/gollum_rails/page_spec.rb
64
68
  spec/gollum_rails/respository_spec.rb
65
69
  spec/gollum_rails/setup_spec.rb
data/lib/gollum_rails.rb CHANGED
@@ -1,11 +1,25 @@
1
1
  # ~*~ encoding: utf-8 ~*~
2
+ #--
3
+ # Copyright (C) 2013 Florian Kasper
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
2
18
 
3
- # stdlib
4
- require 'rubygems'
5
19
 
6
- # external
7
20
  require 'gollum-lib'
8
-
21
+ require 'active_model'
22
+ require 'active_support'
9
23
 
10
24
  # GollumRails is a RubyGem for extending Rails and the Gollum wiki powered by github
11
25
  # It has the ability to combine the benefits from a git powered wiki with Rails.
@@ -16,11 +30,20 @@ require 'gollum-lib'
16
30
  # * ...
17
31
  #
18
32
  module GollumRails
19
- autoload :Page, 'gollum_rails/page'
20
- autoload :Setup, 'gollum_rails/setup'
33
+ extend ActiveSupport::Autoload
34
+
35
+ autoload :Persistance
36
+ autoload :Callbacks
37
+ autoload :Core
38
+ autoload :Store
39
+ autoload :Validation
40
+ autoload :Finders
41
+ autoload :Page
42
+ autoload :Setup
43
+ autoload :Orm
21
44
 
22
45
  # GollumRails version string
23
- VERSION = '1.4.6'
46
+ VERSION = '1.4.7'
24
47
 
25
48
  # Simplified error
26
49
  class Error < StandardError; end
@@ -49,6 +72,4 @@ module GollumRails
49
72
  end
50
73
  end
51
74
 
52
-
53
- require File.expand_path '../gollum_rails/adapters/activemodel', __FILE__
54
75
  require File.expand_path '../gollum_rails/adapters/gollum', __FILE__
@@ -51,21 +51,6 @@ module GollumRails
51
51
  end
52
52
  end
53
53
 
54
- # == Creates a new page
55
- #
56
- # name - The name of the page
57
- # content - The content of the page
58
- # wiki - An instance of Gollum::Wiki
59
- # type - A filetype as symbol (optional)
60
- # commit - Commit Hash
61
- #
62
- # Returns the page
63
- def new_page( name, content, wiki, type=:markdown, commit={} )
64
- path_data = self.class.parse_path(name)
65
- wiki.write_page( path_data[:name], type, content, commit, path_data[:path].gsub!(/^\//, "").gsub!(/(\/)+$/,'') || "" )
66
- wiki.clear_cache
67
- self.class.find_page( name, wiki )
68
- end
69
54
 
70
55
  # == Updates an existing page
71
56
  #
@@ -89,125 +74,6 @@ module GollumRails
89
74
  self.class.find_page( mixin(page.url_path, name), wiki )
90
75
  end
91
76
 
92
- # == Preview page
93
- #
94
- # wiki - An instance of Gollum::Wiki
95
- # content - New content
96
- # name - A String
97
- # format - A filetype as symbol (optional)
98
- #
99
- def preview_page(wiki, name, content, format=:markdown)
100
- page = wiki.preview_page(name,content,format)
101
- page.formatted_data
102
- end
103
-
104
- # == Deletes an existing page
105
- #
106
- # page - Gollum::Page
107
- # wiki - Gollum::Wiki
108
- # commit - Commit Hash
109
- #
110
- # Returns the commit id
111
- def delete_page( page,wiki,commit={} )
112
- wiki.clear_cache
113
- wiki.delete_page(page, commit)
114
- end
115
-
116
- # renames an existing page
117
- #
118
- # page - instance of myself
119
- # newname - new pagename
120
- # commit - Hash or instance of Committer
121
- #
122
- # Returns the commit id
123
- def rename_page( page, newname, commit={} )
124
-
125
- end
126
-
127
- # finds all versions of a page
128
- #
129
- # name - the pagename to search
130
- #
131
- # Returns the Gollum::Page class
132
- def find_page(name)
133
-
134
- self.class.find_page(name)
135
- end
136
-
137
- # moves an existing page
138
- #
139
- # TODO:
140
- # * implement
141
- def move_page()
142
- end
143
-
144
- # gets page last edit date
145
- #
146
- # Returns an instance of Time
147
- def page_last_edited_date
148
- if @page
149
- return @page.versions.first.authored_date
150
- else
151
- raise Error.new "page cannot be empty for #{__method__}", :high
152
- end
153
- end
154
-
155
- # gets the latest commit
156
- #
157
- # Returns an instance of Grit::Commit
158
- def page_last_commit
159
- if @page
160
- return @page.versions.first
161
- else
162
- raise Error.new "page cannot be empty for #{__method__}", :high
163
- end
164
- end
165
-
166
- # gets the creation date of the page
167
- #
168
- # Returns an instance of Time
169
- def page_created
170
- if @page
171
- return @page.versions.last.authored_date
172
- else
173
- raise Error.new "page cannot be empty for #{__method__}", :high
174
- end
175
-
176
- end
177
-
178
- # gets the first page commit
179
- #
180
- # Returns an instance of Grit::Commit
181
- def page_first_commit
182
- if @page
183
- return @page.versions.last
184
- else
185
- raise Error.new "page cannot be empty for #{__method__}", :high
186
- end
187
- end
188
-
189
- # gets a specific commit version
190
- #
191
- # Returns an instance of Grit::Commit
192
- def page_commit(id)
193
- if @page
194
- return @page.versions.each{|v| return v if v.id == id}
195
- else
196
- raise Error.new "page cannot be empty for #{__method__}", :high
197
- end
198
- end
199
-
200
- # gets a specific commit time
201
- #
202
- # Returns an instance of Time
203
- def page_commit_date(id)
204
- if @page
205
- return @page.versions.each{|v| return v.authored_date if v.id == id}
206
- else
207
- raise Error.new "page cannot be empty for #{__method__}", :high
208
- end
209
- end
210
-
211
77
  private
212
78
 
213
79
  # replaces old filename with new
@@ -30,13 +30,6 @@ module GollumRails
30
30
  Wiki.new(location, options)
31
31
  end
32
32
 
33
- # Forwards unknown methods to Gollum::Wiki
34
- #
35
- # may throw an Argument error or method missing
36
- def self.method_missing(name, *args)
37
- Connector.wiki_class.send(name, *args)
38
- end
39
-
40
33
  end
41
34
  end
42
35
  end
@@ -0,0 +1,47 @@
1
+ module GollumRails
2
+ module Callbacks
3
+ extend ActiveSupport::Concern
4
+
5
+ CALLBACKS = [
6
+ :after_initialize,
7
+ :before_save, :around_save, :after_save, :before_create, :around_create,
8
+ :after_create, :before_update, :around_update, :after_update,
9
+ :before_destroy, :around_destroy, :after_destroy, :after_commit
10
+ ]
11
+ module ClassMethods
12
+ include ActiveModel::Callbacks
13
+ end
14
+
15
+ included do
16
+ include ActiveModel::Validations::Callbacks
17
+
18
+ define_model_callbacks :initialize, :only => :after
19
+ define_model_callbacks :save, :create, :update, :destroy
20
+ end
21
+
22
+
23
+
24
+ def destroy(*)
25
+ run_callbacks(:destroy) { super }
26
+ end
27
+
28
+ def save
29
+ run_callbacks(:save) { super }
30
+ end
31
+
32
+ private
33
+
34
+ # def create_or_update #:nodoc:
35
+ # run_callbacks(:save) { super }
36
+ # end
37
+
38
+ def create_record #:nodoc:
39
+ run_callbacks(:create) { super }
40
+ end
41
+
42
+ def update_record(*) #:nodoc:
43
+ run_callbacks(:update) { super }
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,158 @@
1
+ module GollumRails
2
+ module Core
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ # Checks if the fileformat is supported
8
+ #
9
+ # format - String
10
+ #
11
+ # Returns true or false
12
+ def format_supported?(format)
13
+ Gollum::Markup.formats.include?(format.to_sym)
14
+ end
15
+
16
+
17
+
18
+ end
19
+
20
+ # Initializes a new Page
21
+ #
22
+ # attrs - Hash of attributes
23
+ #
24
+ # commit must be given to perform any page action!
25
+ def initialize(attrs = {})
26
+ run_callbacks :initialize do
27
+ if Adapters::Gollum::Connector.enabled
28
+ attrs.each{|k,v| self.public_send("#{k}=",v)} if attrs
29
+ update_attrs if attrs[:gollum_page]
30
+ else
31
+ raise GollumInternalError, 'gollum_rails is not enabled!'
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ def path_name
38
+ name.gsub(/(^\/|(\/){2}+|#{canonicalized_filename})/, "")
39
+ end
40
+
41
+ def canonicalized_filename
42
+ Gollum::Page.canonicalize_filename(name)
43
+ end
44
+
45
+ # == Previews the page - Mostly used if you want to see what you do before saving
46
+ #
47
+ # This is an extremely fast method!
48
+ # 1 rendering attempt take depending on the content about 0.001 (simple markdown)
49
+ # upto 0.004 (1000 chars markdown) seconds, which is quite good
50
+ #
51
+ #
52
+ # format - Specify the format you want to render with see {self.format_supported?}
53
+ # for formats
54
+ #
55
+ # Returns a String
56
+ def preview(format=:markdown)
57
+ wiki.preview_page(name, content, format).formatted_data
58
+ end
59
+
60
+ # == Gets the url for current page from Gollum::Page
61
+ #
62
+ # Returns a String
63
+ def url
64
+ gollum_page.url_path
65
+ end
66
+
67
+ # == Gets the title for current Gollum::Page
68
+ #
69
+ # Returns a String
70
+ def title
71
+ gollum_page.title
72
+ end
73
+
74
+ # == Gets formatted_data for current Gollum::Page
75
+ #
76
+ # Returns a String
77
+ def html_data
78
+ gollum_page.formatted_data
79
+ end
80
+ # == Gets raw_data for current Gollum::Page
81
+ #
82
+ # Returns a String
83
+ def raw_data
84
+ gollum_page.raw_data
85
+ end
86
+
87
+ # == Gets the history of current gollum_page
88
+ #
89
+ # Returns an Array
90
+ def history
91
+ return nil unless persisted?
92
+ gollum_page.versions
93
+ end
94
+
95
+ # == Gets the last modified by Gollum::Committer
96
+ #
97
+ # Returns a String
98
+ def last_changed_by
99
+ "%s <%s>" % [history.last.author.name, history.last.author.email]
100
+ end
101
+
102
+ # == Compare 2 Commits.
103
+ #
104
+ # sha1 - SHA1
105
+ # sha2 - SHA1
106
+ def compare_commits(sha1,sha2=nil)
107
+ Page.wiki.full_reverse_diff_for(@gollum_page,sha1,sha2)
108
+ end
109
+
110
+
111
+ # == The pages filename, based on the name and the format
112
+ #
113
+ # Returns a String
114
+ # def filename
115
+ # Page.wiki.page_file_name(@name, @format)
116
+ # end
117
+
118
+ # == Checks if current page is a subpage
119
+ def sub_page?
120
+ return nil unless persisted?
121
+ @gollum_page.sub_page
122
+ end
123
+
124
+ # == Gets the version of current commit
125
+ #
126
+ def current_version(long=false)
127
+ return nil unless persisted?
128
+ unless long
129
+ @gollum_page.version_short
130
+ else
131
+ @gollum_page.version.to_s
132
+ end
133
+
134
+ end
135
+
136
+ private
137
+
138
+ # == Gets the right commit out of 2 commits
139
+ #
140
+ # commit_local - local commit Hash
141
+ #
142
+ # Returns local_commit > class_commit
143
+ def get_right_commit(commit_local)
144
+ com = commit if commit_local.nil?
145
+ com = commit_local if !commit_local.nil?
146
+ return com
147
+ end
148
+
149
+ # == Updates local attributes from gollum_page class
150
+ #
151
+ def update_attrs
152
+ @name = gollum_page.name
153
+ @content= gollum_page.raw_data
154
+ @format = gollum_page.format
155
+ end
156
+
157
+ end
158
+ end