Sha256: 6424f08f91c1d42dd4cb47cc2da4f2a814f8a2d7bd04200df0130e862b95452d

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

module Padrino
  module Generators

    DEV_PATH = File.expand_path("../../../", File.dirname(__FILE__))

    class << self
      def load_paths
        @load_paths ||= Dir[File.dirname(__FILE__) + '/generators/{project,app,mailer,controller,model,migration}.rb']
      end

      def mappings
        @mappings ||= SupportLite::OrderedHash.new
      end

      def add_generator(name, klass)
        mappings[name] = klass
      end

      def setup!
        require 'padrino-gen/generators/actions'
        Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
      end

      def lockup!
        load_paths.each { |lib| require lib  }
      end
    end

    class Cli < Thor::Group

      # Include related modules
      include Thor::Actions

      class_option :root, :desc => "The root destination", :aliases => '-r', :default => nil, :type => :string

      # We need to TRY to load boot because some of our app dependencies maybe have 
      # custom generators, so is necessary know who are.
      def load_boot
        Padrino::Generators.setup!

        begin
          ENV['PADRINO_LOG_LEVEL'] ||= "test"
          if options[:root]
            require File.join(options[:root], 'config/boot.rb') if File.exist?(File.join(options[:root], 'config/boot.rb'))
          else
            require 'config/boot.rb' if File.exist?('config/boot.rb')
          end
        rescue Exception => e
          puts "=> Problem loading config/boot.rb"
        end
      end

      def setup
        Padrino::Generators.lockup!

        generator_kind  = ARGV.delete_at(0).to_s.downcase.to_sym if ARGV[0].present?
        generator_class = Padrino::Generators.mappings[generator_kind]

        if generator_class
          generator_class.start(ARGV)
        else
          puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
        end
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
padrino-gen-0.8.1 lib/padrino-gen/generators.rb
padrino-gen-0.8.0 lib/padrino-gen/generators.rb