Sha256: 979609620becc24b0cdaa4ee89dd432b50a5a220783dab37ccc24451ae830653

Contents?: true

Size: 1.48 KB

Versions: 36

Compression:

Stored size: 1.48 KB

Contents

require 'rails'

module Alchemy
  module Generators
    class Base < ::Rails::Generators::Base
      class_option :template_engine, type: :string, aliases: '-e', desc: 'Template engine for the views. Available options are "erb", "haml", and "slim".'

      private

      def conditional_template(source, destination)
        files = Dir.glob(destination.gsub(/\.([a-z]+)$/, '*'))
        if files.any?
          ext = File.extname(files.first)[1..-1]

          # If view already exists using a different template engine, change
          # source and destination file names to use that engine.
          if ext != template_engine.to_s
            say_status :warning, "View uses unexpected template engine '#{ext}'.", :cyan
            destination.gsub!(/#{template_engine}$/, ext)
            source.gsub!(/#{template_engine}$/, ext)
          end
        end

        template source, destination
      end

      def template_engine
        # Rails is clever enough to default this to whatever template
        # engine is configured through its generator configuration,
        # but we'll default it to erb anyway, just in case.
        options[:template_engine] || 'erb'
      end

      def load_alchemy_yaml(name)
        YAML.safe_load(ERB.new(File.read("#{Rails.root}/config/alchemy/#{name}")).result, YAML_WHITELIST_CLASSES, [], true)
      rescue Errno::ENOENT
        puts "\nERROR: Could not read config/alchemy/#{name} file. Please run: `rails generate alchemy:install`"
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.6 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.5 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.5.1 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.4.5 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.4 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.0.6 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.3 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.2 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.1 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.6.0 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.5.0 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.4.4 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.4.3 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.4.2 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.4.1 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.4.0 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.3.2 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.2.4 lib/rails/generators/alchemy/base.rb
alchemy_cms-4.3.1 lib/rails/generators/alchemy/base.rb