effective_pages 0.9.7 → 0.9.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1d30bf85dfe32cfaa5d4cbfeb4af24cd5078d44
4
- data.tar.gz: b580911a306abd7383e6aa2fb0c1bbe0510476ca
3
+ metadata.gz: e1a00ef1dd50024c7491f7112e97b858fd65a7a9
4
+ data.tar.gz: a1cb70948388278617d07d3e401bb0a43f425f1d
5
5
  SHA512:
6
- metadata.gz: e2410edff072d954a3606cefd966581be37953a78f6169dd635cd648b9a7160620b811d5db3a95af8fb7e89b02adc0c568e01f24548a549e120bc0a75130359b
7
- data.tar.gz: f7e227c8759d2738684192e93c5b4cad3acc41093dcc70ac6583b9ed5f1eee03e66090c1b2331187454b37cb59919c13c7baafd2d86ac80ab42f9b8df79daaeb
6
+ metadata.gz: abadfdb4293769589bb16bba5f0818377056b6fcc2842c7678dfc8e7ea756315cb3b5f1f71ba8128534f8674faa1b0547a87bd8cbb4039bc45455bf8e6b2be0a
7
+ data.tar.gz: 598eea46d0fdbc1a2543dfba51f87ca048fe603032da65f8d52acdd0f5e28a9fbf3801606ab8efb05cb8637a43107bd2074bcc3252f44bdbb51d015f2f276a0e
@@ -12,25 +12,35 @@ module Effective
12
12
 
13
13
  accepts_nested_attributes_for :menu_items, :allow_destroy => true
14
14
 
15
- before_create do
15
+ before_save do
16
16
  if self.menu_items.find { |menu_item| menu_item.lft == 1 }.blank?
17
- menu_items.build(:title => 'Home', :url => '#', :lft => 1, :rgt => 2)
17
+ menu_items.build(:title => 'Home', :url => '/', :lft => 1, :rgt => 2)
18
18
  end
19
19
  end
20
20
 
21
21
  def self.update_from_effective_regions!(params)
22
- (params || {}).each do |menu_id, attributes|
23
- menu = Effective::Menu.includes(:menu_items).find(menu_id)
22
+ Effective::Menu.transaction do
23
+ (params || {}).each do |menu_id, attributes|
24
+ menu = Effective::Menu.includes(:menu_items).find(menu_id)
25
+ menu.menu_items.delete_all
24
26
 
25
- attributes[:menu_items_attributes].each { |_, atts| atts[:menuable_type] = 'Effective::Page' if atts[:menuable_type].blank? }
26
- menu.attributes = attributes
27
+ attributes[:menu_items_attributes].each do |_, atts|
28
+ atts[:menuable_type] = 'Effective::Page' if atts[:menuable_type].blank?
29
+ atts.delete(:id)
30
+ end
27
31
 
28
- # So when we render the menu, we don't include the Root/Home item.
29
- # It has a left of 1 and a right of max(items.right)
30
- right = attributes[:menu_items_attributes].map { |_, atts| atts[:rgt].to_i }.max
31
- menu.menu_items.find { |menu_item| menu_item.lft == 1 }.rgt = right + 1
32
+ menu.attributes = attributes
32
33
 
33
- menu.save!
34
+ # So when we render the menu, we don't include the Root/Home item.
35
+ # It has a left of 1 and a right of max(items.right)
36
+ right = attributes[:menu_items_attributes].map { |_, atts| atts[:rgt].to_i }.max
37
+
38
+ root_node = menu.menu_items.find { |menu_item| menu_item.lft == 1 }
39
+ root_node ||= menu.menu_items.build(:title => 'Home', :url => '/', :lft => 1, :rgt => 2)
40
+ root_node.rgt = right + 1
41
+
42
+ menu.save!
43
+ end
34
44
  end
35
45
  end
36
46
 
@@ -42,7 +52,7 @@ module Effective
42
52
  def build(&block)
43
53
  raise 'build must be called with a block' if !block_given?
44
54
 
45
- root = menu_items.build(:title => 'Home', :url => '#', :lft => 1, :rgt => 2)
55
+ root = menu_items.build(:title => 'Home', :url => '/', :lft => 1, :rgt => 2)
46
56
  root.parent = true
47
57
  instance_exec(&block) # A call to dropdown or item
48
58
  root.rgt = menu_items.map(&:rgt).max
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '0.9.7'.freeze
2
+ VERSION = '0.9.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect