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_directoryObject



9
10
11
12
# File 'lib/rails/generators/alchemy/elements/elements_generator.rb', line 9

def create_directory
  @elements_dir = "#{Rails.root}/app/views/alchemy/elements"
  empty_directory @elements_dir
end

#create_partialsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails/generators/alchemy/elements/elements_generator.rb', line 14

def create_partials
  @elements = load_alchemy_yaml('elements.yml')
  @elements.each do |element|
    @element = element
    contents = element["contents"] || []
    if @element['available_contents']
      @available_contents_names = @element['available_contents'].collect { |c| c['name'] }
      @contents = contents.delete_if { |c| @available_contents_names.include?(c['name']) } or []
    else
      @contents = contents
    end
    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 if @elements
end