Sha256: 024af8850b3d25b29bd9e06f6b94b1dca478b85291508f62b6a028825db72ac8

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

module Hobo
  class FrontControllerGenerator < Rails::Generators::NamedBase
    source_root File.expand_path('../templates', __FILE__)

    # overrides the default
    argument :name, :type => :string, :default => 'front', :optional => true

    include Generators::Hobo::Controller
    include Generators::Hobo::InviteOnly

    def self.banner
      "rails generate hobo:front_controller [NAME=front] [options]"
    end

    class_option :add_routes,
                 :type => :boolean,
                 :desc => "Modify config/routes.rb to support the front controller",
                 :default => true

    class_option :delete_index,
                 :aliases => '-d',
                 :type => :boolean,
                 :desc => "Delete public/index.html",
                 :default => true

    class_option :user_resource_name,
                 :type => :string,
                 :desc => "User Resource Name",
                 :default => 'user'

    def generate_controller
      template 'controller.rb.erb', File.join('app/controllers',"#{file_path}_controller.rb")
    end

    def generate_index
      template("index.dryml", File.join('app/views', file_path, "index.dryml"))
    end

    def remove_index_html
      return unless options[:delete_index]
      remove_file File.join(Rails.root, "public/index.html")
    end

    def add_routes
      return unless options[:add_routes]
      route "match 'search' => '#{file_path}#search', :as => 'search'"
      if class_path.empty?
        route "root :to => '#{file_path}#index'"
      else
        route "match '#{file_path}' => '#{file_path}#index', :as => '#{file_path.gsub(/\//,'_')}'"
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hobo-1.3.0.pre24 lib/generators/hobo/front_controller/front_controller_generator.rb
hobo-1.3.0.pre23 lib/generators/hobo/front_controller/front_controller_generator.rb
hobo-1.3.0.pre22 lib/generators/hobo/front_controller/front_controller_generator.rb
hobo-1.3.0.pre21 lib/generators/hobo/front_controller/front_controller_generator.rb
hobo-1.3.0.pre20 lib/generators/hobo/front_controller/front_controller_generator.rb
hobo-1.3.0.pre19 lib/generators/hobo/front_controller/front_controller_generator.rb
hobo-1.3.0.pre18 lib/generators/hobo/front_controller/front_controller_generator.rb