Class: NoCms::Blocks::Block

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Concerns::SerializingFields, Concerns::TranslationScopes
Defined in:
app/models/no_cms/blocks/block.rb

Defined Under Namespace

Classes: Translation

Instance Method Summary collapse

Instance Method Details

#css_filesObject

It returns an array of arrays with the css path and the mediaquery for each css template configured



29
30
31
32
33
34
35
36
# File 'app/models/no_cms/blocks/block.rb', line 29

def css_files
  css_templates = layout_config.css_templates || []
  css_templates.map do |css_template|
    media_type = css_template.split("_").last.to_sym
    media_query = NoCms::Blocks.css_mediaqueries[media_type]
    ["#{NoCms::Blocks.css_blocks_folder}/#{self.layout}/#{css_template}", media_query]
  end
end

#duplicate_self(new_self) ⇒ Object

A block dups all it’s children and the translations



44
45
46
47
48
49
50
51
52
# File 'app/models/no_cms/blocks/block.rb', line 44

def duplicate_self new_self

  new_self.translations = translations.map(&:dup)
  new_self.translations.each { |t| t.globalized_model = new_self }

  children.each do |child|
    new_self.children << child.dup
  end
end

#fields_configurationObject

In the block we get all the fields so it can accept all of them



22
23
24
# File 'app/models/no_cms/blocks/block.rb', line 22

def fields_configuration
  layout_config.fields
end

#to_admin_partial_pathObject

Method that will define wich partial is used for the block in the admin views. It uses the engine configuration to read the partials folder and then add the block template



125
126
127
# File 'app/models/no_cms/blocks/block.rb', line 125

def to_admin_partial_path
  "#{NoCms::Blocks.admin_partials_folder}/#{self.template}"
end

#to_partial_pathObject

Method that will define wich partial is used in the public views. It uses the engine configuration to read the partials folder and then add the block template



117
118
119
# File 'app/models/no_cms/blocks/block.rb', line 117

def to_partial_path
  "#{NoCms::Blocks.front_partials_folder}/#{self.template}"
end

#to_skeleton_pathObject

Method that will define skeleton path in the public views It uses the engine configuration to read the partials folder and then add the skeleton template



134
135
136
# File 'app/models/no_cms/blocks/block.rb', line 134

def to_skeleton_path
  "#{NoCms::Blocks.front_skeletons_folder}/#{layout_config.skeleton_template}"
end