Sha256: 57ea2b1d013e07855bb997d9d953d7d2c8d502b55b683e9aaef109777d75758f

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require_relative '../base'

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

      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

      private

      def elements_dir
        @_elements_dir ||= "app/views/alchemy/elements"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-4.1.2 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-4.1.1 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-4.1.0 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-4.1.0.rc1 lib/rails/generators/alchemy/elements/elements_generator.rb
alchemy_cms-4.1.0.beta lib/rails/generators/alchemy/elements/elements_generator.rb