contents_core 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/models/contents_core/block.rb +27 -3
- data/app/models/contents_core/item.rb +4 -0
- data/app/models/contents_core/{item_enum.rb → item_array.rb} +3 -3
- data/config/initializers/contents_core.rb +1 -1
- data/db/migrate/20170414173611_add_extra_items.rb +1 -1
- data/lib/contents_core.rb +10 -0
- data/lib/contents_core/blocks.rb +1 -7
- data/lib/contents_core/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da496467b39f33f60cba8e1ce3356a83cf26f804
|
4
|
+
data.tar.gz: a81d0b06211ffaf5c3aa262fd82167c9e88f88ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47c86fbecb6193acb88816373765193d7c60cf68ae81ca4ae781675d9b27794ed58b617fb733d32cd70ba7ab3f4d5cd25e106288d5698c23c1a5dcd897c9511e
|
7
|
+
data.tar.gz: 3dd11bae3f087cf3ad7d6569c6387d5c3aa57240bda029b7cb1b97945974c1979f74de165eed0e8384340b0cb8111c2f6292bd361e1619db3869335be1be4945
|
data/README.md
CHANGED
@@ -104,7 +104,7 @@ To set a field value: `block.set( 'new-field', 'Some value' )`
|
|
104
104
|
|
105
105
|
#### ActiveAdmin
|
106
106
|
|
107
|
-
If you use ActiveAdmin as admin interface you can find a sample model configuration [
|
107
|
+
If you use ActiveAdmin as admin interface you can find a sample model configuration: [page](extra/active_admin_page.rb) plus a js [page](extra/active_admin.js)
|
108
108
|
|
109
109
|
### Notes
|
110
110
|
|
@@ -51,10 +51,25 @@ module ContentsCore
|
|
51
51
|
#
|
52
52
|
# # scope :published, -> { where( published: true ) unless ApplicationController.edit_mode }
|
53
53
|
|
54
|
+
def initialize( params = {} )
|
55
|
+
super
|
56
|
+
self.group = config[:group]
|
57
|
+
self.block_type = parent.config[:children_type] if params[:block_type].nil? && self.parent_type == 'ContentsCore::Block'
|
58
|
+
end
|
59
|
+
|
60
|
+
def as_json
|
61
|
+
# binding.pry
|
62
|
+
super({ only: [:id, :block_type, :name, :group, :position, :published], methods: [:blocks_collection, :items_collection]}.merge(options || {}))
|
63
|
+
end
|
64
|
+
|
54
65
|
def attr_id
|
55
66
|
"#{self.class.to_s.split('::').last}-#{self.id}"
|
56
67
|
end
|
57
68
|
|
69
|
+
def blocks_collection
|
70
|
+
self.cc_blocks.map &:as_json
|
71
|
+
end
|
72
|
+
|
58
73
|
def children_type
|
59
74
|
config[:children_type]
|
60
75
|
end
|
@@ -86,11 +101,16 @@ module ContentsCore
|
|
86
101
|
|
87
102
|
# Returns an item by name
|
88
103
|
def get( name )
|
104
|
+
item = get_item( name )
|
105
|
+
item.data if item
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_item( name )
|
89
109
|
unless @_items
|
90
110
|
@_items = {}
|
91
111
|
items.each { |item| @_items[item.name] = item }
|
92
112
|
end
|
93
|
-
@_items[name]
|
113
|
+
@_items[name]
|
94
114
|
end
|
95
115
|
|
96
116
|
def has_parent?
|
@@ -105,6 +125,10 @@ module ContentsCore
|
|
105
125
|
parent.present? && parent_type == 'ContentsCore::Block'
|
106
126
|
end
|
107
127
|
|
128
|
+
def items_collection
|
129
|
+
self.items.map &:as_json
|
130
|
+
end
|
131
|
+
|
108
132
|
def on_after_create
|
109
133
|
# TODO: validates type before creation!
|
110
134
|
Block::init_items( self, config[:items] ) if Block::block_types.include?( self.block_type.to_sym )
|
@@ -161,7 +185,7 @@ module ContentsCore
|
|
161
185
|
end
|
162
186
|
|
163
187
|
def self.block_list
|
164
|
-
@@block_list ||= ContentsCore.config[:cc_blocks].map{|k, v| [v[:name], k.to_s]}.sort_by{|b| b[0]}
|
188
|
+
@@block_list ||= ContentsCore.config[:cc_blocks].map{|k, v| [v[:name], k.to_s] unless v[:child_only]}.compact.sort_by{|b| b[0]}
|
165
189
|
end
|
166
190
|
|
167
191
|
def self.block_types
|
@@ -191,7 +215,7 @@ module ContentsCore
|
|
191
215
|
end
|
192
216
|
|
193
217
|
def config
|
194
|
-
|
218
|
+
ContentsCore.config[:cc_blocks][block_type.to_sym] ? ContentsCore.config[:cc_blocks][block_type.to_sym] : {}
|
195
219
|
end
|
196
220
|
end
|
197
221
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ContentsCore
|
2
|
-
class
|
2
|
+
class ItemArray < Item
|
3
3
|
alias_attribute :data, :data_string
|
4
4
|
|
5
5
|
serialize :data_hash, Array
|
6
6
|
|
7
7
|
def enum
|
8
|
-
config[:values] ? config[:values] : self.data_hash
|
8
|
+
config[:values] ? config[:values] : ( config[:values_method] ? config[:values_method].call : self.data_hash )
|
9
9
|
end
|
10
10
|
|
11
11
|
def init
|
@@ -22,7 +22,7 @@ module ContentsCore
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.type_name
|
25
|
-
'
|
25
|
+
'array'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -4,7 +4,7 @@ class AddExtraItems < ActiveRecord::Migration[5.0]
|
|
4
4
|
add_column :contents_core_items, :data_datetime, :datetime
|
5
5
|
add_column :contents_core_items, :data_file, :string # , null: false, default: ''
|
6
6
|
add_column :contents_core_items, :data_float, :float
|
7
|
-
add_column :contents_core_items, :data_hash, :
|
7
|
+
add_column :contents_core_items, :data_hash, :text # , null: false, default: ''
|
8
8
|
add_column :contents_core_items, :data_integer, :integer
|
9
9
|
add_column :contents_core_items, :data_string, :string # , null: false, default: ''
|
10
10
|
add_column :contents_core_items, :data_text, :text
|
data/lib/contents_core.rb
CHANGED
@@ -7,6 +7,16 @@ module ContentsCore
|
|
7
7
|
@@config
|
8
8
|
end
|
9
9
|
|
10
|
+
def self.create_block_in_parent( parent, type = :text, params = {} )
|
11
|
+
block = Block.new( block_type: type )
|
12
|
+
block.name = params[:name] if params[:name]
|
13
|
+
block.options = params[:options] if params[:options]
|
14
|
+
block.validations = params[:validations] if params[:validations]
|
15
|
+
parent.cc_blocks << block
|
16
|
+
Block::init_items block, params[:schema] if params[:schema]
|
17
|
+
block
|
18
|
+
end
|
19
|
+
|
10
20
|
def self.editing( editing = nil )
|
11
21
|
@@editing = editing unless editing.nil?
|
12
22
|
@@editing
|
data/lib/contents_core/blocks.rb
CHANGED
@@ -8,13 +8,7 @@ module ContentsCore
|
|
8
8
|
accepts_nested_attributes_for :cc_blocks, allow_destroy: true
|
9
9
|
|
10
10
|
def create_block( type = :text, params = {} )
|
11
|
-
|
12
|
-
block.name = params[:name] if params[:name]
|
13
|
-
block.options = params[:options] if params[:options]
|
14
|
-
block.validations = params[:validations] if params[:validations]
|
15
|
-
cc_blocks << block
|
16
|
-
Block::init_items block, params[:schema] if params[:schema]
|
17
|
-
block
|
11
|
+
ContentsCore::create_block_in_parent( self, type, params )
|
18
12
|
end
|
19
13
|
|
20
14
|
def current_blocks( version = 0 )
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contents_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,9 +38,9 @@ files:
|
|
38
38
|
- app/models/contents_core/application_record.rb
|
39
39
|
- app/models/contents_core/block.rb
|
40
40
|
- app/models/contents_core/item.rb
|
41
|
+
- app/models/contents_core/item_array.rb
|
41
42
|
- app/models/contents_core/item_boolean.rb
|
42
43
|
- app/models/contents_core/item_datetime.rb
|
43
|
-
- app/models/contents_core/item_enum.rb
|
44
44
|
- app/models/contents_core/item_file.rb
|
45
45
|
- app/models/contents_core/item_float.rb
|
46
46
|
- app/models/contents_core/item_hash.rb
|