Sha256: 813df4fe135152683977aef59d2e2cf5fe5d29b5d5ee820f962e2a0643d97cc2

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'generators/haml/base.rb'
require 'rails/generators/resource_helpers'

module Haml
  module Generators
    class ScaffoldGenerator < Haml::Generators::Base
      include Rails::Generators::ResourceHelpers

      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"

      class_option :layout,    :type => :boolean
      class_option :singleton, :type => :boolean, :desc => "Supply to skip index view"

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

      def copy_index_file
        return if options[:singleton]
        copy_view :index
      end

      def copy_edit_file
        copy_view :edit
      end

      def copy_show_file
        copy_view :show
      end

      def copy_new_file
        copy_view :new
      end

      def copy_form_file
        copy_view :_form
      end

      def copy_layout_file
        return unless options[:layout]
        template "layout.html.haml", File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.haml")
      end

      protected
        def copy_view(view)
          template "#{view}.html.haml", File.join("app/views", controller_file_path, "#{view}.html.haml")
        end
    end
  end
end

Version data entries

3 entries across 2 versions & 2 rubygems

Version Path
sc_core-0.0.7 test/dummy/lib/generators/haml/scaffold/scaffold_generator.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/haml_rails-0.1.0/lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb
haml_rails-0.1.0 lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb