contents_core 0.1.4 → 0.1.5

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: e7d1b8b264e340a66ef666f3531ba77ab6c30738
4
- data.tar.gz: 5cc9fd8dc12f6e30fe17ebdbf727e8ba8d861d8c
3
+ metadata.gz: a3e790025ed4a3222f501a20371d24c9d0673f89
4
+ data.tar.gz: a6d988af5c4e27072651a2f3a05d7dc8bacd15a2
5
5
  SHA512:
6
- metadata.gz: 8345f87ea98574cabc250b958cf80a828553f2f34475ffd060100de9763a897bd20cfaa22d85d32fc35557e4cefd1e5bd3e393c346eb047ff00a9775d51024f7
7
- data.tar.gz: 8f66cfbfa1cb4faad0976dce1aca8958c536134469e39228701cf2c5c7038406589c7814fcf18935ea274a54b679e06f78808e1c597cd157a3ed6343f71565c2
6
+ metadata.gz: db8bdfec13a651a08b5c09f89fbf3138745c23b7c531f78e539e1866cfb1fdd6c5f8d8401cc24415444d6bf93a1fc92dfcf01e84345a2cb75ebab175047be305
7
+ data.tar.gz: e237083b259321327d439fa1d3c026abab3d19a3ce438b856998d7a0be2095e84b39004bfc41062ea9c4ad00478465a2530c0d2a6d24b566256f05dc704a1b4d
data/README.md CHANGED
@@ -91,19 +91,34 @@ module ContentsCore
91
91
  end
92
92
  ```
93
93
 
94
- #### Custom blocks
94
+ #### Customizations
95
95
 
96
96
  To create a "free form" block just use: `Page.first.create_block :intro, name: 'IntroBlock', schema: { intro: :item_string, subtitle: :item_string }`
97
97
 
98
98
  Then create a *app/view/contents_core/_block_intro* view.
99
99
 
100
- ### Dev Notes
100
+ To list the blocks of a page: `Page.first.cc_blocks.pluck :name`
101
+
102
+ To add a new field to an existing block (ex. to first Page, on the first Block):
103
+
104
+ ```rb
105
+ block = Page.first.get_block 'text-1'
106
+ block.create_item( 'ContentsCore::ItemString', 'test-1' ).set( 'A test...' ).save
107
+ ```
108
+
109
+ Then add to the block view: `block.get( 'new-field' )`
110
+
111
+ ### Notes
112
+
113
+ - Blocks types: `ContentsCore::Block.block_types`
114
+
115
+ - Default blocks [here](https://github.com/blocknotes/contents_core/blob/master/config/initializers/contents_core.rb)
101
116
 
102
117
  #### Structure
103
118
 
104
- - Including the Editable concern to a model will add `has_many :ec_blocks` relationship (the list of blocks attached to a container) and some utility methods
119
+ - Including the Blocks concern to a model will add `has_many :cc_blocks` relationship (the list of blocks attached to a container) and some utility methods
105
120
 
106
- - Block: an editable UI component (ex. a text with a title, a slider, a 3 column text widgets, etc.); built with a list of sub blocks (for nested components) and a list of items
121
+ - Block: UI component, a group of items (ex. a text with a title, a slider, a 3 column text widgets, etc.); built with a list of sub blocks (for nested components) and a list of items
107
122
 
108
123
  - Item: a single piece of information (ex. a string, a text, a boolean, an integer, a file, etc.)
109
124
 
@@ -59,6 +59,13 @@ module ContentsCore
59
59
  ContentsCore.config[:cc_blocks][block_type.to_sym][:children_type]
60
60
  end
61
61
 
62
+ def create_item( item_type, item_name = nil )
63
+ new_item = ContentsCore::Item.new( type: item_type )
64
+ new_item.name = item_name if item_name
65
+ self.items << new_item
66
+ new_item
67
+ end
68
+
62
69
  def editable
63
70
  ContentsCore.editing ? (
64
71
  is_sub_block? ?
@@ -41,6 +41,11 @@ module ContentsCore
41
41
  @@item_types ||= ContentsCore.config[:items].keys.map &:to_s
42
42
  end
43
43
 
44
+ def set( value )
45
+ self.data = value
46
+ self
47
+ end
48
+
44
49
  protected
45
50
 
46
51
  def config
@@ -3,6 +3,12 @@ module ContentsCore
3
3
 
4
4
  @@config = {
5
5
  cc_blocks: {
6
+ image: {
7
+ name: 'Image block',
8
+ items: {
9
+ img: :item_file
10
+ }
11
+ },
6
12
  multi_text: {
7
13
  children_type: :text,
8
14
  name: 'Multi columns block',
@@ -10,6 +16,20 @@ module ContentsCore
10
16
  column: :text
11
17
  }
12
18
  },
19
+ slide: {
20
+ name: 'Slide block',
21
+ items: {
22
+ img: :item_file,
23
+ title: :item_string
24
+ }
25
+ },
26
+ slider: {
27
+ children_type: :slide,
28
+ name: 'Slider block',
29
+ items: {
30
+ slide: :slide
31
+ }
32
+ },
13
33
  text: {
14
34
  name: 'Text block',
15
35
  items: {
@@ -17,6 +37,14 @@ module ContentsCore
17
37
  content: :item_text
18
38
  }
19
39
  },
40
+ text_with_image: {
41
+ name: 'Text with image block',
42
+ items: {
43
+ img: :item_file,
44
+ title: :item_string,
45
+ content: :item_text
46
+ }
47
+ },
20
48
  },
21
49
  items: {
22
50
  boolean: {},
@@ -33,41 +61,4 @@ module ContentsCore
33
61
  },
34
62
  }
35
63
  }
36
-
37
- if defined? CarrierWave
38
- @@config[:cc_blocks].merge!({
39
- image: {
40
- name: 'Image block',
41
- items: {
42
- img: :item_file
43
- }
44
- },
45
- slide: {
46
- name: 'Slide block',
47
- items: {
48
- img: :item_file,
49
- title: :item_string
50
- }
51
- },
52
- slider: {
53
- children_type: :slide,
54
- name: 'Slider block',
55
- items: {
56
- slide: :slide
57
- }
58
- },
59
- text_with_image: {
60
- name: 'Text with image block',
61
- items: {
62
- img: :item_file,
63
- title: :item_string,
64
- content: :item_text
65
- }
66
- },
67
- })
68
-
69
- # ItemImage.class_eval do
70
- # mount_uploader :data, ImageUploader
71
- # end
72
- end
73
64
  end
@@ -1,3 +1,3 @@
1
1
  module ContentsCore
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contents_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat