Sha256: 061a98c3343574b450805f07351a291252c75252582ef744b68d4eca9d277243

Contents?: true

Size: 1.97 KB

Versions: 87

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true
require "rails"

module Alchemy
  module Generators
    class EssenceGenerator < ::Rails::Generators::Base
      desc "This generator generates an Alchemy essence for you."
      argument :essence_name, banner: "YourEssenceName"
      source_root File.expand_path("templates", __dir__)

      def init
        @essence_name = essence_name.underscore
        @essence_view_path = "app/views/alchemy/essences"
      end

      def create_model
        invoke("model", [@essence_name])
      end

      def act_as_essence
        essence_class_file = "app/models/#{@essence_name}.rb"
        essence_class = @essence_name.classify
        inject_into_class essence_class_file, essence_class, <<~CLASSMETHOD
          acts_as_essence(
            # Your options:
            #
            # ingredient_column:   [String or Symbol] - Specifies the column name you use for storing the content in the database. (Default :body)
            # validate_column:     [String or Symbol] - Which column should be validated. (Default: ingredient_column)
            # preview_text_column: [String or Symbol] - Specifies the column for the preview_text method. (Default: ingredient_column)
            # preview_text_method: [String or Symbol] - A method called on ingredient to get the preview text. (Default: ingredient_column)
          )
        CLASSMETHOD
      end

      def copy_templates
        essence_name = @essence_name.classify.demodulize.underscore
        @essence_editor_local = "#{essence_name}_editor"
        template "view.html.erb", "#{@essence_view_path}/_#{essence_name}_view.html.erb"
        template "editor.html.erb", "#{@essence_view_path}/_#{essence_name}_editor.html.erb"
      end

      def show_todo
        say "\nPlease open the generated migration file and add your columns to your table."
        say "Then run 'rake db:migrate' to update your database."
        say "Also check the generated view files and alter them to fit your needs."
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
alchemy_cms-6.1.10 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.9 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.8 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.7 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.6 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.5 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.14 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.4 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.13 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.3 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.2 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.1 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.1.0 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.12 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.11 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.10 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-5.3.8 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.9 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-5.3.7 lib/generators/alchemy/essence/essence_generator.rb
alchemy_cms-6.0.8 lib/generators/alchemy/essence/essence_generator.rb