gollum_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rake', '~> 10.0.2'
data/HISTORY.md ADDED
File without changes
data/LICENSE.md ADDED
File without changes
data/README.md ADDED
File without changes
@@ -0,0 +1,44 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'gollum_rails'
3
+ s.version = '0.0.1'
4
+
5
+ s.summary = 'Combines Gollum wiki with Rails'
6
+ s.description= File.read(File.join(File.dirname(__FILE__), 'README.md'))
7
+
8
+ s.add_dependency('activemodel', '~> 3.2.11')
9
+ s.add_dependency('gollum', '~> 2.4.11')
10
+ s.add_dependency('grit', '~> 2.5.0')
11
+ s.add_dependency('builder', '~> 3.0.0')
12
+ s.add_dependency('rack', '~> 1.4.0')
13
+ s.add_development_dependency('org-ruby', '~> 0.7.2')
14
+ s.add_development_dependency('shoulda', '~> 3.3.2')
15
+ s.add_development_dependency('rack-test', '~> 0.6.2')
16
+ s.add_development_dependency('rake', '~> 10.0.2')
17
+ s.add_development_dependency('rails', '~> 3.2.11')
18
+
19
+ s.author = 'nirnanaaa'
20
+ s.email = 'nirnanaaa@khnetworks.com'
21
+ s.homepage = 'https://github.com/nirnanaaa/gollum_rails'
22
+ s.platform = Gem::Platform::RUBY
23
+ s.required_ruby_version = '>=1.9'
24
+ s.files = %w[
25
+ Gemfile
26
+ HISTORY.md
27
+ gollum_rails.gemspec
28
+ LICENSE.md
29
+ README.md
30
+ lib/gollum_rails.rb
31
+ lib/gollum/rails/dependency_injector.rb
32
+ lib/gollum/rails/page.rb
33
+ lib/gollum/rails/validations.rb
34
+ lib/gollum/rails/wiki.rb
35
+ lib/gollum/rails/version.rb
36
+ lib/gollum/rails/gollum_rails.rb
37
+ lib/gollum/rails/engine.rb
38
+ lib/gollum/rails/config.rb
39
+ lib/gollum/rails/messages.yml
40
+ ]
41
+ s.require_paths = %w[lib]
42
+ s.has_rdoc = false
43
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
44
+ end
@@ -0,0 +1,38 @@
1
+ require 'yaml'
2
+
3
+ module Gollum
4
+ module Rails
5
+ class Config
6
+ attr_reader :config
7
+ def self.read_config
8
+ @config = self.open_config
9
+ @config
10
+ end
11
+ def self.config_location
12
+ end
13
+
14
+ def self.lang_from_rails
15
+ end
16
+
17
+ def self.settings_from_rails
18
+ Rails.settings
19
+ end
20
+
21
+ def self.rails_root
22
+ Rails.root
23
+ end
24
+
25
+ def self.rails_config_dir
26
+ end
27
+
28
+ #######
29
+ private
30
+ #######
31
+ #gives a hardcoded configuration file
32
+ def self.open_config
33
+ YAML.load_file(::File.join(::File.dirname(__FILE__), 'messages.yml'))
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ module Gollum
2
+ module Rails
3
+ ## simple DI component
4
+ class DependencyInjector
5
+
6
+ attr_accessor :storage
7
+
8
+ #initializes the :storage with a new Hash
9
+ def self.initialize
10
+ @storage = Hash.new
11
+ end
12
+
13
+ #sets a storage Hash
14
+ def self.set(name, value)
15
+ if !@storage.is_a?(Hash)
16
+ self.initialize
17
+ end
18
+ @storage[name] = value
19
+ end
20
+
21
+ # gets a storage
22
+ def self.get(name)
23
+ if !@storage.is_a?(Hash)
24
+ self.initialize
25
+ end
26
+ @storage[name]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails'
2
+ require 'gollum/rails/config'
3
+
4
+ module Gollum
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ #initialize "gollum_rails.load_app" do |app|
8
+ ## Gollum::Rails::Config::rails = app
9
+ # end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,7 @@
1
+ require "gollum/rails/engine"
2
+ require "gollum/rails/version"
3
+ require 'gollum/rails/config'
4
+ require "gollum/rails/dependency_injector"
5
+ require "gollum/rails/wiki"
6
+ require "gollum/rails/page"
7
+ require 'gollum/rails/validations'
@@ -0,0 +1,2 @@
1
+ a:
2
+ file: is
@@ -0,0 +1,240 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+ module Gollum
3
+ module Rails
4
+ class Page
5
+ include ActiveModel::Conversion
6
+ extend ActiveModel::Naming
7
+
8
+ #the filename
9
+ attr_accessor :name
10
+
11
+ # text content
12
+ attr_accessor :content
13
+
14
+ # file formatting type
15
+ # possible:
16
+ # - :asciidoc
17
+ # - :creole
18
+ # - :markdown
19
+ # - :org
20
+ # - :pod
21
+ # - :rdoc
22
+ # - :rst
23
+ # - :tex
24
+ # - :wiki
25
+ attr_accessor :format
26
+
27
+ # the commit Hash
28
+ attr_accessor :commit
29
+
30
+ # WHAT?!
31
+ attr_accessor :options
32
+
33
+ # a boolean variable that holds the status of save() and update()
34
+ attr_reader :persisted
35
+
36
+ # holds the error messages
37
+ attr_reader :error
38
+
39
+ # holds an instance of Gollum::Wiki
40
+ attr_reader :wiki
41
+ # attributes needs to be a hash
42
+ # example:
43
+ # Gollum::Rails::Page.new({name: '', content: '', format: '', commit: {}})
44
+ #
45
+ #
46
+ # explanation:
47
+ # name must be a string.
48
+ # content should be a text/String
49
+ # format must be eighter :markdown, :latex, :rdoc, ...
50
+ # commit must be a hash for example:
51
+ # commit = {
52
+ # message: 'page created',
53
+ # name: 'Florian Kasper',
54
+ # email: 'nirnanaaa@khnetworks.com'
55
+ # }
56
+ def initialize(attributes = {}, options = {})
57
+ wiki = DependencyInjector.get('wiki')
58
+ if wiki && wiki.is_a?(Wiki)
59
+ @wiki = wiki
60
+ end
61
+ if !Validations.is_boolean?(@persisted)
62
+ @persisted = false
63
+ end
64
+ if !@error
65
+ @error = nil
66
+ end
67
+ attributes.each do |name, value|
68
+ send("#{name}=", value)
69
+ end
70
+
71
+ end
72
+
73
+ ## checks if @wiki.wiki is an instance of Gollum::Wiki
74
+ def wikiLoaded?
75
+ @wiki.wiki.is_a?(Gollum::Wiki)
76
+ end
77
+
78
+ ## Error String content brought by the functions in this class
79
+ def get_error_message
80
+ @error
81
+ end
82
+
83
+ # Some "ActiveRecord" like things e.g. .save .valid? .find .find_by_* .where and so on
84
+ def save
85
+ if valid?
86
+ begin
87
+ @wiki.wiki.write_page(@name, @format, @content, @commit)
88
+ @persisted = true
89
+ rescue Gollum::DuplicatePageError => e
90
+ @error = e
91
+ return false
92
+ end
93
+ end
94
+ return true
95
+ end
96
+
97
+ # Updates an existing page
98
+ # usage:
99
+ #
100
+ #
101
+ # wiki = Gollum::Rails::Wiki.new(PATH)
102
+ #
103
+ # page = Gollum::Rails::Page.new
104
+ # cnt = page.find(PAGENAME)
105
+ #
106
+ # commit = {
107
+ # :message => "production test update",
108
+ # :name => 'Florian Kasper',
109
+ # :email => 'nirnanaaa@khnetworks.com'
110
+ # }
111
+ # update = page.update("content", commit)
112
+
113
+ def update(content, commit, name=nil, format=nil)
114
+ if !name.nil?
115
+ @name = name
116
+ end
117
+ if !format.nil?
118
+ @format = format
119
+ end
120
+ if commit.nil? || content.nil?
121
+ @error = "commit must be given"
122
+ return false
123
+ end
124
+ return @wiki.wiki.update_page(@page, @name, @format, content, commit)
125
+ end
126
+
127
+ # Deletes page fetched by find()
128
+ def delete(commit)
129
+ if commit.nil?
130
+ @error = "commit must be given"
131
+ return false
132
+ end
133
+ return @wiki.wiki.delete_page(@page, commit)
134
+ end
135
+ # if a page is loaded wraps Gollum::Page.raw_data
136
+ def raw_data
137
+ if @page
138
+ @page.raw_data
139
+ else
140
+ @error = "no page fetched"
141
+ return false
142
+ end
143
+ end
144
+
145
+ # if a page is loaded wraps Gollum::Page.formatted_data
146
+ def formatted_data
147
+ if @page
148
+ @page.formatted_data
149
+ else
150
+ @error = "no page fetched"
151
+ return false
152
+ end
153
+ end
154
+
155
+ # Active Record like
156
+ # Page.version.first.id
157
+ # Page.version.first.authored_data
158
+ #
159
+ #
160
+ # see Active Model documentation
161
+ def version
162
+ if @page
163
+ @page.versions
164
+ else
165
+ @error = "no page fetched"
166
+ return false
167
+ end
168
+ end
169
+
170
+
171
+
172
+ #
173
+ # Validates the Class variables
174
+ # default:
175
+ # - name must be set
176
+ # - content can be NIL || " "
177
+ # - committer must be set
178
+ # format must be set
179
+ def valid?
180
+ if !@name || @name.nil?
181
+ return false
182
+ end
183
+ if !@commit || !@commit.is_a?(Hash)
184
+ return false
185
+ end
186
+ if !@format
187
+ return false
188
+ end
189
+ return true
190
+
191
+ end
192
+
193
+ #gets an Instance of Gollum::Wiki fetched by find() method
194
+ attr_reader :page
195
+
196
+ #finds a wiki page
197
+ def find(name = nil)
198
+ if !name.nil?
199
+ page = @wiki.wiki.page(name)
200
+ if page.nil?
201
+ @error = "The given page was not found"
202
+ return nil
203
+ end
204
+
205
+ #need a better solution thats fu***** bull*****
206
+ @page = page
207
+ @name = page.name
208
+ @format = page.format
209
+
210
+ return page
211
+ else
212
+ return nil
213
+ end
214
+ end
215
+
216
+ def persisted?
217
+ @persisted
218
+ end
219
+
220
+ # Static into non static converter
221
+ def self.method_missing(name, *args)
222
+ klass = self.new
223
+ return klass.send(name, args)
224
+ end
225
+
226
+ # def method_missing(name, *args)
227
+ # meth = name.to_s.index("find_by_")
228
+ # if meth.nil?
229
+ # @error = "method not found"
230
+ # raise RuntimeError
231
+ # end
232
+ # finder = name[8 .. name.length]
233
+ # if finder == "name"
234
+ # find(args)
235
+ # end
236
+ # end
237
+
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,10 @@
1
+ module Gollum
2
+ module Rails
3
+ class Validations
4
+ include ActiveModel::Validations
5
+ def self.is_boolean?(variable)
6
+ variable.is_a?(TrueClass) || variable.is_a?(FalseClass)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Gollum
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ module Gollum
2
+ module Rails
3
+ class Wiki
4
+ attr_accessor :wiki
5
+ def initialize(path)
6
+ main = getMainGollum(path)
7
+ send("wiki=", main)
8
+ DependencyInjector.set('wiki', self)
9
+ end
10
+
11
+ def getMainGollum(path)
12
+ wiki = Gollum::Wiki.new(path)
13
+ end
14
+
15
+ def getPath
16
+ @wiki.path
17
+ end
18
+
19
+ def getRepo
20
+ @wiki.repo
21
+ end
22
+
23
+ def search(string = '')
24
+
25
+ end
26
+
27
+ ## static setters / getters
28
+
29
+ def self.getWiki
30
+ @wiki
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'gollum'
3
+
4
+ module Gollum
5
+ module Rails
6
+ require 'gollum/rails/engine' if defined?(Rails)
7
+ end
8
+ end
9
+
10
+ require 'gollum/rails/gollum_rails' if defined?(Rails)
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gollum_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nirnanaaa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemodel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.11
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: gollum
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.4.11
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.4.11
46
+ - !ruby/object:Gem::Dependency
47
+ name: grit
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.5.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.5.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: builder
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.0.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 3.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.4.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.4.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: org-ruby
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.7.2
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.7.2
110
+ - !ruby/object:Gem::Dependency
111
+ name: shoulda
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 3.3.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 3.3.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: rack-test
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.6.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.6.2
142
+ - !ruby/object:Gem::Dependency
143
+ name: rake
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 10.0.2
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 10.0.2
158
+ - !ruby/object:Gem::Dependency
159
+ name: rails
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ version: 3.2.11
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 3.2.11
174
+ description: ''
175
+ email: nirnanaaa@khnetworks.com
176
+ executables: []
177
+ extensions: []
178
+ extra_rdoc_files: []
179
+ files:
180
+ - Gemfile
181
+ - HISTORY.md
182
+ - gollum_rails.gemspec
183
+ - LICENSE.md
184
+ - README.md
185
+ - lib/gollum_rails.rb
186
+ - lib/gollum/rails/dependency_injector.rb
187
+ - lib/gollum/rails/page.rb
188
+ - lib/gollum/rails/validations.rb
189
+ - lib/gollum/rails/wiki.rb
190
+ - lib/gollum/rails/version.rb
191
+ - lib/gollum/rails/gollum_rails.rb
192
+ - lib/gollum/rails/engine.rb
193
+ - lib/gollum/rails/config.rb
194
+ - lib/gollum/rails/messages.yml
195
+ homepage: https://github.com/nirnanaaa/gollum_rails
196
+ licenses: []
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ! '>='
205
+ - !ruby/object:Gem::Version
206
+ version: '1.9'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ none: false
209
+ requirements:
210
+ - - ! '>='
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubyforge_project:
215
+ rubygems_version: 1.8.23
216
+ signing_key:
217
+ specification_version: 3
218
+ summary: Combines Gollum wiki with Rails
219
+ test_files: []