Sha256: fcf58386da8e118a93c80faac0acd5c9574ade25c4e681833e4d6fda9878c5e6

Contents?: true

Size: 1.06 KB

Versions: 49

Compression:

Stored size: 1.06 KB

Contents

require 'rails/generators/active_record'

module ScaffoldPlus
  module Generators
    class CollectionGenerator < ActiveRecord::Generators::Base
      desc "Add a collection to a resource route"
      argument :name, type: :string,
               desc: "The object for the collection routes and views"
      argument :routes, type: :array, banner: "route[:verb=get] ...",
               desc: "The collection(s) to be added to NAME"
      source_root File.expand_path('../templates', __FILE__)
      
      def add_routes
        list = []
        routes.each do |route|
          view, verb = route.split(':')
          list << "      #{verb || 'get'} '#{view}'"
        end
        result = list.join("\n")
        gsub_file "config/routes.rb", /(^  resources :#{name.pluralize})$/,
                  "\\1 do\n    collection do\n#{result}\n    end\n  end"
      end
      
      def add_views
        routes.each do |route|
          @view = route.split(':').first
          template "view.html.erb", "app/views/#{table_name}/#{@view}.html.erb"
        end
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
scaffold_plus-2.1.4 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-2.1.3 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-2.1.2 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-2.1.1 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.10.3 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.10.2 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.10.1 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.10.0 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.9.3 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.9.2 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.9.1 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.9.0 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.8.0 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.14 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.13 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.12 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.11 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.10 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.9 lib/generators/scaffold_plus/collection/collection_generator.rb
scaffold_plus-1.7.8 lib/generators/scaffold_plus/collection/collection_generator.rb