cadmus 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## cadmus 0.4.2 (06-16-2012)
2
+
3
+ * Make `cadmus_pages` route function work with no arguments
@@ -62,94 +62,94 @@ module Cadmus
62
62
  # BookPage
63
63
  # end
64
64
  # end
65
- module PagesController
66
- extend ActiveSupport::Concern
67
- include Cadmus::Renderable
68
-
69
- included do
70
- class << self
71
- attr_accessor :page_parent_name, :page_parent_class, :find_parent_by
72
- end
73
-
74
- before_filter :load_parent_and_page
75
- helper_method :cadmus_renderer
76
- end
77
-
78
- def index
79
- @pages = page_scope.order(:name).all
80
-
81
- respond_to do |format|
82
- format.html { render 'cadmus/pages/index' }
83
- format.xml { render :xml => @pages }
65
+ module PagesController
66
+ extend ActiveSupport::Concern
67
+ include Cadmus::Renderable
68
+
69
+ included do
70
+ class << self
71
+ attr_accessor :page_parent_name, :page_parent_class, :find_parent_by
72
+ end
73
+
74
+ before_filter :load_parent_and_page
75
+ helper_method :cadmus_renderer
76
+ end
77
+
78
+ def index
79
+ @pages = page_scope.order(:name).all
80
+
81
+ respond_to do |format|
82
+ format.html { render 'cadmus/pages/index' }
83
+ format.xml { render :xml => @pages }
84
84
  format.json { render :json => @pages }
85
- end
86
- end
87
-
88
- def show
89
- respond_to do |format|
90
- format.html { render 'cadmus/pages/show' }
91
- format.xml { render :xml => @page }
85
+ end
86
+ end
87
+
88
+ def show
89
+ respond_to do |format|
90
+ format.html { render 'cadmus/pages/show' }
91
+ format.xml { render :xml => @page }
92
92
  format.json { render :json => @page }
93
- end
94
- end
95
-
96
- def new
97
- @page = page_scope.new(params[:page])
98
-
99
- respond_to do |format|
100
- format.html { render 'cadmus/pages/new' }
101
- format.xml { render :xml => @page }
93
+ end
94
+ end
95
+
96
+ def new
97
+ @page = page_scope.new(params[:page])
98
+
99
+ respond_to do |format|
100
+ format.html { render 'cadmus/pages/new' }
101
+ format.xml { render :xml => @page }
102
102
  format.json { render :json => @page }
103
- end
104
- end
105
-
106
- def edit
107
- render 'cadmus/pages/edit'
108
- end
109
-
110
- def create
111
- @page = page_scope.new(params[:page])
112
-
113
- respond_to do |format|
114
- if @page.save
115
- dest = { :action => 'show', :page_glob => @page.slug }
116
- format.html { redirect_to(dest, :notice => 'Page was successfully created.') }
117
- format.xml { render :xml => @page, :status => :created, :location => dest }
103
+ end
104
+ end
105
+
106
+ def edit
107
+ render 'cadmus/pages/edit'
108
+ end
109
+
110
+ def create
111
+ @page = page_scope.new(params[:page])
112
+
113
+ respond_to do |format|
114
+ if @page.save
115
+ dest = { :action => 'show', :page_glob => @page.slug }
116
+ format.html { redirect_to(dest, :notice => 'Page was successfully created.') }
117
+ format.xml { render :xml => @page, :status => :created, :location => dest }
118
118
  format.json { render :json => @page, :status => :created, :location => dest }
119
- else
120
- format.html { render 'cadmus/pages/new' }
121
- format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
119
+ else
120
+ format.html { render 'cadmus/pages/new' }
121
+ format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
122
122
  format.json { render :json => @page.errors, :status => :unprocessable_entity }
123
- end
124
- end
125
- end
126
-
127
- def update
128
- respond_to do |format|
129
- if @page.update_attributes(params[:page])
130
- dest = { :action => 'show', :page_glob => @page.slug }
131
- format.html { redirect_to(dest, :notice => 'Page was successfully updated.') }
132
- format.xml { head :ok }
123
+ end
124
+ end
125
+ end
126
+
127
+ def update
128
+ respond_to do |format|
129
+ if @page.update_attributes(params[:page])
130
+ dest = { :action => 'show', :page_glob => @page.slug }
131
+ format.html { redirect_to(dest, :notice => 'Page was successfully updated.') }
132
+ format.xml { head :ok }
133
133
  format.json { head :ok }
134
- else
135
- format.html { render 'cadmus/pages/edit' }
136
- format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
137
- format.json { render :json => @page.errors, :status => :unprocessable_entity }
138
- end
139
- end
140
- end
141
-
142
- def destroy
143
- @page.destroy
144
-
145
- respond_to do |format|
146
- format.html { redirect_to(:action => :index) }
147
- format.xml { head :ok }
134
+ else
135
+ format.html { render 'cadmus/pages/edit' }
136
+ format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
137
+ format.json { render :json => @page.errors, :status => :unprocessable_entity }
138
+ end
139
+ end
140
+ end
141
+
142
+ def destroy
143
+ @page.destroy
144
+
145
+ respond_to do |format|
146
+ format.html { redirect_to(:action => :index) }
147
+ format.xml { head :ok }
148
148
  format.json { head :ok }
149
- end
150
- end
151
-
152
- protected
149
+ end
150
+ end
151
+
152
+ protected
153
153
 
154
154
  # This gets kind of meta.
155
155
  #
@@ -161,38 +161,38 @@ module Cadmus
161
161
  #
162
162
  # If you don't want to use :id to find the parent object, then redefine the find_parent_by method to return
163
163
  # what you want to use.
164
- def page_parent
165
- return @page_parent if @page_parent
166
-
167
- if page_parent_name && page_parent_class
168
- parent_id_param = "#{page_parent_name}_id"
169
- if params[parent_id_param]
170
- @page_parent = page_parent_class.where(find_parent_by => params[parent_id_param]).first
171
- end
172
- end
173
-
174
- @page_parent
175
- end
176
-
164
+ def page_parent
165
+ return @page_parent if @page_parent
166
+
167
+ if page_parent_name && page_parent_class
168
+ parent_id_param = "#{page_parent_name}_id"
169
+ if params[parent_id_param]
170
+ @page_parent = page_parent_class.where(find_parent_by => params[parent_id_param]).first
171
+ end
172
+ end
173
+
174
+ @page_parent
175
+ end
176
+
177
177
  # Returns the name of the page parent object. This will be used for determining the parameter name for
178
178
  # finding the parent object. For example, if the page parent name is "wiki", the finder will look in
179
179
  # params["wiki_id"] to determine the object ID.
180
180
  #
181
181
  # By default, this will return the value of page_parent_name set at the controller class level, but can
182
182
  # be overridden for cases where the page parent name must be determined on a per-request basis.
183
- def page_parent_name
183
+ def page_parent_name
184
184
  self.class.page_parent_name
185
- end
186
-
185
+ end
186
+
187
187
  # Returns the class of the page parent object. For example, if the pages used by this controller are
188
188
  # children of a Section object, this method should return the Section class.
189
189
  #
190
190
  # By default, this will return the value of page_parent_class set at the controller class level, but can
191
191
  # be overridden for cases where the page parent class must be determined on a per-request basis.
192
- def page_parent_class
193
- self.class.page_parent_class
194
- end
195
-
192
+ def page_parent_class
193
+ self.class.page_parent_class
194
+ end
195
+
196
196
  # Returns the field used to find the page parent object. By default this is :id, but if you need to
197
197
  # find the page parent object using a different parameter (for example, if you use a "slug" field for
198
198
  # part of the URL), this can be changed.
@@ -200,22 +200,22 @@ module Cadmus
200
200
  # By default this method takes its value from the "find_parent_by" accessor set at the controller class
201
201
  # level, but it can be overridden for cases where the finder field name should be determined on a
202
202
  # per-request basis.
203
- def find_parent_by
204
- self.class.find_parent_by || :id
205
- end
206
-
203
+ def find_parent_by
204
+ self.class.find_parent_by || :id
205
+ end
206
+
207
207
  # Returns the ActiveRecord::Relation that will be used for finding pages. If there is a page parent
208
208
  # for this request, this will be the "pages" scope defined by the parent object. If there isn't,
209
209
  # this will be the "global" scope of the page class (i.e. pages with no parent object).
210
- def page_scope
211
- @page_scope ||= page_parent ? page_parent.pages : page_class.global
212
- end
213
-
214
- def load_parent_and_page
215
- if params[:page_glob]
216
- @page = page_scope.find_by_slug(params[:page_glob])
217
- raise ActiveRecord::RecordNotFound.new("No page called #{params[:page_glob]}") unless @page
218
- end
219
- end
220
- end
210
+ def page_scope
211
+ @page_scope ||= page_parent ? page_parent.pages : page_class.global
212
+ end
213
+
214
+ def load_parent_and_page
215
+ if params[:page_glob]
216
+ @page = page_scope.find_by_slug(params[:page_glob])
217
+ raise ActiveRecord::RecordNotFound.new("No page called #{params[:page_glob]}") unless @page
218
+ end
219
+ end
220
+ end
221
221
  end
@@ -3,24 +3,24 @@ module Cadmus
3
3
  # page glob consists of one or more valid slug parts separated by forward slashes. A valid
4
4
  # slug part consists of a lower-case letter followed by any combination of lower-case letters,
5
5
  # digits, and hyphens.
6
- class SlugConstraint
6
+ class SlugConstraint
7
7
  # @param request an HTTP request object.
8
8
  # @return [Boolean] true if this request's +:page_glob+ parameter is a valid Cadmus page
9
9
  # glob, false if it's not. Allows +:page_glob+ to be nil only if the Rails environment
10
10
  # is +test+, because +assert_recognizes+ doesn't always pass the full params hash
11
11
  # including globbed parameters.
12
- def matches?(request)
13
- page_glob = request.symbolized_path_parameters[:page_glob]
14
-
15
- # assert_recognizes doesn't pass the full params hash as we would in a real Rails
16
- # application. So we have to always pass this constraint if we're testing.
17
- return true if page_glob.nil? && Rails.env.test?
18
-
19
- page_glob.sub(/^\//, '').split(/\//).all? do |part|
20
- part =~ /^[a-z][a-z0-9\-]*$/
21
- end
22
- end
23
- end
12
+ def matches?(request)
13
+ page_glob = request.symbolized_path_parameters[:page_glob]
14
+
15
+ # assert_recognizes doesn't pass the full params hash as we would in a real Rails
16
+ # application. So we have to always pass this constraint if we're testing.
17
+ return true if page_glob.nil? && Rails.env.test?
18
+
19
+ page_glob.sub(/^\//, '').split(/\//).all? do |part|
20
+ part =~ /^[a-z][a-z0-9\-]*$/
21
+ end
22
+ end
23
+ end
24
24
  end
25
25
 
26
26
  ActionDispatch::Routing::Mapper.class_eval do
@@ -40,30 +40,31 @@ ActionDispatch::Routing::Mapper.class_eval do
40
40
  # * :controller - changes which controller it maps to. By default, it is "pages" (meaning PagesController).
41
41
  # * :shallow - if set to "true", the edit, show, update and destroy routes won't include the "/pages" prefix. Useful if you're
42
42
  # already inside a unique prefix.
43
- def cadmus_pages(options)
44
- options = options.with_indifferent_access
45
-
46
- controller = options[:controller] || 'pages'
47
-
48
- get "pages" => "#{controller}#index", :as => 'pages'
49
- get "pages/new" => "#{controller}#new", :as => 'new_page'
50
- post "pages" => "#{controller}#create"
43
+ def cadmus_pages(options = nil)
44
+ options ||= {}
45
+ options = options.with_indifferent_access
46
+
47
+ controller = options[:controller] || 'pages'
48
+
49
+ get "pages" => "#{controller}#index", :as => 'pages'
50
+ get "pages/new" => "#{controller}#new", :as => 'new_page'
51
+ post "pages" => "#{controller}#create"
51
52
 
52
- slug_constraint = Cadmus::SlugConstraint.new
53
-
54
- page_actions = Proc.new do
55
- get "*page_glob/edit" => "#{controller}#edit", :as => 'edit_page', :constraints => slug_constraint
56
- get "*page_glob" => "#{controller}#show", :as => 'page', :constraints => slug_constraint
57
- put "*page_glob" => "#{controller}#update", :constraints => slug_constraint
58
- delete "*page_glob" => "#{controller}#destroy", :constraints => slug_constraint
59
- end
60
-
61
- if options[:shallow]
62
- instance_eval(&page_actions)
63
- else
64
- scope 'pages' do
65
- instance_eval(&page_actions)
66
- end
67
- end
68
- end
53
+ slug_constraint = Cadmus::SlugConstraint.new
54
+
55
+ page_actions = Proc.new do
56
+ get "*page_glob/edit" => "#{controller}#edit", :as => 'edit_page', :constraints => slug_constraint
57
+ get "*page_glob" => "#{controller}#show", :as => 'page', :constraints => slug_constraint
58
+ put "*page_glob" => "#{controller}#update", :constraints => slug_constraint
59
+ delete "*page_glob" => "#{controller}#destroy", :constraints => slug_constraint
60
+ end
61
+
62
+ if options[:shallow]
63
+ instance_eval(&page_actions)
64
+ else
65
+ scope 'pages' do
66
+ instance_eval(&page_actions)
67
+ end
68
+ end
69
+ end
69
70
  end
@@ -1,3 +1,3 @@
1
1
  module Cadmus
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cadmus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-18 00:00:00.000000000 Z
13
+ date: 2012-06-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70361178912560 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70361178912560
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: liquid
28
- requirement: &70361178912140 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,7 +38,12 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70361178912140
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  description: Why deal with setting up a separate CMS? Cadmus is just a little bit
38
48
  of CMS and fits nicely into your existing app. It can be used for allowing users
39
49
  to customize areas of the site, for creating editable "about us" pages, and more.
@@ -46,6 +56,7 @@ extra_rdoc_files: []
46
56
  files:
47
57
  - .gitignore
48
58
  - .yardopts
59
+ - CHANGELOG.md
49
60
  - Gemfile
50
61
  - LICENSE
51
62
  - README.md
@@ -77,15 +88,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
88
  - - ! '>='
78
89
  - !ruby/object:Gem::Version
79
90
  version: '0'
91
+ segments:
92
+ - 0
93
+ hash: -1527653325497525867
80
94
  required_rubygems_version: !ruby/object:Gem::Requirement
81
95
  none: false
82
96
  requirements:
83
97
  - - ! '>='
84
98
  - !ruby/object:Gem::Version
85
99
  version: '0'
100
+ segments:
101
+ - 0
102
+ hash: -1527653325497525867
86
103
  requirements: []
87
104
  rubyforge_project:
88
- rubygems_version: 1.8.11
105
+ rubygems_version: 1.8.24
89
106
  signing_key:
90
107
  specification_version: 3
91
108
  summary: Embeddable CMS for Rails 3 apps