Module: ContentsCore

Defined in:
app/models/contents_core/item_object.rb,
lib/contents_core.rb,
lib/contents_core/blocks.rb,
lib/contents_core/engine.rb,
lib/contents_core/version.rb,
app/models/contents_core/item.rb,
app/models/contents_core/block.rb,
app/models/contents_core/item_file.rb,
app/models/contents_core/item_hash.rb,
app/models/contents_core/item_text.rb,
app/models/contents_core/item_array.rb,
app/models/contents_core/item_float.rb,
app/models/contents_core/item_string.rb,
app/models/contents_core/item_boolean.rb,
app/models/contents_core/item_integer.rb,
app/models/contents_core/item_datetime.rb,
app/models/contents_core/application_record.rb

Overview

TODO: needs improvements

Defined Under Namespace

Modules: Blocks Classes: ApplicationRecord, Block, Engine, Item, ItemArray, ItemBoolean, ItemDatetime, ItemFile, ItemFloat, ItemHash, ItemInteger, ItemObject, ItemString, ItemText

Constant Summary collapse

VERSION =
'0.3.2'

Class Method Summary collapse

Class Method Details

.config(options = {}) ⇒ Object



5
6
7
8
# File 'lib/contents_core.rb', line 5

def self.config( options = {} )
  @@config.merge! options
  @@config
end

.create_block_in_parent(parent, type = :text, params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/contents_core.rb', line 10

def self.create_block_in_parent( parent, type = :text, params = {} )
  block = Block.new( block_type: type )
  block.name = params[:name] if params[:name]
  block.conf = params[:conf] if params[:conf]
  # block.validations = params[:validations] if params[:validations]
  block.create_children = params[:create_children].to_i if params[:create_children]
  parent.cc_blocks << block  # TODO: change me (with cc_blocks.new)
  Block::initialize_children block, params[:schema], {create_children: params[:create_children]} if params[:schema]
  if params[:values]
    traverse_hash block.tree, params[:values]
    block.save
  elsif params[:values_list]
    params[:values_list].each{ |k, v| block.set k.to_s, v }
    block.save
  end
  block
end

.editing(editing = nil) ⇒ Object



28
29
30
31
# File 'lib/contents_core.rb', line 28

def self.editing( editing = nil )
  @@editing = editing unless editing.nil?
  @@editing
end

.traverse_hash(hash, values) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/contents_core.rb', line 33

def self.traverse_hash( hash, values )
  ret = {}
  values.each do |k, v|
    if v.is_a? Hash
      ret = traverse_hash hash[k.to_s], values[k]
    else
      hash[k.to_s].data = values[k]
    end
  end
  ret
end