Class: Padrino::Generators::Controller

### Home Classes Methods

### In Files

- lib/padrino-gen/generators/controller.rb

### Parent

Thor::Group

### Methods

- ::banner
- ::source_root
- #create_controller

### Included Modules

- Thor::Actions
- Padrino::Generators::Actions
- Padrino::Generators::Components::Actions

### Files

- README.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Generators
- Padrino::Generators::Actions
- Padrino::Generators::Actions::ClassMethods
- Padrino::Generators::App
- Padrino::Generators::AppRootNotFound
- Padrino::Generators::Cli
- Padrino::Generators::Component
- Padrino::Generators::Components
- Padrino::Generators::Components::Actions
- Padrino::Generators::Controller
- Padrino::Generators::Helper
- Padrino::Generators::Mailer
- Padrino::Generators::Migration
- Padrino::Generators::Model
- Padrino::Generators::Plugin
- Padrino::Generators::Project
- Padrino::Generators::Runner
- Padrino::Generators::SqlHelpers
- Padrino::Generators::Task
- ActiveRecord
- ActiveRecord::Schema
- Object

No matching classes.

# Padrino::Generators::Controller

Responsible for generating route controllers and associated tests within a Padrino application.

### Public Class Methods

banner() click to toggle source

    # File lib/padrino-gen/generators/controller.rb, line 13
    def self.banner; "padrino-gen controller [name]"; end

source_root() click to toggle source

    # File lib/padrino-gen/generators/controller.rb, line 12
    def self.source_root; File.expand_path(File.dirname(__FILE__)); end

### Public Instance Methods

create_controller() click to toggle source

Execute controller generation

    # File lib/padrino-gen/generators/controller.rb, line 38
    def create_controller
      self.destination_root = options[:root]
      if in_app_root?
        app = options[:app]
        check_app_existence(app)
        @project_name = options[:namespace].underscore.camelize
        @project_name = fetch_project_name(app) if @project_name.empty?
        @app_name     = fetch_app_name(app)
        @actions      = controller_actions(fields)
        @controller   = name.to_s.underscore
        @layout       = options[:layout] if options[:layout] && !options[:layout].empty?

        block_opts = []
        block_opts << ":parent => :#{options[:parent]}" if options[:parent] && !options[:parent].empty?
        block_opts << ":provides => [#{options[:provides]}]" if options[:provides] && !options[:provides].empty?
        @block_opts_string = block_opts.join(', ') unless block_opts.empty?

        self.behavior = :revoke if options[:destroy]
        template 'templates/controller.rb.tt', destination_root(app, 'controllers', "#{name.to_s.underscore}.rb")
        empty_directory destination_root(app, "/views/#{name.to_s.underscore}")

        if test?
          include_component_module_for(:test)
          path = @controller.dup

          if options[:parent] && !options[:parent].empty?
            path = Application.process_path_for_parent_params(path, [options[:parent]]).prepend("/")
          end
          path.prepend("/") unless path.start_with?("/")
          generate_controller_test(name, path)
        end

        create_helper_files(app, name) unless options[:'no-helper']
      else
        say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.