gollum_rails 1.5.10 → 1.5.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,8 @@
1
1
  module GollumRails
2
2
  module Core
3
3
  extend ActiveSupport::Concern
4
-
5
4
  module ClassMethods
6
-
5
+
7
6
  # Checks if the fileformat is supported
8
7
  #
9
8
  # format - String
@@ -12,7 +11,7 @@ module GollumRails
12
11
  def format_supported?(format)
13
12
  Gollum::Markup.formats.include?(format.to_sym)
14
13
  end
15
-
14
+
16
15
  # Resets the folder to /
17
16
  def reset_folder
18
17
  set_folder(nil)
@@ -32,7 +31,7 @@ module GollumRails
32
31
  end
33
32
  alias_method :folder=, :set_folder
34
33
  end
35
-
34
+
36
35
  # Initializes a new Page
37
36
  #
38
37
  # attrs - Hash of attributes
@@ -45,7 +44,6 @@ module GollumRails
45
44
  run_callbacks :initialize unless _initialize_callbacks.empty?
46
45
  end
47
46
 
48
-
49
47
  # Allows you to set all the attributes by passing in a hash of attributes with
50
48
  # keys matching the attribute name
51
49
  #
@@ -55,15 +53,12 @@ module GollumRails
55
53
  raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
56
54
  end
57
55
  return if new_attributes.blank?
58
-
59
56
  attributes = new_attributes.stringify_keys
60
57
  attributes.each do |k, v|
61
58
  _assign_attribute(k, v)
62
59
  end
63
60
  end
64
-
65
61
 
66
-
67
62
  def url_path #:nodoc:
68
63
  File.split(url)
69
64
  end
@@ -86,11 +81,11 @@ module GollumRails
86
81
  Gollum::Page.cname(self.name)
87
82
  end
88
83
 
89
- # Gets a canonicalized filename of the page
84
+ # Gets a canonicalized filename of the page
90
85
  def canonicalized_filename
91
86
  Gollum::Page.canonicalize_filename(name)
92
87
  end
93
-
88
+
94
89
  # == Previews the page - Mostly used if you want to see what you do before saving
95
90
  #
96
91
  # This is an extremely fast method!
@@ -103,10 +98,9 @@ module GollumRails
103
98
  #
104
99
  # Returns a String
105
100
  def preview(format=:markdown)
106
- wiki.preview_page(name, content, format).formatted_data
101
+ require 'active_support/core_ext/string/output_safety'
102
+ wiki.preview_page(name, content, format).formatted_data.html_safe
107
103
  end
108
-
109
-
110
104
 
111
105
  # == Gets the url for current page from Gollum::Page
112
106
  #
@@ -116,15 +110,14 @@ module GollumRails
116
110
  gollum_page.url_path
117
111
  end
118
112
  end
119
-
113
+
120
114
  # == Gets the title for current Gollum::Page
121
115
  #
122
116
  # Returns a String
123
117
  def title
124
118
  gollum_page.title
125
119
  end
126
-
127
-
120
+
128
121
  # == Gets formatted_data for current Gollum::Page
129
122
  #
130
123
  # Returns a String
@@ -137,7 +130,7 @@ module GollumRails
137
130
  def raw_data
138
131
  gollum_page.raw_data
139
132
  end
140
-
133
+
141
134
  # == Gets the history of current gollum_page
142
135
  #
143
136
  # Returns an Array
@@ -145,14 +138,14 @@ module GollumRails
145
138
  return nil unless persisted?
146
139
  gollum_page.versions
147
140
  end
148
-
141
+
149
142
  # == Gets the last modified by Gollum::Committer
150
143
  #
151
144
  # Returns a String
152
145
  def last_changed_by
153
- "%s <%s>" % [history.last.author.name, history.last.author.email]
146
+ "%s <%s>" % [history.first.author.name, history.first.author.email]
154
147
  end
155
-
148
+
156
149
  # == Compare 2 Commits.
157
150
  #
158
151
  # sha1 - SHA1
@@ -161,34 +154,26 @@ module GollumRails
161
154
  Page.wiki.full_reverse_diff_for(@gollum_page,sha1,sha2)
162
155
  end
163
156
 
164
-
165
- # == The pages filename, based on the name and the format
166
- #
167
- # Returns a String
168
- # def filename
169
- # Page.wiki.page_file_name(@name, @format)
170
- # end
171
-
172
157
  # == Checks if current page is a subpage
173
158
  def sub_page?
174
159
  return nil unless persisted?
175
160
  @gollum_page.sub_page
176
161
  end
177
-
162
+
178
163
  # == Gets the version of current commit
179
164
  #
180
165
  def current_version(long=false)
181
166
  return nil unless persisted?
182
167
  unless long
183
- @gollum_page.version_short
168
+ @gollum_page.version_short
184
169
  else
185
170
  @gollum_page.version.to_s
186
171
  end
187
-
172
+
188
173
  end
189
-
174
+
190
175
  private
191
-
176
+
192
177
  # == Gets the right commit out of 2 commits
193
178
  #
194
179
  # commit_local - local commit Hash
@@ -202,19 +187,19 @@ module GollumRails
202
187
 
203
188
  def _assign_attribute(key, value)
204
189
  public_send("#{key}=", value)
205
- rescue NoMethodEr3ror
190
+ rescue NoMethodError
206
191
  if respond_to?("#{key}=")
207
192
  raise
208
193
  end
209
194
  end
210
-
195
+
211
196
  # == Updates local attributes from gollum_page class
212
197
  #
213
198
  def _update_page_attributes
214
199
  @name = gollum_page.name
215
200
  @content= gollum_page.raw_data
216
- @format = gollum_page.format
201
+ @format = gollum_page.format
217
202
  end
218
-
203
+
219
204
  end
220
205
  end
@@ -1,6 +1,5 @@
1
1
  module GollumRails
2
2
  class InitializationError < StandardError; end
3
-
4
3
  module Error
5
4
  end
6
- end
5
+ end
@@ -1,9 +1,9 @@
1
1
  module GollumRails
2
2
  module Finders
3
3
  extend ActiveSupport::Concern
4
-
5
4
  module ClassMethods
6
- # Finds an existing page or creates it
5
+
6
+ # Find an existing page or create it
7
7
  #
8
8
  # name - The name
9
9
  # commit - Hash
@@ -17,7 +17,7 @@ module GollumRails
17
17
  new(:format => :markdown, :name => name, :content => ".", :commit => commit)
18
18
  end
19
19
  end
20
-
20
+
21
21
  # Finds a page based on the name and specified version
22
22
  #
23
23
  # name - the name of the page
@@ -43,7 +43,7 @@ module GollumRails
43
43
  nil
44
44
  end
45
45
  end
46
-
46
+
47
47
  # == Searches the wiki for files CONTENT!
48
48
  #
49
49
  # string - Searchstring
@@ -63,7 +63,7 @@ module GollumRails
63
63
  self.new(gollum_page: page)
64
64
  end
65
65
  end
66
-
66
+
67
67
  # Gets the last item from `all` method call
68
68
  #
69
69
  # options - optional - some options e.g. :folder
@@ -72,7 +72,7 @@ module GollumRails
72
72
  def first(options={})
73
73
  all(options).first
74
74
  end
75
-
75
+
76
76
  # Gets the first item from `all` method call
77
77
  #
78
78
  # options - optional - some options e.g. :folder
@@ -81,10 +81,10 @@ module GollumRails
81
81
  def last(options={})
82
82
  all(options).last
83
83
  end
84
-
84
+
85
85
  # Aliasing this for ActiveRecord behavior
86
86
  alias_method :find_all, :all
87
-
87
+
88
88
  # Catch-all method
89
89
  def method_missing(name, *args)
90
90
  if name =~ /^find_by_(name)$/
@@ -92,8 +92,6 @@ module GollumRails
92
92
  else super
93
93
  end
94
94
  end
95
-
96
-
97
95
  end
98
96
  end
99
97
  end
@@ -1,10 +1,10 @@
1
1
  module GollumRails
2
2
  module Meta
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  # == Checks if this page has a Yaml part
6
6
  #
7
- # Example YAML part:
7
+ # Example YAML part:
8
8
  #
9
9
  # ---
10
10
  # title: "My Page"
@@ -26,7 +26,7 @@ module GollumRails
26
26
  def raw_meta
27
27
  raw_data.match(/^(?<headers>---\s*\n.*?\n?)^(---\s*$\n?)/m).to_s
28
28
  end
29
-
29
+
30
30
  # == Gets the parsed meta data
31
31
  #
32
32
  #
@@ -36,8 +36,7 @@ module GollumRails
36
36
  rescue Psych::SyntaxError => e
37
37
  {error: e}
38
38
  end
39
-
40
-
39
+
41
40
  # == Example for meta data usage:
42
41
  #
43
42
  # Gets the title from the meta data
@@ -53,6 +52,6 @@ module GollumRails
53
52
  def html_without_yaml
54
53
  gollum_page.markup_class.render(raw_data.tap{|s| s.slice!(raw_meta.to_s)})
55
54
  end
56
-
55
+
57
56
  end
58
- end
57
+ end
@@ -2,11 +2,8 @@ module GollumRails
2
2
  # Playground
3
3
  module Orm
4
4
  extend ActiveSupport::Concern
5
-
6
5
  def save
7
-
8
6
  super
9
7
  end
10
-
11
8
  end
12
- end
9
+ end
@@ -1,11 +1,11 @@
1
1
  module GollumRails
2
-
3
-
2
+
3
+
4
4
  # = GollumRails
5
5
  #
6
6
  # Gollum Rails was initially designed to integrate the Gollum wiki software
7
7
  # into your Rails application without any mounts or extra applications to run.
8
- #
8
+ #
9
9
  # Now you can use your completely own layout without struggling with gollum forks.
10
10
  #
11
11
  # Just integrate this gem into your Gemfile and you are good to go:
@@ -18,7 +18,7 @@ module GollumRails
18
18
  #
19
19
  #
20
20
  # If you want to use this gem with Rails version prior 4.0.0 please check out the rails3
21
- # branch on Github:
21
+ # branch on Github:
22
22
  #
23
23
  # https://github.com/nirnanaaa/gollum_rails/tree/rails3
24
24
  #
@@ -48,7 +48,7 @@ module GollumRails
48
48
  #
49
49
  # commit = { name: 'nirnanaa', email: 'mosny@zyg.li', message: 'created page page'}
50
50
  # Page.create(name: 'test_page', content: 'content', format: :markdown, commit: commit)
51
- #
51
+ #
52
52
  # Page.create!(name: 'test_page', content: 'content', format: :markdown, commit: commit)
53
53
  #
54
54
  # The <tt>!</tt> version of the method throws an error on failure.
@@ -65,7 +65,6 @@ module GollumRails
65
65
  #
66
66
  #
67
67
  class Page
68
-
69
68
  if ActiveModel::VERSION::MAJOR == 4
70
69
  include ActiveModel::Model
71
70
  else
@@ -74,7 +73,6 @@ module GollumRails
74
73
  include ActiveModel::Conversion
75
74
  include ActiveModel::Validations
76
75
  end
77
-
78
76
  include Error
79
77
  include Core
80
78
  include Meta
@@ -83,9 +81,6 @@ module GollumRails
83
81
  include Persistance
84
82
  include Finders
85
83
  include Callbacks
86
-
87
84
  end
88
-
89
85
  ActiveSupport.run_load_hooks(:gollum, Page)
90
-
91
- end
86
+ end
@@ -1,9 +1,11 @@
1
1
  module GollumRails
2
2
  module Persistance
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
+ class AttributeMissingError < NoMethodError; end
6
+
5
7
  module ClassMethods
6
-
8
+
7
9
  # first creates an instance of itself and executes the save function.
8
10
  #
9
11
  # data - Hash containing the page data
@@ -15,7 +17,6 @@ module GollumRails
15
17
  page.save
16
18
  end
17
19
 
18
-
19
20
  # calls `create` on current class. If returned value is nil an exception will be thrown
20
21
  #
21
22
  # data - Hash of Data containing all necessary stuff
@@ -27,7 +28,7 @@ module GollumRails
27
28
  page = self.new(data)
28
29
  page.save!
29
30
  end
30
-
31
+
31
32
  end
32
33
  #############
33
34
  # activemodel
@@ -58,7 +59,7 @@ module GollumRails
58
59
  return nil unless valid?
59
60
  begin
60
61
  create_or_update
61
- rescue ::Gollum::DuplicatePageError => e
62
+ rescue ::Gollum::DuplicatePageError
62
63
  end
63
64
  self.gollum_page = wiki.paged(file_name, path_name, true, wiki.ref)
64
65
  _update_page_attributes
@@ -66,15 +67,16 @@ module GollumRails
66
67
  end
67
68
 
68
69
  # == Save without exception handling
69
- # raises errors everytime something is wrong
70
+ # raises errors everytime something is wrong
70
71
  #
72
+ # Returns an instance of GollumRails::Page
71
73
  def save!
72
74
  raise StandardError, "record is not valid" unless valid?
73
75
  raise StandardError, "commit must not be empty" if commit == {}
74
76
  create_or_update
75
77
  self
76
78
  end
77
-
79
+
78
80
  # == Creates a record or updates it!
79
81
  #
80
82
  # Returns a Commit id string
@@ -85,30 +87,30 @@ module GollumRails
85
87
  create_record
86
88
  end
87
89
  end
88
-
90
+
89
91
  # == Creates a record
90
92
  #
91
93
  # Returns a Commit id
92
94
  def create_record
93
- wiki.write_page(canonicalized_filename, format, content, commit, path_name)
95
+ wiki.write_page(canonicalized_filename, format, content, commit, path_name)
94
96
  wiki.clear_cache
97
+ rescue NoMethodError => e
98
+ raise AttributeMissingError, "Attributes are missing. Error message: <%s>" % e.message
95
99
  end
96
-
100
+
97
101
  # == Update a record
98
102
  #
99
- # NYI
103
+ # Updates a record based on current instance variables
100
104
  #
101
105
  # returns a Commit id
102
106
  def update_record
103
107
  wiki.update_page(self.gollum_page,
104
108
  self.name,
105
- self.format,
109
+ self.format,
106
110
  self.content,
107
111
  self.commit)
108
112
  end
109
-
110
-
111
-
113
+
112
114
  # == Updates an existing page (or created)
113
115
  #
114
116
  # attributes - Hash of arguments
@@ -118,8 +120,8 @@ module GollumRails
118
120
  assign_attributes(attributes)
119
121
  save
120
122
  end
121
-
122
- def seperate_path(path)
123
+
124
+ def seperate_path(path) #:nodoc:
123
125
  path = File.split(name)
124
126
  if path.first == '/' || path.first == '.'
125
127
  folder = nil
@@ -128,7 +130,6 @@ module GollumRails
128
130
  end
129
131
  end
130
132
 
131
-
132
133
  # == Deletes current page
133
134
  #
134
135
  # commit - optional. If given this commit will be used instead of that one, used
@@ -157,17 +158,5 @@ module GollumRails
157
158
  return true if gollum_page
158
159
  return false
159
160
  end
160
-
161
-
162
-
163
-
164
- # == Checks if the page is valid
165
- #
166
- # #
167
- # def valid?
168
- # #if Gollum::Page.valid_page_name?(self.name)
169
- # end
170
-
171
-
172
161
  end
173
162
  end