Sha256: 2be2ec0eaa3bdc519d24138073881eaee19690bf8b679f2536b8ced9539b2088

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# Generates scaffold for Mack applications.
# 
# Example:
#   rake generate:scaffold name=post
class ScaffoldGenerator < Genosaurus
  
  require_param :name
  
  def setup
    @name_singular = param(:name).singular.underscore
    @name_plural = param(:name).plural.underscore
    @name_singular_camel = @name_singular.camelcase
    @name_plural_camel = @name_plural.camelcase    
  end
  
  def after_generate
    if app_config.orm
      ModelGenerator.run(@options)
    end
    update_routes_file
  end
  
  def update_routes_file
    # update routes.rb
    routes = File.join(MACK_CONFIG, "routes.rb")
    rf = File.open(routes).read
    unless rf.match(".resource :#{@name_plural}")
      puts "Updating routes.rb"
      nrf = ""
      rf.each do |line|
        if line.match("Mack::Routes.build")
          x = line.match(/\|(.+)\|/).captures
          line << "\n  #{x}.resource :#{@name_plural} # Added by rake generate:scaffold name=#{param(:name)}\n"
        end
        nrf << line
      end
      File.open(routes, "w") do |f|
        f.puts nrf
      end
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mack-0.4.7 lib/generators/scaffold_generator/scaffold_generator.rb