Sha256: 567f60090f3c8e038a0cd7cd561da9158b9c9b6a63dc8ff1e70eb8c6cc3eb91a

Contents?: true

Size: 1.06 KB

Versions: 48

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
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"] || []
          @element_name = element_name(element)
          conditional_template "view.html.#{template_engine}", "#{elements_dir}/_#{@element_name}.html.#{template_engine}"
        end
      end

      private

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

      def element_name(element)
        if element["name"] =~ Alchemy::Element::NAME_REGEXP
          element["name"].underscore
        else
          raise "Element name '#{element["name"]}' has wrong format. Only lowercase and non whitespace characters allowed."
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
alchemy_cms-5.3.8 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.7 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.6 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.5 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.4 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.3 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.2 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.1 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.3.0 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.2.7 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.2.6 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.1.10 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.0.10 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.2.5 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.1.9 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.0.9 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.2.4 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.1.8 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.0.8 lib/generators/alchemy/elements/elements_generator.rb
alchemy_cms-5.0.7 lib/generators/alchemy/elements/elements_generator.rb