require 'rubygems' require 'bivouac/utils' module Bivouac class Generate add_generator [:iphone] private def iphone_view( iphone = nil, empty = false ) warn "iphone_view generator is deprecated. Please use iphone generator." return end def iphone if @app.environment.orgtype.downcase == "erb" raise "ERB applications are no longer supported. Sorry!" end # The view must not be empty empty = false # iPhone options argument_options = OptionParser.new do |opts| opts.banner = "" opts.separator "iphone generator options:" opts.on( "-e", "--empty", "Create an empty views" ) do empty = true end opts.on_tail("-h", "--help", "Show this message") do help puts opts puts "" puts "Description:" puts " Stubs out a new iphone controller and its views. Pass the controller name," puts " either CamelCased or under_scored, and a list of views as arguments." puts "" puts "Example:" puts " ruby script/generate iphone my_controller my_view_one my_view_two ..." exit end end # parse options if view name is not passed argument_options.parse! @script_arguments if @script_arguments.length < 1 help puts argument_options exit end # Get controller name iphone_controller = @script_arguments.shift # Controller file iphone_controller_destination_file = File.dirname( $0 ) + "/../app/controllers/iphone_" + iphone_controller.underscore + ".rb" # Views directory iphone_view_directory = File.dirname( $0 ) + "/../app/views/" + iphone_controller.underscore # Create views directory createDir( iphone_view_directory ) # Create controller file createFile( iphone_controller_destination_file ) do |io_controller| io_controller.puts plugin_template( File.join( File.expand_path( File.dirname(__FILE__) ), "template/iphone_controller_begin.rb" ), binding ) # Each actions... @script_arguments.each do |iphone_action| @iphone_class = iphone_controller.classify + iphone_action.classify @iphone_view = "iphone_" + @iphone_class.underscore @iphone_route = iphone_controller.underscore + "/" + iphone_action.underscore # Update iPhone Controller io_controller.puts plugin_template( File.join( File.expand_path( File.dirname(__FILE__) ), "template/iphone_controller_action.rb" ), binding ) # Create iPhone View for action iphone_view_destination_file = iphone_view_directory + "/iphone_" + iphone_action.underscore + ".rb" createFile( iphone_view_destination_file ) do |io_view| if empty io_view.puts plugin_template( File.join( File.expand_path( File.dirname(__FILE__) ), "template/iphone_view_empty.rb" ), binding ) else io_view.puts plugin_template( File.join( File.expand_path( File.dirname(__FILE__) ), "template/iphone_view.rb" ), binding ) end end end io_controller.puts plugin_template( File.join( File.expand_path( File.dirname(__FILE__) ), "template/iphone_controller_end.rb" ), binding ) end end end end