Sha256: 3cd4d7c8b25270fa869b7b49573ac06ab0306fa22d63a427bc3183cdbc30c7d9

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require "generators/kiso_themes/handler_support"

module KisoThemes
  module Generators
    class EmailLayoutGenerator < Rails::Generators::Base
      include HandlerSupport

      source_root File.expand_path('../templates', __FILE__)

      namespace "kiso_themes:email_layout"
      desc "Copy KisoThemes's custom Email templates to your project."

      def copy_layouts
        abort "You must create a mailer first" and return unless mailer?
        copy_file "views/emails/_email_header.html.#{handler}", "app/views/emails/_email_header.html.#{handler}"
        copy_file "views/emails/_email_footer.html.#{handler}", "app/views/emails/_email_footer.html.#{handler}"
      end

      def add_helpers

        code = <<-INJECTEDCODE

  add_template_helper EmailTemplateHelper
  include Rails.application.routes.url_helpers
  include ActionView::Helpers::UrlHelper
INJECTEDCODE

        inject_into_file( "app/mailers/application_mailer.rb", code, :after => /^class ApplicationMailer < ActionMailer::Base/)

        gsub_file 'app/mailers/application_mailer.rb', 'mailer', 'email'
      end

      protected

      def mailer?
        File.file?('app/mailers/application_mailer.rb')
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kiso_themes-1.0.2 lib/generators/kiso_themes/email_layout_generator.rb