Sha256: df88ae91920d3c210d41e9ac48648d6cf8282d959f9600ed22830a1846ddea2f

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Ecm
  module CalendarHelper
    module Generators
      class ControllerGenerator < Rails::Generators::Base
        desc 'Generates a calendar controller (with views)'

        source_root File.expand_path('../templates', __FILE__)

        attr_reader :base_controller_class_name
        attr_reader :controller_class_name

        def initialize(*args)
          super
          @base_controller_class_name = ENV.fetch('BASE_CONTROLLER_CLASS_NAME') { '::FrontendController' }
          @controller_class_name = ENV.fetch('CONTROLLER_CLASS_NAME') { 'CalendarsController' }
        end

        def generate_routes
          route File.read(File.join(File.expand_path('../templates', __FILE__), 'routes.source'))
        end

        def generate_controller
          binding.pry
          template 'controller.rb', "app/controllers/#{controller_path_name}.rb"
        end

        def generate_views
          template 'views/index.html.haml',     "app/views/#{view_path}/index.html.haml"
          template 'views/index.js.erb',        "app/views/#{view_path}/index.js.erb"
          template 'views/_calendar.html.haml', "app/views/#{view_path}/_calendar.html.haml"
        end

        private

        def controller_path_name
          @controller_class_name.underscore
        end

        def view_path
          @controller_class_name.underscore.gsub('_controller', '')
        end

        def route_name
          @controller_class_name.demodulize.underscore.pluralize
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ecm_calendar_helper-1.0.1 lib/generators/ecm/calendar_helper/controller/controller_generator.rb
ecm_calendar_helper-1.0.0 lib/generators/ecm/calendar_helper/controller/controller_generator.rb