refinerycms-page-menus 2.0.3 → 2.0.4

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.
Files changed (67) hide show
  1. data/app/assets/javascripts/refinery/backend.js.coffee +24 -0
  2. data/app/assets/stylesheets/refinery/select_form.css.scss +182 -0
  3. data/app/controllers/refinery/admin/page_menus_controller.rb +57 -1
  4. data/app/controllers/refinery/admin/page_positions_controller.rb +19 -39
  5. data/app/helpers/refinery/page_positions_helper.rb +66 -0
  6. data/app/models/refinery/page_menu.rb +3 -15
  7. data/app/models/refinery/page_position.rb +87 -15
  8. data/app/views/refinery/admin/page_menus/_form.html.erb +27 -35
  9. data/app/views/refinery/admin/page_menus/_form_actions.html.erb +23 -0
  10. data/app/views/refinery/admin/page_menus/_page_menu.html.erb +16 -0
  11. data/app/views/refinery/admin/page_menus/_page_menus.html.erb +2 -0
  12. data/app/views/refinery/admin/page_menus/_records.html.erb +18 -0
  13. data/app/views/refinery/admin/page_menus/_sortable_list.html.erb +5 -0
  14. data/app/views/refinery/admin/page_menus/edit.html.erb +12 -1
  15. data/app/views/refinery/admin/page_menus/index.html.erb +3 -0
  16. data/app/views/refinery/admin/page_positions/_custom_link.html.erb +14 -0
  17. data/app/views/refinery/admin/page_positions/_page_position.html.erb +25 -48
  18. data/app/views/refinery/admin/page_positions/_resource_link.html.erb +14 -0
  19. data/app/views/refinery/admin/page_positions/_resource_link_editor_box.html.erb +21 -0
  20. data/app/views/refinery/admin/page_positions/create.js.erb +5 -0
  21. data/app/views/refinery/admin/page_positions/destroy.js.erb +3 -0
  22. data/config/locales/da.yml +9 -5
  23. data/config/locales/en.yml +25 -82
  24. data/config/locales/fr.yml +37 -0
  25. data/config/routes.rb +15 -4
  26. data/db/migrate/{20120406121839_create_page_menus.rb → 01_create_page_menus.rb} +0 -0
  27. data/db/migrate/{20120411133453_add_permatitle_to_page_menus.rb → 02_add_permatitle_to_page_menus.rb} +0 -0
  28. data/db/migrate/{20120411134419_add_menu_match_to_page_positions.rb → 03_add_menu_match_to_page_positions.rb} +0 -0
  29. data/db/migrate/04_add_flex_fields_to_page_positions.rb +9 -0
  30. data/db/migrate/05_remove_refinery_page_id_from_refinery_page_positions.rb +9 -0
  31. data/db/seeds.rb +18 -0
  32. data/lib/generators/refinery/page_menus/page_menus_generator.rb +12 -2
  33. data/lib/generators/refinery/page_menus/templates/config/initializers/refinery/page_menus.rb.erb +11 -0
  34. data/lib/refinery/page_menus/configuration.rb +24 -3
  35. data/lib/refinery/page_menus/controller_extension.rb +7 -3
  36. data/lib/refinery/page_menus/engine.rb +9 -9
  37. data/lib/refinery/page_menus/instance_methods.rb +1 -1
  38. data/lib/refinery/page_menus/version.rb +18 -0
  39. data/lib/refinery/page_menus.rb +1 -2
  40. data/readme.md +66 -1
  41. metadata +91 -52
  42. data/.gitignore +0 -2
  43. data/app/views/refinery/admin/page_positions/_actions.html.erb +0 -45
  44. data/app/views/refinery/admin/page_positions/_records.html.erb +0 -14
  45. data/app/views/refinery/admin/page_positions/_sortable_list.html.erb +0 -4
  46. data/app/views/refinery/admin/page_positions/index.html.erb +0 -11
  47. data/app/views/refinery/admin/pages/_actions.html.erb +0 -40
  48. data/app/views/refinery/admin/pages/_list_actions.html.erb +0 -28
  49. data/app/views/refinery/admin/pages/_list_page.html.erb +0 -46
  50. data/app/views/refinery/admin/pages/_list_records.html.erb +0 -16
  51. data/app/views/refinery/admin/pages/list.html.erb +0 -8
  52. data/app/views/refinery/admin/pages_shared/_submenu.html.erb +0 -65
  53. data/lib/refinery/page_menus/model_extension.rb +0 -14
  54. data/license.md +0 -21
  55. data/refinerycms-page-menus.gemspec +0 -25
  56. data/spec/factories/pages.rb +0 -5
  57. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +0 -44
  58. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +0 -29
  59. data/spec/lib/pages/content_page_presenter_spec.rb +0 -43
  60. data/spec/lib/pages/content_presenter_spec.rb +0 -111
  61. data/spec/lib/pages/page_part_section_presenter_spec.rb +0 -35
  62. data/spec/lib/pages/section_presenter_spec.rb +0 -86
  63. data/spec/lib/pages/title_section_presenter_spec.rb +0 -21
  64. data/spec/lib/pages_spec.rb +0 -26
  65. data/spec/models/refinery/page_spec.rb +0 -415
  66. data/spec/requests/refinery/admin/pages_spec.rb +0 -613
  67. data/spec/requests/refinery/pages_spec.rb +0 -302
@@ -1,415 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Refinery
4
- describe Page do
5
-
6
- let(:page_title) { 'RSpec is great for testing too' }
7
- let(:child_title) { 'The child page' }
8
-
9
- # For when we do not need the page persisted.
10
- let(:page) { subject.class.new(:title => page_title, :deletable => true)}
11
- let(:child) { page.children.new(:title => child_title) }
12
-
13
- # For when we need the page persisted.
14
- let(:created_page) { subject.class.create!(:title => page_title, :deletable => true) }
15
- let(:created_child) { created_page.children.create!(:title => child_title) }
16
-
17
- def page_cannot_be_destroyed
18
- page.destroy.should == false
19
- end
20
-
21
- def turn_off_marketable_urls
22
- Refinery::Pages.stub(:marketable_urls).and_return(false)
23
- end
24
-
25
- def turn_on_marketable_urls
26
- Refinery::Pages.stub(:marketable_urls).and_return(true)
27
- end
28
-
29
- context 'cannot be deleted under certain rules' do
30
- it 'if link_url is present' do
31
- page.link_url = '/plugin-name'
32
- page_cannot_be_destroyed
33
- end
34
-
35
- it 'if refinery team deems it so' do
36
- page.deletable = false
37
- page_cannot_be_destroyed
38
- end
39
-
40
- it 'if menu_match is present' do
41
- page.menu_match = "^/#{page_title}*$"
42
- page_cannot_be_destroyed
43
- end
44
-
45
- it 'unless you really want it to! >:]' do
46
- page.deletable = false
47
- page_cannot_be_destroyed
48
- page.destroy!.should be
49
- end
50
- end
51
-
52
- context 'page urls' do
53
- let(:page_path) { 'rspec-is-great-for-testing-too' }
54
- let(:child_path) { 'the-child-page' }
55
- it 'return a full path' do
56
- page.path.should == page_title
57
- end
58
-
59
- it 'and all of its parent page titles, reversed' do
60
- created_child.path.should == [page_title, child_title].join(' - ')
61
- end
62
-
63
- it 'or normally ;-)' do
64
- created_child.path(:reversed => false).should == [child_title, page_title].join(' - ')
65
- end
66
-
67
- it 'returns its url' do
68
- page.link_url = '/contact'
69
- page.url.should == '/contact'
70
- end
71
-
72
- it 'returns its path with marketable urls' do
73
- created_page.url[:id].should be_nil
74
- created_page.url[:path].should == [page_path]
75
- end
76
-
77
- it 'returns its path underneath its parent with marketable urls' do
78
- created_child.url[:id].should be_nil
79
- created_child.url[:path].should == [created_page.url[:path].first, child_path]
80
- end
81
-
82
- it 'no path parameter without marketable urls' do
83
- turn_off_marketable_urls
84
- created_page.url[:path].should be_nil
85
- created_page.url[:id].should == page_path
86
- turn_on_marketable_urls
87
- end
88
-
89
- it "doesn't mention its parent without marketable urls" do
90
- turn_off_marketable_urls
91
- created_child.url[:id].should == child_path
92
- created_child.url[:path].should be_nil
93
- turn_on_marketable_urls
94
- end
95
-
96
- it 'returns its path with slug set by menu_title' do
97
- page.menu_title = 'RSpec is great'
98
- page.save
99
- page.reload
100
-
101
- page.url[:id].should be_nil
102
- page.url[:path].should == ['rspec-is-great']
103
- end
104
- end
105
-
106
- context 'custom slugs' do
107
- let(:custom_page_slug) { 'custom-page-slug' }
108
- let(:custom_child_slug) { 'custom-child-slug' }
109
- let(:page_with_custom_slug) {
110
- subject.class.new(:title => page_title, :custom_slug => custom_page_slug)
111
- }
112
- let(:child_with_custom_slug) {
113
- page.children.new(:title => child_title, :custom_slug => custom_child_slug)
114
- }
115
-
116
- after(:each) do
117
- ::Refinery::I18n.stub(:current_frontend_locale).and_return(Refinery::I18n.default_frontend_locale)
118
- ::Refinery::I18n.current_locale = Refinery::I18n.default_locale
119
- end
120
-
121
- it 'returns its path with custom slug' do
122
- page_with_custom_slug.save
123
- page_with_custom_slug.url[:id].should be_nil
124
- page_with_custom_slug.url[:path].should == [custom_page_slug]
125
- end
126
-
127
- it 'returns its path underneath its parent with custom urls' do
128
- child_with_custom_slug.save
129
- page.save
130
-
131
- child_with_custom_slug.url[:id].should be_nil
132
- child_with_custom_slug.url[:path].should == [page.url[:path].first, custom_child_slug]
133
- end
134
-
135
- it 'returns its path with custom slug when using different locale' do
136
- ::Refinery::I18n.stub(:current_frontend_locale).and_return(:ru)
137
- ::Refinery::I18n.current_locale = :ru
138
- page_with_custom_slug.custom_slug = "#{custom_page_slug}-ru"
139
- page_with_custom_slug.save
140
- page_with_custom_slug.reload
141
-
142
- page_with_custom_slug.url[:id].should be_nil
143
- page_with_custom_slug.url[:path].should == ["#{custom_page_slug}-ru"]
144
- end
145
-
146
- it 'returns path underneath its parent with custom urls when using different locale' do
147
- ::Refinery::I18n.stub(:current_frontend_locale).and_return(:ru)
148
- ::Refinery::I18n.current_locale = :ru
149
- child_with_custom_slug.custom_slug = "#{custom_child_slug}-ru"
150
- child_with_custom_slug.save
151
- child_with_custom_slug.reload
152
-
153
- child_with_custom_slug.url[:id].should be_nil
154
- child_with_custom_slug.url[:path].should == [page.url[:path].first, "#{custom_child_slug}-ru"]
155
- end
156
-
157
- end
158
-
159
- context 'home page' do
160
- it 'responds as the home page' do
161
- page.link_url = '/'
162
- page.home?.should == true
163
- end
164
-
165
- it 'responds as a normal page when not set to home page' do
166
- page.home?.should == false
167
- end
168
- end
169
-
170
- context 'content sections (page parts)' do
171
- before do
172
- page.parts.new(:title => 'body', :content => "I'm the first page part for this page.", :position => 0)
173
- page.parts.new(:title => 'side body', :content => 'Closely followed by the second page part.', :position => 1)
174
- end
175
-
176
- it 'return the content when using content_for' do
177
- page.content_for(:body).should == "<p>I'm the first page part for this page.</p>"
178
- page.content_for('BoDY').should == "<p>I'm the first page part for this page.</p>"
179
- end
180
-
181
- it 'return all page part content' do
182
- page.all_page_part_content.should == "<p>I'm the first page part for this page.</p> <p>Closely followed by the second page part.</p>"
183
- end
184
-
185
- it 'reposition correctly' do
186
- page.save
187
-
188
- page.parts.first.update_attribute(:position, 6)
189
- page.parts.last.update_attribute(:position, 4)
190
-
191
- page.parts.first.position.should == 6
192
- page.parts.last.position.should == 4
193
-
194
- page.reposition_parts!
195
-
196
- page.parts.first.position.should == 0
197
- page.parts.last.position.should == 1
198
- end
199
- end
200
-
201
- context 'draft pages' do
202
- it 'not live when set to draft' do
203
- page.draft = true
204
- page.live?.should_not be
205
- end
206
-
207
- it 'live when not set to draft' do
208
- page.draft = false
209
- page.live?.should be
210
- end
211
- end
212
-
213
- context "should add url suffix" do
214
- let(:reserved_word) { subject.class.friendly_id_config.reserved_words.last }
215
- let(:page_with_reserved_title) {
216
- subject.class.create!(:title => reserved_word, :deletable => true)
217
- }
218
- let(:child_with_reserved_title_parent) {
219
- page_with_reserved_title.children.create(:title => 'reserved title child page')
220
- }
221
-
222
- before { turn_on_marketable_urls }
223
-
224
- it 'when title is set to a reserved word' do
225
- page_with_reserved_title.url[:path].should == ["#{reserved_word}-page"]
226
- end
227
-
228
- it "when parent page title is set to a reserved word" do
229
- child_with_reserved_title_parent.url[:path].should == ["#{reserved_word}-page", 'reserved-title-child-page']
230
- end
231
- end
232
-
233
- context 'meta data' do
234
- context 'responds to' do
235
- it 'meta_keywords' do
236
- page.respond_to?(:meta_keywords)
237
- end
238
-
239
- it 'meta_description' do
240
- page.respond_to?(:meta_description)
241
- end
242
-
243
- it 'browser_title' do
244
- page.respond_to?(:browser_title)
245
- end
246
- end
247
-
248
- context 'allows us to assign to' do
249
- it 'meta_keywords' do
250
- page.meta_keywords = 'Some, great, keywords'
251
- page.meta_keywords.should == 'Some, great, keywords'
252
- end
253
-
254
- it 'meta_description' do
255
- page.meta_description = 'This is my description of the page for search results.'
256
- page.meta_description.should == 'This is my description of the page for search results.'
257
- end
258
-
259
- it 'browser_title' do
260
- page.browser_title = 'An awesome browser title for SEO'
261
- page.browser_title.should == 'An awesome browser title for SEO'
262
- end
263
- end
264
-
265
- context 'allows us to update' do
266
- it 'meta_keywords' do
267
- page.meta_keywords = 'Some, great, keywords'
268
- page.save
269
-
270
- page.reload
271
- page.meta_keywords.should == 'Some, great, keywords'
272
- end
273
-
274
- it 'meta_description' do
275
- page.meta_description = 'This is my description of the page for search results.'
276
- page.save
277
-
278
- page.reload
279
- page.meta_description.should == 'This is my description of the page for search results.'
280
- end
281
-
282
- it 'browser_title' do
283
- page.browser_title = 'An awesome browser title for SEO'
284
- page.save
285
-
286
- page.reload
287
- page.browser_title.should == 'An awesome browser title for SEO'
288
- end
289
- end
290
-
291
- end
292
-
293
- describe "#to_refinery_menu_item" do
294
- let(:page) do
295
- Refinery::Page.new(
296
- :id => 5,
297
- :parent_id => 8,
298
- :menu_match => "^/foo$"
299
-
300
- # Refinery::Page does not allow setting lft and rgt, so stub them.
301
- ).tap do |p|
302
- p[:lft] = 6
303
- p[:rgt] = 7
304
- end
305
- end
306
-
307
- subject { page.to_refinery_menu_item }
308
-
309
- shared_examples_for("Refinery menu item hash") do
310
- [ [:id, 5],
311
- [:lft, 6],
312
- [:rgt, 7],
313
- [:parent_id, 8],
314
- [:menu_match, "^/foo$"]
315
- ].each do |attr, value|
316
- it "returns the correct :#{attr}" do
317
- subject[attr].should eq(value)
318
- end
319
- end
320
-
321
- it "returns the correct :url" do
322
- subject[:url].should be_a(Hash) # guard against nil
323
- subject[:url].should eq(page.url)
324
- end
325
- end
326
-
327
- context "with #page_menu_title" do
328
- before do
329
- page.page_menu_title = "Page Menu Title"
330
- end
331
-
332
- it_should_behave_like "Refinery menu item hash"
333
-
334
- it "returns the page_menu_title for :title" do
335
- subject[:title].should eq("Page Menu Title")
336
- end
337
- end
338
-
339
- context "with #page_title" do
340
- before do
341
- page.page_title = "Page Title"
342
- end
343
-
344
- it_should_behave_like "Refinery menu item hash"
345
-
346
- it "returns the page_title for :title" do
347
- subject[:title].should eq("Page Title")
348
- end
349
- end
350
-
351
- context "with #menu_title" do
352
- before do
353
- page[:menu_title] = "Menu Title"
354
- end
355
-
356
- it_should_behave_like "Refinery menu item hash"
357
-
358
- it "returns the menu_title for :title" do
359
- subject[:title].should eq("Menu Title")
360
- end
361
- end
362
-
363
- context "with #title" do
364
- before do
365
- page[:title] = "Title"
366
- end
367
-
368
- it_should_behave_like "Refinery menu item hash"
369
-
370
- it "returns the title for :title" do
371
- subject[:title].should eq("Title")
372
- end
373
- end
374
- end
375
-
376
- describe ".in_menu?" do
377
- context "when live? and show_in_menu? returns true" do
378
- it "returns true" do
379
- page.stub(:live?).and_return(true)
380
- page.stub(:show_in_menu?).and_return(true)
381
- page.in_menu?.should be_true
382
- end
383
- end
384
-
385
- context "when live? or show_in_menu? doesn't return true" do
386
- it "returns false" do
387
- page.stub(:live?).and_return(true)
388
- page.stub(:show_in_menu?).and_return(false)
389
- page.in_menu?.should be_false
390
-
391
- page.stub(:live?).and_return(false)
392
- page.stub(:show_in_menu?).and_return(true)
393
- page.in_menu?.should be_false
394
- end
395
- end
396
- end
397
-
398
- describe ".not_in_menu?" do
399
- context "when in_menu? returns true" do
400
- it "returns false" do
401
- page.stub(:in_menu?).and_return(true)
402
- page.not_in_menu?.should be_false
403
- end
404
- end
405
-
406
- context "when in_menu? returns false" do
407
- it "returns true" do
408
- page.stub(:in_menu?).and_return(false)
409
- page.not_in_menu?.should be_true
410
- end
411
- end
412
- end
413
-
414
- end
415
- end