Sha256: edcbfaf762c9888c7511c70c0a95cdf400fb562d2e0c8cb9328882adc815742a

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require 'thor'

module Padrino
  module Generators

    class Controller < Thor::Group

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

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

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

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

      argument :name, :desc => "The name of your padrino controller"
      argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
      class_option :root, :aliases => '-r', :default => nil, :type => :string
      class_option :destroy, :aliases => '-d', :default => false, :type => :boolean

      # Copies over the base sinatra starting project
      def create_controller
        if in_app_root?(options[:root])
          @app_name = fetch_app_name(options[:root])
          @actions = controller_actions(fields)
          self.behavior = :revoke if options[:destroy]
          inject_into_file app_root_path("config/urls.rb"), controller_routes(name,fields), :after => "urls do\n"
          template "templates/controller.rb.tt", app_root_path("app/controllers", "#{name}.rb")
          template "templates/helper.rb.tt",     app_root_path("app/helpers", "#{name}_helper.rb")
          empty_directory app_root_path("app/views/#{name}")
          include_component_module_for(:test, options[:root])
          generate_controller_test(name, options[:root] || '.')
        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.5.0 lib/padrino-gen/generators/controller.rb
padrino-gen-0.4.6 lib/padrino-gen/generators/controller.rb
padrino-gen-0.4.5 lib/padrino-gen/generators/controller.rb