Class: Alchemy::Generators::ElementsGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/rails/generators/alchemy/elements/elements_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_partialsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails/generators/alchemy/elements/elements_generator.rb', line 9

def create_partials
  @elements = load_alchemy_yaml('elements.yml')
  return unless @elements

  @elements.each do |element|
    @element = element
    @contents = element["contents"] || []
    if element["name"] =~ /\A[a-z0-9_-]+\z/
      @element_name = element["name"].underscore
    else
      raise "Element name '#{element['name']}' has wrong format. Only lowercase and non whitespace characters allowed."
    end

    conditional_template "editor.html.#{template_engine}", "#{elements_dir}/_#{@element_name}_editor.html.#{template_engine}"
    conditional_template "view.html.#{template_engine}", "#{elements_dir}/_#{@element_name}_view.html.#{template_engine}"
  end
end