Sha256: cd539cff6a0999a305bd3450cc934e429476978eb08abaa5b93739f4a81d4f9e

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

require 'rails/generators/base'
require 'generators/my_scaffold_generator'

module MyGenerators::Generators
    class ScaffoldGenerator < Rails::Generators::NamedBase
      include Rails::Generators::ResourceHelpers
      include MyScaffoldGenerator
      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"

      def create_root_folder
        empty_directory File.join("app/views", controller_file_path)
      end

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

      def copy_view_files
        available_views.each do |view|
          filename = filename_with_extensions(view)
          template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
        end
      end

      hook_for :form_builder, :as => :scaffold

      def copy_form_file
        if options[:form_builder].nil?
          filename = filename_with_extensions("_form")
          template "_form.html.haml", File.join("app/views", controller_file_path, filename)
        end
      end

    protected

      def available_views
        %w(index edit show new)
      end

      def handler
        :haml
      end
      def format
        :html
      end
      
      def filename_with_extensions(name)
        [name, format, handler].compact.join(".")
      end
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
my_generators-0.0.4 lib/generators/my_generators/scaffold/scaffold_generator.rb
my_generators-0.0.3 lib/generators/my_generators/scaffold/scaffold_generator.rb
my_generators-0.0.2 lib/generators/my_generators/scaffold/scaffold_generator.rb
my_generators-0.0.1 lib/generators/my_generators/scaffold/scaffold_generator.rb