Sha256: fd25abc3a01126ad4b2726a7fc5d8cec273781d8e64d583d0b9e45a6aa053e6d

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 KB

Contents

# A cell is a group of elements that are rendered inside a specific area on your page_layout.
# Think of it like a column, or section in your layout. I.e. a header or right column.
# 
# Elements are displayed in tabs inside the elements window in page edit view.
# Every cell is a list of elements with the position scoped to +cell_id+ and +page_id+.
# 
# Define cells inside a +cells.yml+ file located in the +config/alchermy+ folder of your project.
# 
# Render cells with the +render_cell+ helper
# 
# Views for cells are inside the +app/views/cells+ folder in you project.
# 
class Cell < ActiveRecord::Base
  
  belongs_to :page
  has_many :elements, :dependent => :destroy, :order => :position
  
  def self.definitions
    cell_yml = File.join(Rails.root, 'config', 'alchemy', 'cells.yml')
    YAML.load_file(cell_yml) if File.exist?(cell_yml)
  end
  
  def self.definition_for(cellname)
    return nil if cellname.blank?
    definitions.detect { |c| c['name'] == cellname }
  end
  
  def self.all_definitions_for(cellnames)
    definitions.select { |c| cellnames.include? c['name'] }
  end
  
  def self.all_element_definitions_for(cellnames)
    element_names = []
    all_definitions_for(cellnames).each do |cell|
      element_names += cell['elements']
    end
    Element.all_definitions_for(element_names.uniq)
  end
  
  def self.definition_for_element(element_name)
    definitions_for_element(element_name).first
  end
  
  def self.definitions_for_element(element_name)
    return [] if definitions.blank?
    definitions.select { |d| d['elements'].include?(element_name) }
  end
  
  def self.name_for_element(element_name)
    definition = definition_for_element(element_name)
    return nil if definition.blank?
    definition['name']
  end
  
  def name_for_label
    self.class.translated_label_for(self.name)
  end
  
  def self.translated_label_for(cell_name)
    I18n.t("alchemy.cell_names.#{cell_name}", :default => cell_name.camelcase)
  end
  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
alchemy_cms-2.0 app/models/cell.rb
alchemy_cms-2.0.rc6 app/models/cell.rb
alchemy_cms-2.0.rc5 app/models/cell.rb
alchemy_cms-2.0.rc4 app/models/cell.rb
alchemy_cms-2.0.rc3 app/models/cell.rb
alchemy_cms-2.0.rc2 app/models/cell.rb
alchemy_cms-2.0.rc1 app/models/cell.rb
alchemy_cms-2.0.pre5 app/models/cell.rb
alchemy_cms-2.0.pre4 app/models/cell.rb
alchemy_cms-2.0.pre3 app/models/cell.rb
alchemy_cms-2.0.pre2 app/models/cell.rb