gollum_rails 1.4.6 → 1.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -2
- data/Gemfile.lock +6 -4
- data/Guardfile +1 -0
- data/gollum_rails.gemspec +16 -12
- data/lib/gollum_rails.rb +30 -9
- data/lib/gollum_rails/adapters/gollum/page.rb +0 -134
- data/lib/gollum_rails/adapters/gollum/wiki.rb +0 -7
- data/lib/gollum_rails/callbacks.rb +47 -0
- data/lib/gollum_rails/core.rb +158 -0
- data/lib/gollum_rails/finders.rb +62 -0
- data/lib/gollum_rails/orm.rb +11 -0
- data/lib/gollum_rails/page.rb +80 -399
- data/lib/gollum_rails/persistance.rb +165 -0
- data/lib/gollum_rails/store.rb +60 -0
- data/lib/gollum_rails/validation.rb +9 -0
- data/spec/gollum_rails/orm_spec.rb +25 -0
- data/spec/gollum_rails/page_spec.rb +62 -33
- metadata +70 -14
- data/lib/gollum_rails/adapters/activemodel.rb +0 -36
- data/lib/gollum_rails/adapters/activemodel/boolean.rb +0 -15
- data/lib/gollum_rails/adapters/activemodel/error.rb +0 -27
- data/lib/gollum_rails/adapters/activemodel/naming.rb +0 -42
- data/spec/gollum_rails/adapters/activemodel/error_spec.rb +0 -11
- data/spec/gollum_rails/adapters/activemodel/naming_spec.rb +0 -27
- data/spec/gollum_rails/adapters/activemodel/validation_unused.rb +0 -102
- data/spec/gollum_rails/adapters/gollum/error_spec.rb +0 -7
@@ -0,0 +1,165 @@
|
|
1
|
+
module GollumRails
|
2
|
+
module Persistance
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
# first creates an instance of itself and executes the save function.
|
8
|
+
#
|
9
|
+
# data - Hash containing the page data
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# Returns an instance of Gollum::Page or false
|
13
|
+
def create(data)
|
14
|
+
page = Page.new(data)
|
15
|
+
page.save
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# calls `create` on current class. If returned value is nil an exception will be thrown
|
20
|
+
#
|
21
|
+
# data - Hash of Data containing all necessary stuff
|
22
|
+
# TODO write this stuff
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# Returns an instance of Gollum::Page
|
26
|
+
def create!(data)
|
27
|
+
page = Page.new(data)
|
28
|
+
page.save!
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
#############
|
33
|
+
# activemodel
|
34
|
+
#############
|
35
|
+
|
36
|
+
# Handles the connection betweet plain activemodel and Gollum
|
37
|
+
# Saves current page in GIT wiki
|
38
|
+
# If another page with the same name is existing, gollum_rails
|
39
|
+
# will detect it and returns that page instead.
|
40
|
+
#
|
41
|
+
# Examples:
|
42
|
+
#
|
43
|
+
# obj = GollumRails::Page.new <params>
|
44
|
+
# @article = obj.save
|
45
|
+
# # => Gollum::Page
|
46
|
+
#
|
47
|
+
# @article.name
|
48
|
+
# whatever name you have entered OR the name of the previous
|
49
|
+
# created page
|
50
|
+
#
|
51
|
+
#
|
52
|
+
# TODO:
|
53
|
+
# * overriding for creation(duplicates)
|
54
|
+
# * do not alias save! on save
|
55
|
+
#
|
56
|
+
# Returns an instance of Gollum::Page or false
|
57
|
+
def save
|
58
|
+
return nil unless valid?
|
59
|
+
begin
|
60
|
+
create_or_update
|
61
|
+
rescue ::Gollum::DuplicatePageError => e
|
62
|
+
#false
|
63
|
+
end
|
64
|
+
@gollum_page = Adapters::Gollum::Page.find_page(name, wiki)
|
65
|
+
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
# == Save without exception handling
|
70
|
+
# raises errors everytime something is wrong
|
71
|
+
#
|
72
|
+
def save!
|
73
|
+
raise StandardError, "record is not valid" unless valid?
|
74
|
+
raise StandardError, "commit must not be empty" if commit == {}
|
75
|
+
create_or_update
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
# == Creates a record or updates it!
|
80
|
+
#
|
81
|
+
# Returns a Commit id string
|
82
|
+
def create_or_update
|
83
|
+
if persisted?
|
84
|
+
update_record
|
85
|
+
else
|
86
|
+
create_record
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# == Creates a record
|
91
|
+
#
|
92
|
+
# Returns a Commit id
|
93
|
+
def create_record
|
94
|
+
wiki.write_page(canonicalized_filename, format, content, commit, path_name)
|
95
|
+
wiki.clear_cache
|
96
|
+
end
|
97
|
+
|
98
|
+
# == Update a record
|
99
|
+
#
|
100
|
+
# NYI
|
101
|
+
#
|
102
|
+
# returns a Commit id
|
103
|
+
def update_record
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
# == Updates an existing page (or created)
|
109
|
+
#
|
110
|
+
# content - optional. If given the content of the gollum_page will be updated
|
111
|
+
# name - optional. If given the name of gollum_page will be updated
|
112
|
+
# format - optional. Updates the format. Uses markdown as default
|
113
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
114
|
+
# to initialize the instance
|
115
|
+
#
|
116
|
+
#
|
117
|
+
# Returns an instance of GollumRails::Page
|
118
|
+
def update_attributes(content=nil,name=nil,format=:markdown, commit=nil)
|
119
|
+
run_callbacks :update do
|
120
|
+
@gollum_page = page.update_page(gollum_page, wiki, content, get_right_commit(commit), name, format)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# == Deletes current page
|
125
|
+
#
|
126
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
127
|
+
# to initialize the instance
|
128
|
+
#
|
129
|
+
# Returns the commit id of the current action as String
|
130
|
+
def destroy(commit=nil)
|
131
|
+
return false if @gollum_page.nil?
|
132
|
+
wiki.delete_page(@gollum_page, get_right_commit(commit))
|
133
|
+
end
|
134
|
+
|
135
|
+
# == Deletes current page
|
136
|
+
#
|
137
|
+
# commit - optional. If given this commit will be used instead of that one, used
|
138
|
+
# to initialize the instance
|
139
|
+
#
|
140
|
+
# Returns the commit id of the current action as String
|
141
|
+
def delete(commit=nil)
|
142
|
+
destroy(commit)
|
143
|
+
end
|
144
|
+
|
145
|
+
# checks if entry already has been saved
|
146
|
+
#
|
147
|
+
#
|
148
|
+
def persisted?
|
149
|
+
return true if gollum_page
|
150
|
+
return false
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
# == Checks if the page is valid
|
157
|
+
#
|
158
|
+
# #
|
159
|
+
# def valid?
|
160
|
+
# #if Gollum::Page.valid_page_name?(self.name)
|
161
|
+
# end
|
162
|
+
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module GollumRails
|
2
|
+
module Store
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
|
6
|
+
ATTR_READERS = []
|
7
|
+
ATTR_WRITERS = [:name, :content, :format]
|
8
|
+
ATTR_ACCESSORS = [:commit, :gollum_page]
|
9
|
+
|
10
|
+
included do
|
11
|
+
ATTR_WRITERS.each do |a|
|
12
|
+
attr_writer a
|
13
|
+
end
|
14
|
+
ATTR_ACCESSORS.each do |a|
|
15
|
+
attr_accessor a
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# Gets the wiki instance
|
22
|
+
def wiki
|
23
|
+
@wiki ||= Gollum::Wiki.new(Adapters::Gollum::Connector.wiki_path, Adapters::Gollum::Connector.wiki_options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
# Gets the pages format
|
27
|
+
def format
|
28
|
+
(@format || @gollum_page.format).to_sym
|
29
|
+
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
@name ||= @gollum_page.name
|
33
|
+
end
|
34
|
+
|
35
|
+
# == Outputs the pages filename on disc
|
36
|
+
#
|
37
|
+
# ext - Wether to output extension or not
|
38
|
+
def filename(ext=true)
|
39
|
+
@filename ||= (ext) ? @gollum_page.filename : @gollum_page.filename_stripped
|
40
|
+
end
|
41
|
+
|
42
|
+
def content
|
43
|
+
@content ||= @gollum_page.content
|
44
|
+
end
|
45
|
+
|
46
|
+
# Gets the page class
|
47
|
+
def page
|
48
|
+
Adapters::Gollum::Page.new
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
# == To static
|
53
|
+
def wiki
|
54
|
+
self.class.wiki
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe GollumRails::Orm do
|
5
|
+
let(:commit){{
|
6
|
+
name: "flo",
|
7
|
+
message: "commit",
|
8
|
+
email: "mosny@zyg.li"}}
|
9
|
+
let(:pageattrs){{
|
10
|
+
name: "Pagetester",
|
11
|
+
content: "content data",
|
12
|
+
commit: commit,
|
13
|
+
format: :markdown}}
|
14
|
+
class PTest < GollumRails::Page
|
15
|
+
include GollumRails::Orm
|
16
|
+
end
|
17
|
+
# before(:each){@rr = PTest.create(pageattrs)}
|
18
|
+
# after(:each){}
|
19
|
+
|
20
|
+
it "should alias the all function" do
|
21
|
+
@rr = PTest.new(pageattrs)
|
22
|
+
#expect(PTest).to respond_to(:all_pages)
|
23
|
+
#@rr.destroy(commit)
|
24
|
+
end
|
25
|
+
end
|
@@ -115,13 +115,7 @@ describe "Gollum Page" do
|
|
115
115
|
delete = @cc.delete
|
116
116
|
delete.should be_a String
|
117
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
|
-
|
124
|
-
end
|
118
|
+
|
125
119
|
end
|
126
120
|
|
127
121
|
|
@@ -145,7 +139,9 @@ describe "Gollum Page" do
|
|
145
139
|
it "should have a name" do
|
146
140
|
expect(rr.name).to match(/^Goole$/)
|
147
141
|
end
|
148
|
-
|
142
|
+
it "should have a preview" do
|
143
|
+
expect(rr.preview).to match(/^content/)
|
144
|
+
end
|
149
145
|
it "should have a content" do
|
150
146
|
expect(rr.content).to match(/^content\ data$/)
|
151
147
|
end
|
@@ -177,6 +173,24 @@ describe "Gollum Page" do
|
|
177
173
|
rr.format=(:markdown).should == :markdown
|
178
174
|
end
|
179
175
|
|
176
|
+
it "builds an url for the page" do
|
177
|
+
page = RailsModel.find('Goole')
|
178
|
+
|
179
|
+
p = RailsModel.new(name: "bla/testfa", commit: @commit, content: "[[Goole]]", format: :markdown)
|
180
|
+
#p.destroy(@commit)
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
it "gets the pages filename on disk with a 'DOT' in filename" do
|
187
|
+
expect(RailsModel.find('Goole').filename).to match('.')
|
188
|
+
end
|
189
|
+
|
190
|
+
it "gets the pages filename on disk withOUT a 'dot' in filename" do
|
191
|
+
expect(RailsModel.find('Goole').filename(false)).not_to match('.md')
|
192
|
+
end
|
193
|
+
|
180
194
|
it "tests the find method to return nil if no page was found" do
|
181
195
|
expect(RailsModel.find('whoooohoo')).to be_nil
|
182
196
|
end
|
@@ -223,8 +237,8 @@ describe "Gollum Page" do
|
|
223
237
|
|
224
238
|
before_save ::SaveCallback
|
225
239
|
after_save :after_save
|
226
|
-
|
227
|
-
|
240
|
+
after_destroy :after_delete
|
241
|
+
before_destroy :before_delete
|
228
242
|
before_update :before_update
|
229
243
|
after_update :after_update
|
230
244
|
|
@@ -336,15 +350,7 @@ describe "Gollum Page" do
|
|
336
350
|
end
|
337
351
|
|
338
352
|
end
|
339
|
-
|
340
|
-
describe "Filename" do
|
341
|
-
class Fns < GollumRails::Page
|
342
|
-
end
|
343
|
-
it "should assemble a filename" do
|
344
|
-
res = CommitDiff.new @call
|
345
|
-
expect(res.filename).to match(/^Goole\.md$/)
|
346
|
-
end
|
347
|
-
end
|
353
|
+
|
348
354
|
|
349
355
|
describe "Sub Page" do
|
350
356
|
class Fns < GollumRails::Page
|
@@ -418,20 +424,43 @@ describe "Gollum Page" do
|
|
418
424
|
|
419
425
|
end
|
420
426
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
427
|
+
describe "path names" do
|
428
|
+
class Fns < GollumRails::Page
|
429
|
+
end
|
430
|
+
it "should output nothing as there is no path" do
|
431
|
+
res = Fns.create @call
|
432
|
+
expect(res.path_name).to match ''
|
433
|
+
res.destroy(@commit)
|
434
|
+
end
|
435
|
+
|
436
|
+
it "should output a path name as there was a path supplied" do
|
437
|
+
res = Fns.new @call.merge(name: 'test/pagess')
|
438
|
+
res.save
|
439
|
+
expect(res.path_name).not_to be_nil
|
440
|
+
res.destroy(@commit)
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should create a nested page under /test" do
|
444
|
+
res = Fns.new @call.merge(name: 'test/my_page')
|
445
|
+
res.save
|
446
|
+
expect(res.path_name).to match 'test'
|
447
|
+
res.destroy(@commit)
|
448
|
+
end
|
449
|
+
it "should find a nested file" do
|
450
|
+
res = Fns.new @call.merge(name: 'test/my_page2')
|
451
|
+
res.save
|
452
|
+
expect(Fns.find('test/my_page2')).not_to be_nil
|
453
|
+
res.destroy
|
454
|
+
end
|
455
|
+
it "should search for a files content" do
|
456
|
+
res = Fns.new @call.merge(name: 'test/my_page3')
|
457
|
+
res.save
|
458
|
+
expect(Fns.search('content')).not_to be_empty
|
459
|
+
expect(Fns.search('content').first[:count]).to be(1)
|
460
|
+
res.destroy
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
435
464
|
|
436
465
|
|
437
466
|
#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.
|
4
|
+
version: 1.4.7
|
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-12-
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.11
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.2.11
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.11
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.11
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: gollum-lib
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +86,56 @@ dependencies:
|
|
72
86
|
requirements:
|
73
87
|
- - '>='
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 3.2.11
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.2.11
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rb-fsevent
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
76
132
|
type: :development
|
77
133
|
prerelease: false
|
78
134
|
version_requirements: !ruby/object:Gem::Requirement
|
79
135
|
requirements:
|
80
136
|
- - '>='
|
81
137
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
138
|
+
version: '0'
|
83
139
|
description: include Gollum into Rails with ease
|
84
140
|
email: mosny@zyg.li
|
85
141
|
executables: []
|
@@ -100,26 +156,26 @@ files:
|
|
100
156
|
- lib/generators/gollum_rails/model/model_generator.rb
|
101
157
|
- lib/generators/gollum_rails/model/templates/model_template.erb
|
102
158
|
- lib/gollum_rails.rb
|
103
|
-
- lib/gollum_rails/adapters/activemodel.rb
|
104
|
-
- lib/gollum_rails/adapters/activemodel/boolean.rb
|
105
|
-
- lib/gollum_rails/adapters/activemodel/error.rb
|
106
|
-
- lib/gollum_rails/adapters/activemodel/naming.rb
|
107
159
|
- lib/gollum_rails/adapters/gollum.rb
|
108
160
|
- lib/gollum_rails/adapters/gollum/.gitkeep
|
109
161
|
- lib/gollum_rails/adapters/gollum/error.rb
|
110
162
|
- lib/gollum_rails/adapters/gollum/page.rb
|
111
163
|
- lib/gollum_rails/adapters/gollum/wiki.rb
|
164
|
+
- lib/gollum_rails/callbacks.rb
|
165
|
+
- lib/gollum_rails/core.rb
|
166
|
+
- lib/gollum_rails/finders.rb
|
167
|
+
- lib/gollum_rails/orm.rb
|
112
168
|
- lib/gollum_rails/page.rb
|
169
|
+
- lib/gollum_rails/persistance.rb
|
113
170
|
- lib/gollum_rails/setup.rb
|
114
|
-
-
|
115
|
-
-
|
116
|
-
- spec/gollum_rails/adapters/activemodel/validation_unused.rb
|
171
|
+
- lib/gollum_rails/store.rb
|
172
|
+
- lib/gollum_rails/validation.rb
|
117
173
|
- spec/gollum_rails/adapters/gollum/committer_spec.rb
|
118
174
|
- spec/gollum_rails/adapters/gollum/connector_spec.rb
|
119
|
-
- spec/gollum_rails/adapters/gollum/error_spec.rb
|
120
175
|
- spec/gollum_rails/adapters/gollum/page_spec.rb
|
121
176
|
- spec/gollum_rails/adapters/gollum/wiki_spec_off.rb
|
122
177
|
- spec/gollum_rails/error_spec.rb
|
178
|
+
- spec/gollum_rails/orm_spec.rb
|
123
179
|
- spec/gollum_rails/page_spec.rb
|
124
180
|
- spec/gollum_rails/respository_spec.rb
|
125
181
|
- spec/gollum_rails/setup_spec.rb
|