Sha256: 16d06e442c2d69cafb32d6cd0972a217e6a5270d2c6379e0c716b3eb559a12a0

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

require 'rails/generators'

module Inky
  module Generators
    class InstallGenerator < ::Rails::Generators::Base
      desc 'Install Foundation for Emails'
      source_root File.join(File.dirname(__FILE__), 'templates')
      argument :layout_name, type: :string, default: 'mailer', banner: 'layout_name'

      class_option :haml, desc: "Generate layout in Haml", type: :boolean
      class_option :slim, desc: "Generate layout in Slim", type: :boolean

      def preserve_original_mailer_layout
        return unless layout_name == 'mailer' && extension == 'erb'

        original_mailer = File.join(layouts_base_dir, "mailer.html.erb")
        rename_filename = File.join(layouts_base_dir, "old_mailer_#{Time.now.to_i}.html.erb")
        File.rename(original_mailer, rename_filename) if File.exist? original_mailer
      end

      def create_mailer_stylesheet
        template 'foundation_emails.scss', File.join(stylesheets_base_dir, 'foundation_emails.scss')
      end

      def create_mailer_layout
        template "mailer_layout.html.#{extension}", File.join(layouts_base_dir, "#{layout_name.underscore}.html.#{extension}")
      end

      private

      def stylesheets_base_dir
        File.join('app', 'assets', 'stylesheets')
      end

      def layouts_base_dir
        File.join('app', 'views', 'layouts')
      end

      def extension
        %w(haml slim).each do |ext|
          return ext if options.send(ext)
        end
        'erb'
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inky-rb-1.4.2.1 lib/generators/inky/install_generator.rb
inky-rb-1.4.2.0 lib/generators/inky/install_generator.rb
inky-rb-1.3.8.0 lib/generators/inky/install_generator.rb
inky-rb-1.3.7.5 lib/generators/inky/install_generator.rb
inky-rb-1.3.7.4 lib/generators/inky/install_generator.rb
inky-rb-1.3.7.3 lib/generators/inky/install_generator.rb