Zend Frameworkでrailsのスケルトンもどき
Railsの generate controller みたいなのを
ZendFrameworkでもしたいと思ってrubyでいい加減だけど書いた。
次はmodelだな。
railsだと↓こんな感じ。
[admin@localhost]~/test% script/generate controller sample2 exists app/controllers/ exists app/helpers/ create app/views/sample2 exists test/functional/ create app/controllers/sample2_controller.rb create test/functional/sample2_controller_test.rb create app/helpers/sample2_helper.rb [admin@localhost]~/test% script/generate controller sample2 exists app/controllers/ exists app/helpers/ exists app/views/sample2 exists test/functional/ identical app/controllers/sample2_controller.rb identical test/functional/sample2_controller_test.rb identical app/helpers/sample2_helper.rb
if ARGV.size != 1 $stderr.puts "Usage: #{$0} controller_name" exit 64 end name = ARGV[0] if FileTest.exists?(Dir::pwd + "/app/controllers") then puts "exists app/controllers" if File.exist?(Dir::pwd + "/app/controllers/" + name + "Controller.php") then puts "identical /app/controllers/#{name}Controller.php" else File.open(Dir::pwd + "/app/controllers/" + name + "Controller.php", "w"){|file| file.puts("<?php") file.puts("") file.puts("require_once dirname(__FILE__) . '/AbstractController.php';\n") file.puts("") file.puts("class " + name + "Controller extends AbstractController") file.puts("{") file.puts("}") file.puts("") } puts "create /app/controllers/#{name}Controller.php" end else puts "not found /app/controllers" end
↓実行結果
[admin@localhost]~/public/tmp% ruby test.rb Post exists app/controllers create /app/controllers/PostController.php [admin@localhost]~/public/tmp% ruby test.rb Post exists app/controllers identical /app/controllers/PostController.php
[追記]↓model
if ARGV.size != 1 $stderr.puts "Usage: #{$0} model_name" exit 64 end name = ARGV[0] if FileTest.exists?(Dir::pwd + "/app/models") then puts "exists app/models" if File.exist?(Dir::pwd + "/app/models/" + name + ".php") then puts "identical /app/models/#{name}.php" else File.open(Dir::pwd + "/app/models/" + name + ".php", "w"){|file| file.puts("<?php") file.puts("") file.puts("require_once 'Wired/Admin/models/account.php';\n") file.puts("") file.puts("class " + name + " extends [モデル名]") file.puts("{") file.puts("}") file.puts("") } puts "create /app/models/#{name}.php" end else puts "not found /app/models" end