Sha256: f03c5cd8225ea29faec597b650b0aac1c8240024afd3115c8d19607e4b86a0d7

Contents?: true

Size: 1.84 KB

Versions: 41

Compression:

Stored size: 1.84 KB

Contents

#!/usr/bin/env ruby
require "rubygems"

require "thor"
require "thor/group"
require 'thor/rake_compat'

module IB
  class ControllerGenerator < Thor
    include Thor::Actions
    include Thor::RakeCompat
    
    map "c" => :controller

    def self.source_root
      File.dirname(__FILE__)
    end

    desc "controller", "generate controller"
    argument :name, :type => :string, :desc => "Name of the controller"
    argument :controller_type, :type => :string, :desc => "Type of the controller, default: UIViewController", :default => "UIViewController"
    class_option :outlets, :type => :hash, :default => {}, :required => false, :desc => "IBOutlets of the controller"
    class_option :actions, :type => :array, :default => [], :required => false, :desc => "IBAtions of the controller"
    class_option :accessors, :type => :array, :default => [], :required => false, :desc => "Accessors of the controller"
    def controller
      create_controller_file
      create_helper_file
      create_spec_file
    end

    private
    def create_controller_file
      template('../template/controller.erb', "app/controllers/#{underscore(name)}_controller.rb")
    end

    def create_helper_file
      template('../template/controller_helper.erb', "app/helpers/#{underscore(name)}_helper.rb")
    end

    def create_spec_file
      template('../template/controller_spec.erb', "spec/controllers/#{underscore(name)}_controller_spec.rb")
    end

    def controller_name
      camelize("#{name}Controller")
    end

    def underscore(string)
      string.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
    end

    def camelize(string)
      return string if string !~ /_/ && string =~ /[A-Z]+.*/
      string.split('_').map{|e| e.capitalize }.join
    end
  end
end

IB::ControllerGenerator.start

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
ib-0.3.3 bin/ib
ib-0.3.2 bin/ib
ib-0.3.1 bin/ib
ib-0.3.0 bin/ib
ib-0.2.10 bin/ib
ib-0.2.9 bin/ib
ib-0.2.7 bin/ib
ib-0.2.6 bin/ib
ib-0.2.5 bin/ib
ib-0.2.4 bin/ib
ib-0.2.3 bin/ib
ib-0.2.2 bin/ib
ib-0.2.1 bin/ib
ib-0.2.0 bin/ib
ib-0.1.4 bin/ib
ib-0.1.3 bin/ib
ib-0.1.2 bin/ib
ib-0.1.1 bin/ib
ib-0.1.0 bin/ib
ib-0.0.5 bin/ib