constructor-pages 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52fee714d69f06402fc65d1d9ad8f30dea28ff63
4
- data.tar.gz: 9dc647b30c35888a0b31b823508f70e9f4268f6e
3
+ metadata.gz: ad8ecd535c634c2ca60ef07a528827309da354dc
4
+ data.tar.gz: a40b0e874c6deb4d0bfd4534429bd43a97484131
5
5
  SHA512:
6
- metadata.gz: 5b5d24e9e7b32277bc20196147fa0dbf784c0046b5238c5aa25acdc4dfdd5a868073c7273904a6238837eee7e7a00f97624a62c1f4e07438148406bbe98a4d4a
7
- data.tar.gz: c3728f3b11e85bd6314d740e727f781b8405d1216a32076b0fc10e06d17548fbd93d64d337bc94ccf9b5a5ee26dcd9a34f909e3cd9e03ce915d83dd2889fb4bf
6
+ metadata.gz: 4d3018fa5da4f6ea3c4dec6e68f9e8868fa6da55c572487fca2d934d6869dc577df6701dd6285695bc730847aeabee27d1d62e18134f00093214d6f202c2866b
7
+ data.tar.gz: d926d66001f42d933ddb6f016d1ac57b1edda1514fb9908e9050eaef3051659a440d59114def71bdaf6083a812bbd9e8589388db92c4a793756281953038d45e
@@ -10,7 +10,7 @@ module ConstructorPages
10
10
 
11
11
  def index
12
12
  @pages = Page.includes(:template).load
13
- @pages_cache = Digest::MD5.hexdigest(@pages.map{|p| [p.name, p.url, p.lft, p.template_id]}.join)
13
+ @pages_cache = Digest::MD5.hexdigest(@pages.map{|p| [p.name, p.full_url, p.in_url, p.lft, p.template_id]}.join)
14
14
  @template_exists = Template.count != 0
15
15
  flash[:notice] = 'Create at least one template' unless @template_exists
16
16
  end
@@ -21,7 +21,7 @@ module ConstructorPages
21
21
 
22
22
  def new_child
23
23
  @page, @parent_id = Page.new, params[:id]
24
- @template_id = Page.find(@parent_id).try(:template).child.id
24
+ @template_id = Page.find(@parent_id).try(:template).try(:child).try(:id)
25
25
  end
26
26
 
27
27
  def show
@@ -30,17 +30,19 @@ module ConstructorPages
30
30
  redirect_to @page.link if @page.redirect?
31
31
  _code_name = @page.template.code_name
32
32
  instance_variable_set('@'+_code_name, @page)
33
-
33
+ _code_name = _code_name.pluralize
34
34
  respond_to do |format|
35
- format.html { render "templates/#{_code_name}" }
36
- format.json { render "templates/#{_code_name}.json", layout: false }
37
- format.xml { render "templates/#{_code_name}.xml", layout: false }
35
+ format.html { render "#{_code_name}/show" }
36
+ format.json { render "#{_code_name}/show.json", layout: false rescue render json: @page }
37
+ format.xml { render "#{_code_name}/show.xml", layout: false rescue render xml: @page }
38
38
  end
39
39
  end
40
40
 
41
41
  def edit
42
42
  @page = Page.find(params[:id])
43
43
  @parent_id, @template_id = @page.parent.try(:id), @page.template.id
44
+ _code_name = @page.template.code_name.pluralize
45
+ render "#{_code_name}/edit" rescue render :edit
44
46
  end
45
47
 
46
48
  def create
@@ -50,7 +52,13 @@ module ConstructorPages
50
52
  @page.touch_branch
51
53
  redirect_to pages_path, notice: t(:page_success_added, name: @page.name)
52
54
  else
53
- render :new
55
+ if @page.template_id
56
+ _template = Template.find(@page.template_id)
57
+ _code_name = _template.code_name.pluralize if _template
58
+ render "#{_code_name}/new" rescue render :new
59
+ else
60
+ render :new
61
+ end
54
62
  end
55
63
  end
56
64
 
@@ -68,7 +76,7 @@ module ConstructorPages
68
76
 
69
77
  redirect_to pages_path, notice: t(:page_success_updated, name: @page.name)
70
78
  else
71
- render :edit
79
+ render "#{@page.template.code_name.pluralize}/new" rescue render :edit
72
80
  end
73
81
  end
74
82
 
@@ -95,6 +103,7 @@ module ConstructorPages
95
103
  :in_nav,
96
104
  :in_map,
97
105
  :in_menu,
106
+ :in_url,
98
107
  :link
99
108
  )
100
109
  end
@@ -34,7 +34,7 @@ module ConstructorPages
34
34
  # @param parent_id integer
35
35
  # @param url should looks like <tt>'hello-world-page'</tt> without leading slash
36
36
  def full_url_generate(parent_id, url = '')
37
- '/' + Page.find(parent_id).self_and_ancestors.map(&:url).append(url).join('/')
37
+ '/' + Page.find(parent_id).self_and_ancestors.map{|p| p.url if p.in_url}.append(url).compact.join('/')
38
38
  end
39
39
 
40
40
  # Check code_name for field and template.
@@ -157,6 +157,8 @@ module ConstructorPages
157
157
 
158
158
  alias_method :find_pages_in_branch, :find_page_in_branch
159
159
 
160
+ def in_breadcrumbs; in_nav end
161
+
160
162
  def published?; active? end
161
163
 
162
164
  # Return true if there is a file upload field in page
@@ -199,7 +201,7 @@ module ConstructorPages
199
201
 
200
202
  # if url has been changed by manually or url is empty
201
203
  def friendly_url
202
- self.url = ((auto_url || url.empty?) ? transliterate(name, '') : url).parameterize
204
+ self.url = ((auto_url || url.empty?) ? parameterize(transliterate(name, '')) : url)
203
205
  end
204
206
 
205
207
  # Page is not valid if there is no template
@@ -215,7 +217,7 @@ module ConstructorPages
215
217
 
216
218
  # Reload all descendants
217
219
  def descendants_update
218
- descendants.map(&:save) if self.full_url_changed?
220
+ descendants.map(&:save) if self.full_url_changed? or self.in_url_changed?
219
221
  end
220
222
  end
221
223
  end
@@ -23,7 +23,7 @@ module ConstructorPages
23
23
 
24
24
  # Return child corresponding child_id or children first
25
25
  def child
26
- child_id ? self.class.find(child_id) : children.first if !leaf?
26
+ child_id ? Template.find(child_id) : children.first if !leaf?
27
27
  end
28
28
 
29
29
  # Convert name to accusative
@@ -1,7 +1,7 @@
1
1
  - image = page.get_field_value(field.code_name)
2
2
 
3
3
  - if image
4
- = image_tag image.value.thumb('200x200').url
4
+ = image_tag image.thumb('200x200').url
5
5
 
6
6
  %br/
7
7
  = file_field_tag "fields[#{field.code_name}]", class: 'span6'
@@ -66,6 +66,10 @@
66
66
  = f.check_box :in_nav
67
67
  =t :breadcrumbs
68
68
 
69
+ %label.checkbox.inline.span2{for: 'in_url'}
70
+ = f.check_box :in_url
71
+ =t :url
72
+
69
73
  .accordion
70
74
  .accordion-group
71
75
  .accordion-heading.text-center
@@ -0,0 +1,17 @@
1
+ class AddInUrlToPages < ActiveRecord::Migration
2
+ def self.up
3
+ add_column 'constructor_pages_pages', :in_url, :boolean, default: true
4
+
5
+ ConstructorPages::Page.reset_column_information
6
+
7
+ ConstructorPages::Page.all.each do |p|
8
+ p.in_url = true
9
+ p.save
10
+ end
11
+
12
+ end
13
+
14
+ def self.down
15
+ remove_column 'constructor_pages_pages', :in_url
16
+ end
17
+ end
data/spec/factories.rb ADDED
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :pages, :class => ConstructorPages::Page do
3
+ sequence(:name, "a") {|n| "Test title #{n}" }
4
+ end
5
+ end
@@ -173,6 +173,13 @@ module ConstructorPages
173
173
  page.should have_select 'Template', selected: '-- Child'
174
174
  end
175
175
 
176
+ it 'should edit with page view if no view found' do
177
+ _template = Template.create name: 'Hello', code_name: 'hello'
178
+ _page = Page.create name: 'Hello', template: _template
179
+ visit pages.new_child_page_path(_page)
180
+ page.should_not have_content 'This page show new with template'
181
+ end
182
+
176
183
  it 'should has published checkbox' do
177
184
  visit pages.new_page_path
178
185
  page.should have_checked_field 'Active'
@@ -225,6 +232,18 @@ module ConstructorPages
225
232
  end
226
233
  end
227
234
 
235
+ it 'should edit with template view' do
236
+ visit pages.edit_page_path(@page)
237
+ page.should have_content 'This page show edit with template'
238
+ end
239
+
240
+ it 'should edit with page view if no view found' do
241
+ _template = Template.create name: 'Hello', code_name: 'hello'
242
+ _page = Page.create name: 'Hello', template: _template
243
+ visit pages.edit_page_path(_page)
244
+ page.should_not have_content 'This page show edit with template'
245
+ end
246
+
228
247
  it 'should has delete link' do
229
248
  visit pages.edit_page_path(@page)
230
249
  page.should have_link 'Delete'
@@ -246,6 +265,40 @@ module ConstructorPages
246
265
  @page.description.should == 'Zanussi conditioners Voronezh'
247
266
  page.should have_text 'updated successfully'
248
267
  end
268
+
269
+ describe 'renegerate descendants' do
270
+ before :each do
271
+ _template = Template.create name: 'Another page', code_name: 'another_page'
272
+ _page_first = Page.create name: 'First', template: _template
273
+ _page_second = Page.create name: 'Second', parent_id: _page_first.id, template: _template
274
+ _page_third = Page.create name: 'Third', parent_id: _page_second.id, template: _template
275
+
276
+ visit pages.pages_path
277
+ page.should have_link('First', '/first')
278
+ page.should have_link('Second', '/first/second')
279
+ page.should have_link('Third', '/first/second/third')
280
+
281
+ visit pages.edit_page_path(_page_first)
282
+ end
283
+
284
+ it 'should regenerate full_url of descendants without url if full_url or in_url changed' do
285
+ check 'Url', false
286
+ click_button 'Update Page'
287
+
288
+ page.should have_link('First', '/first')
289
+ page.should have_link('Second', '/second')
290
+ page.should have_link('Third', '/second/third')
291
+ end
292
+
293
+ it 'should regenerate full_url of descendants with url if full_url or in_url changed' do
294
+ check 'Url', true
295
+ click_button 'Update Page'
296
+
297
+ page.should have_link('First', '/first')
298
+ page.should have_link('Second', '/first/second')
299
+ page.should have_link('Third', '/first/second/third')
300
+ end
301
+ end
249
302
  end
250
303
 
251
304
  describe 'Delete page' do
@@ -21,8 +21,7 @@ module ConstructorPages
21
21
 
22
22
  it 'should create type_fields after' do
23
23
  field = Field.create name: 'Content', code_name: 'content', template: @template, type_value: 'text'
24
- page = Page.create name: 'New page', template: @template
25
-
24
+ page = Page.create(name: 'New page', template: @template)
26
25
  field.get_value_for(page).should == ''
27
26
  end
28
27
  end
@@ -160,7 +159,6 @@ module ConstructorPages
160
159
  end
161
160
  end
162
161
 
163
-
164
162
  context 'INSTANCE METHODS' do
165
163
  context 'Getting and setting field value' do
166
164
  before :each do
@@ -368,6 +366,39 @@ module ConstructorPages
368
366
  page.save
369
367
  page.url.should == 'another-world'
370
368
  end
369
+
370
+ it 'should doesn\'t parameterize' do
371
+ page = Page.create name: 'Hello', url: 'hello_world_How_Are/You', auto_url: false
372
+ page.url.should == 'hello_world_How_Are/You'
373
+ end
374
+ end
375
+ end
376
+
377
+ describe '#in_menu' do
378
+ it 'should be true by default' do
379
+ page = Page.create name: 'Hello'
380
+ page.in_menu.should be_true
381
+ end
382
+ end
383
+
384
+ describe '#in_nav' do
385
+ it 'should be true by default' do
386
+ page = Page.create name: 'Hello'
387
+ page.in_nav.should be_true
388
+ end
389
+ end
390
+
391
+ describe '#in_map' do
392
+ it 'should be true by default' do
393
+ page = Page.create name: 'Hello'
394
+ page.in_map.should be_true
395
+ end
396
+ end
397
+
398
+ describe '#in_url' do
399
+ it 'should be true by default' do
400
+ page = Page.create name: 'Hello'
401
+ page.in_url.should be_true
371
402
  end
372
403
  end
373
404
 
@@ -414,6 +445,17 @@ module ConstructorPages
414
445
  page.full_url.should == '/page'
415
446
  end
416
447
  end
448
+
449
+ context 'if page in_url false' do
450
+ it 'should generate without url' do
451
+ page = Page.create name: 'Hello world'
452
+ second_page = Page.create name: 'Sub page', url: 'my-world', auto_url: false, parent_id: page.id, in_url: false
453
+ third_page = Page.create name: 'Third page', url: 'third', auto_url: false, parent_id: second_page.id
454
+ page.full_url.should == '/hello-world'
455
+ second_page.full_url.should == '/hello-world/my-world'
456
+ third_page.full_url.should == '/hello-world/third'
457
+ end
458
+ end
417
459
  end
418
460
 
419
461
  describe 'method_missing' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Zotov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-01 00:00:00.000000000 Z
11
+ date: 2013-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constructor-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.4
19
+ version: 0.8.5
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: 0.8.4
26
+ version: 0.8.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dragonfly
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +187,7 @@ files:
187
187
  - db/migrate/10_create_html_types.rb
188
188
  - db/migrate/11_create_image_types.rb
189
189
  - db/migrate/12_add_default_template.rb
190
+ - db/migrate/13_add_in_url_to_pages.rb
190
191
  - db/migrate/1_create_pages.rb
191
192
  - db/migrate/2_create_templates.rb
192
193
  - db/migrate/3_create_fields.rb
@@ -198,6 +199,7 @@ files:
198
199
  - db/migrate/9_create_date_types.rb
199
200
  - lib/constructor-pages.rb
200
201
  - lib/constructor_pages/engine.rb
202
+ - spec/factories.rb
201
203
  - spec/features/constructor_pages/fields_spec.rb
202
204
  - spec/features/constructor_pages/pages_spec.rb
203
205
  - spec/features/constructor_pages/templates_spec.rb
@@ -237,6 +239,7 @@ signing_key:
237
239
  specification_version: 4
238
240
  summary: Pages for Constructor CMS
239
241
  test_files:
242
+ - spec/factories.rb
240
243
  - spec/features/constructor_pages/fields_spec.rb
241
244
  - spec/features/constructor_pages/pages_spec.rb
242
245
  - spec/features/constructor_pages/templates_spec.rb