Sha256: e5840d1904f821ae07298883bd6c848b671a7b24f413e19fae3cabfc0e7ad80f
Contents?: true
Size: 1.45 KB
Versions: 13
Compression:
Stored size: 1.45 KB
Contents
module Alchemy # Module concerning element definitions # module Element::Definitions extend ActiveSupport::Concern module ClassMethods # Returns the definitions from elements.yml file. # # Place a +elements.yml+ file inside your apps +config/alchemy+ folder to define # your own set of elements # def definitions @definitions ||= read_definitions_file end # Returns one element definition by given name. # def definition_by_name(name) definitions.detect { |d| d['name'] == name } end private # Reads the element definitions file named +elements.yml+ from +config/alchemy/+ folder. # def read_definitions_file if ::File.exist?(definitions_file_path) ::YAML.load(ERB.new(File.read(definitions_file_path)).result) || [] else raise LoadError, "Could not find elements.yml file! Please run `rails generate alchemy:scaffold`" end end # Returns the +elements.yml+ file path # def definitions_file_path Rails.root.join 'config/alchemy/elements.yml' end end # The definition of this element. # def definition if definition = self.class.definitions.detect { |d| d['name'] == name } definition else log_warning "Could not find element definition for #{name}. Please check your elements.yml file!" return {} end end end end
Version data entries
13 entries across 13 versions & 1 rubygems