Sha256: bcabf6c8fbab28b95c5607b29caeb6e776b9347464dff65311bb881e062e1d68

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'rails/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"
      class_option :cancan,      type: :string, desc: "Use cancan patterns"

      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_destroy_file
        copy_coffee :destroy
      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

      def copy_controller
        return unless defined? Stimulus
        filename = 'navigation_controller.js'
        path = 'app/javascript/controllers/' + filename
        return if File.file? path
        template filename, path
      end

      protected

      def copy_coffee(view)
        template "#{view}.js.coffee",
            File.join("app/views", controller_file_path, "#{view}.js.coffee")
      end

      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

1 entries across 1 versions & 1 rubygems

Version Path
advanced_haml_scaffold_generator-3.0.0 lib/rails/generators/haml/scaffold/scaffold_generator.rb