Sha256: f689e22ae7ceea487a966926ce7637eb4c6a6bc152602fd353ce2925ffc1c265

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

require 'thor'

module Padrino
  module Generators

    class Mailer < Thor::Group

      # Add this generator to our padrino-gen
      Padrino::Generators.add_generator(:mailer, self)

      # Define the source template root
      def self.source_root; File.expand_path(File.dirname(__FILE__)); end
      def self.banner; "padrino-gen mailer [name]"; end

      # Include related modules
      include Thor::Actions
      include Padrino::Generators::Actions
      include Padrino::Generators::Components::Actions

      desc "Description:\n\n\tpadrino-gen mailer generates a new Padrino mailer"

      argument :name, :desc => "The name of your padrino mailer"
      class_option :root, :aliases => '-r', :default => nil, :type => :string

      # Copies over the base sinatra starting project
      def create_mailer
        if in_app_root?(options[:root])
          simple_name = name.to_s.gsub(/mailer/i, '')
          @mailer_basename = "#{simple_name.downcase.underscore}_mailer"
          @mailer_klass    = "#{simple_name.downcase.camelize}Mailer"
          template "templates/mailer_initializer.rb.tt", app_root_path("config/initializers/mailer.rb"), :skip => true
          template "templates/mailer.rb.tt", app_root_path("app/mailers", "#{@mailer_basename}.rb")
          empty_directory app_root_path('app/views/', @mailer_basename)
        else
          say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
        end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
padrino-gen-0.2.9 lib/padrino-gen/generators/mailer.rb
padrino-gen-0.2.6 lib/padrino-gen/generators/mailer.rb
padrino-gen-0.2.5 lib/padrino-gen/generators/mailer.rb