Sha256: dbb01dcbe0622da19db50fcd26f65524afd889794a9ac5b3f25516a44cfd96b3

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require File.join(__FILE__, '../../base')

module Alchemy
  module Generators
    class ElementsGenerator < Base
      desc "This generator generates your elements view partials."
      source_root File.expand_path('templates', File.dirname(__FILE__))

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

      def create_partials
        @elements = load_alchemy_yaml('elements.yml')
        @elements.each do |element|
          @element = element
          if @element['available_contents']
            @available_contents_names = @element['available_contents'].collect { |c| c['name'] }
            @contents = (element["contents"].delete_if { |c| @available_contents_names.include?(c['name']) } or [])
          else
            @contents = (element["contents"] or [])
          end
          @element_name = element["name"].underscore

          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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-2.4.1 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-2.4.0 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-2.4.rc4 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-2.4.rc2 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-2.4.rc1 lib/rails/generators/alchemy/elements/elements_generator.rb