class POJOCLI::Pojo
Public Class Methods
getPackType(type)
click to toggle source
# File lib/playmvc.rb, line 120 def self.getPackType(type) type_hash = { 'char' => 'Character', 'byte' => 'Byte', 'short' => 'Short', 'int' => 'Integer', 'long' => 'Long', 'float' => 'Float', 'double' => 'Double', 'boolean' => 'Boolean' } return type_hash[type] if(type_hash.has_key? type) type end
source_root()
click to toggle source
# File lib/playmvc.rb, line 15 def self.source_root File.dirname(__FILE__) end
Public Instance Methods
add_route()
click to toggle source
# File lib/playmvc.rb, line 97 def add_route if(options[:action].length > 0) routes = ["\n# #{name}"] options[:action].each do |a| p_array = [] ap = a.split(',') actionName = ap.shift action = packgePath("controllers") + "." + name.capitalize + 'Controller.' + actionName + "(" action += ap.join(", ").gsub(/\:(\w)+/){|s| ":" + POJOCLI::Pojo.getPackType(s[1..-1]) } if ap.length > 0 action += ")" route = "/" + name+"/" + actionName route = "/" + options[:namespace].gsub(/\./, "\/") + "/" + name + "/" +actionName if(options[:namespace]) routes.push("GET #{route} #{action}") end append_to_file "conf/routes", routes.join("\n"); end end
create_controller_file()
click to toggle source
# File lib/playmvc.rb, line 69 def create_controller_file if(options[:action].length > 0) path = folderPath("app/controllers") + "/#{name.capitalize}Controller.java" template('templates/controller.erb', path) end end
create_helper_file()
click to toggle source
# File lib/playmvc.rb, line 76 def create_helper_file if(options[:action].length > 0) path = folderPath("app/helpers") + "/#{name.capitalize}Helper.java" template('templates/helper.erb', path) end end
create_model_file()
click to toggle source
# File lib/playmvc.rb, line 62 def create_model_file #path = "models/" #path += options[:namespace].gsub(/\./, "\/") if(options[:namespace]) path = folderPath("app/models") + "/#{name.capitalize}ViewModel.java" template('templates/model.erb', path) end
create_view_file()
click to toggle source
# File lib/playmvc.rb, line 84 def create_view_file path = folderPath("app/views") + "/" if(options[:action].length > 0) options[:action].each do |a| actionname = a.split(',').first #create_file(path + actionname + ".scala.html") template('templates/view.erb', path + actionname + ".scala.html") end end end
exist_play_project()
click to toggle source
# File lib/playmvc.rb, line 19 def exist_play_project if(!File.exist?(File.expand_path("conf/application.conf"))) puts "Can't auto generate code without in the directory of play project's root directory, please change to a play project 's root directory first.\n" raise Error, "This command must be run in a play project's root direcotry!!" end end
parse_argument_option()
click to toggle source
# File lib/playmvc.rb, line 28 def parse_argument_option errors = []; #parseName name_reg = /^[a-z]+[_a-zA-Z0-9]*$/ errors.push("NAME is not valid! #{name}") if(!name.match name_reg ) #property property_reg = /^[a-z]+[_a-zA-Z0-9]*\:[a-zA-Z]+[_a-zA-Z0-9]*$/ properties.each do | property | errors.push("Property is not valid! #{property}") if(!property.match property_reg) end #package pkg_reg = /^[a-zA-Z]+[_a-zA-Z0-9]+(\.[a-z][_a-zA-Z0-9]+)*$/ errors.push("Property is not valid! #{property}") if(!options[:namespace].match pkg_reg) if(options[:namespace]) #super class super_reg = /^[A-Z]+[_a-zA-Z0-9]*$/ errors.push("Property is not valid! #{property}") if(!options[:super].match super_reg ) if(options[:super]) #actions action_reg = /^[a-z]+[_a-zA-Z0-9]*(\,[a-z]+[_a-zA-Z0-9]*:[a-zA-Z]+[_a-zA-Z0-9])*$/ if(options[:action].length > 0) options[:action].each do | a | errors.push() if(!a.match action_reg) end end raise ArgumentError, errors.join("\n") if errors.length > 0 end
Private Instance Methods
folderPath(folder)
click to toggle source
# File lib/playmvc.rb, line 139 def folderPath(folder) path = folder + "/" path += options[:namespace].gsub(/\./, "\/") if(options[:namespace]) path end
packgePath(top)
click to toggle source
# File lib/playmvc.rb, line 145 def packgePath(top) top += "." + options[:namespace] if(options[:namespace]) top end