ordinary_cms 0.2.1 → 0.3.1

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: 6147aefcc03052efd7d81cbeec60cce328e33fe2
4
- data.tar.gz: 6e1603255fadaf7beb11e378ef9ca9fbaad19782
3
+ metadata.gz: de5c0a8f213c36b4fbd052230581ce452c434c78
4
+ data.tar.gz: ecf6071c5f1d2a4edae3afd9d2edc7377ec894f2
5
5
  SHA512:
6
- metadata.gz: 2c71c8e4076e2240351a0b1e2a9cd23754dde1284e3620fe9a7b4e5a8362bb310f6253f5d72f46fc006869928e6723eedecc2ffc5b1c311bd0240b5fcb73e300
7
- data.tar.gz: 1efad14dd7592dc8ef4c9c901e26b89aaac22751a09f1b959dde60ca59eaa3f8004194632562763552ef61ca1a320f701bf32b0cf20feafa4585b79538d761a5
6
+ metadata.gz: 4ead1963c7b4a75401af42f6f345f3ac3553bfa14e530b94fe36217e0e09dc3ee3c3da26f97329aa355d7a1e40b13327dd3248f53d199330afc8240bc82a5583
7
+ data.tar.gz: 4e910f9a2f4039b42e617c2ba0fef678cd7ff7581502d45ebdc285414380a811484a7b786d71dabd3657d5330fd4a3a1dafd6a563931deb6aaf88224dd06fb44
@@ -8,6 +8,14 @@ ActiveAdmin.register OrdinaryCms::Page do
8
8
  redirect_to :back
9
9
  end
10
10
 
11
+ controller do
12
+ protected
13
+ def build_resource
14
+ return super if params[:ordinary_cms_page].blank? || params[:ordinary_cms_page][:factory_id].blank?
15
+ factory = OrdinaryCms::Factories::Page.find params[:ordinary_cms_page].delete(:factory_id)
16
+ factory.build resource_params.first
17
+ end
18
+ end
11
19
 
12
20
  index do
13
21
  selectable_column
@@ -25,6 +33,7 @@ ActiveAdmin.register OrdinaryCms::Page do
25
33
  form do |f|
26
34
  f.inputs do
27
35
  f.input :name
36
+ f.input :factory, as: :select, collection: OrdinaryCms::Factories::Page.all.collect {|f| [f.name,f.id]}
28
37
  f.has_many :sections, allow_destroy: true do |section|
29
38
  section.input :name
30
39
  section.input :alias
@@ -0,0 +1,18 @@
1
+ module OrdinaryCms
2
+ module Factories
3
+ class Page
4
+ include Mongoid::Document
5
+
6
+ field :name
7
+
8
+ embeds_many :sections, class_name: 'OrdinaryCms::Factories::Section'
9
+ validates :name, presence: true, uniqueness: true
10
+
11
+ def build(params = {})
12
+ page = OrdinaryCms::Page.new params
13
+ sections.each {|s| page.sections << s.build}
14
+ page
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module OrdinaryCms
2
+ module Factories
3
+ class Section
4
+ include Mongoid::Document
5
+
6
+ field :name
7
+ field :alias
8
+
9
+ embedded_in :ordinary_cms_factories_page
10
+
11
+ validates :name, presence: true, uniqueness: true
12
+
13
+ def build
14
+ OrdinaryCms::Section.new name: name, alias: self.alias
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,6 +5,8 @@ module OrdinaryCms
5
5
 
6
6
  field :root, type: Boolean, default: false
7
7
 
8
+ belongs_to :factory, class_name: 'OrdinaryCms::Factories::Page'
9
+
8
10
  embeds_many :sections, class_name: 'OrdinaryCms::Section'
9
11
  accepts_nested_attributes_for :sections
10
12
 
@@ -16,5 +18,13 @@ module OrdinaryCms
16
18
  Page.where(root: true).update_all root: false
17
19
  self.update_attributes! root: true
18
20
  end
21
+
22
+ def matches?(factory)
23
+ raise ArgumentError, 'Argument is not OrdinaryCms::Factories::Page' unless factory.is_a? Factories::Page
24
+ factory.sections.each do |s|
25
+ return false if self.sections.where(name: s.name).empty?
26
+ end
27
+ true
28
+ end
19
29
  end
20
30
  end
@@ -1,3 +1,3 @@
1
1
  module OrdinaryCms
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordinary_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - max-konin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-19 00:00:00.000000000 Z
11
+ date: 2014-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,6 +100,8 @@ files:
100
100
  - app/controllers/ordinary_cms/root_controller.rb
101
101
  - app/helpers/ordinary_cms/application_helper.rb
102
102
  - app/helpers/ordinary_cms/pages_helper.rb
103
+ - app/models/ordinary_cms/factories/page.rb
104
+ - app/models/ordinary_cms/factories/section.rb
103
105
  - app/models/ordinary_cms/page.rb
104
106
  - app/models/ordinary_cms/section.rb
105
107
  - app/views/layouts/ordinary_cms/application.html.erb