playmvc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74b11c55a843187f459952ea7566c20eb2b8024d
4
+ data.tar.gz: 811c4aac774b96c291d088831f24dacf59fef52d
5
+ SHA512:
6
+ metadata.gz: ad5367604dcdff4bef306f8180ff8b3123917e328a4fd74fa0d72642cc3782667880a36d15389f8bd0e185fda45cd58838c1bf1a72fbf435ecf54c3556451c5d
7
+ data.tar.gz: 08cda2d34f4704f45137c93758fe6cfd02127fafc8e1fe702d1d345664e2a31537983feead0c4b2979eeaad84f2c624bc4a1f66e83203372df783d4dc5a1d837
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in playmvc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 lincoln
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ ## Usage
2
+
3
+
4
+ 这是一个为playframework从命令行下生成 viewmodel controller helper view route 文件的生成器
5
+
6
+ Demo:
7
+
8
+ $: ruby playmvc/lib/playmvc.rb user username:String password:String age:int married:boolean id:int --namespace com.
9
+ umeng --action create,name:String,age:int,email:String update,name:String,age:int,email:String delete,id:int
10
+
11
+
12
+ ruby playmvc.rb MODEL_NAME Property1:javatype ... Propertyn:javatype --super super --namespace com.lincolnlau --action ACTION1 ACTION2,Parameter:type ACTION3,Parameter:type,Parameter:type
13
+
14
+
15
+ --super 为viewmodel 的父类
16
+ --namesapce 为package名
17
+ --action 为关于contoller中action中的描述  action默认的返回参数都将是 viewmodel
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/playmvc ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'playmvc'
4
+
5
+ POJOCLI::Pojo.start(ARGV)
6
+ #puts "hello"
data/lib/playmvc.rb ADDED
@@ -0,0 +1,153 @@
1
+ require "thor"
2
+
3
+ module POJOCLI
4
+
5
+ class Pojo < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :name
9
+ argument :properties, type: :array, :required => true, banner: "property property"
10
+
11
+ class_option :super, default: nil
12
+ class_option :namespace, default: nil
13
+ class_option :action, type: :array, default: []
14
+
15
+ def self.source_root
16
+ File.dirname(__FILE__)
17
+ end
18
+
19
+ def exist_play_project
20
+
21
+ if(!File.exist?(File.expand_path("conf/application.conf")))
22
+ 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"
23
+ raise Error, "This command must be run in a play project's root direcotry!!"
24
+ end
25
+ end
26
+
27
+
28
+ def parse_argument_option
29
+
30
+ errors = [];
31
+
32
+ #parseName
33
+ name_reg = /^[a-z]+[_a-zA-Z0-9]*$/
34
+ errors.push("NAME is not valid! #{name}") if(!name.match name_reg )
35
+
36
+ #property
37
+ property_reg = /^[a-z]+[_a-zA-Z0-9]*\:[a-zA-Z]+[_a-zA-Z0-9]*$/
38
+ properties.each do | property |
39
+ errors.push("Property is not valid! #{property}") if(!property.match property_reg)
40
+ end
41
+
42
+ #package
43
+ pkg_reg = /^[a-zA-Z]+[_a-zA-Z0-9]+(\.[a-z][_a-zA-Z0-9]+)*$/
44
+ errors.push("Property is not valid! #{property}") if(!options[:namespace].match pkg_reg) if(options[:namespace])
45
+
46
+ #super class
47
+ super_reg = /^[A-Z]+[_a-zA-Z0-9]*$/
48
+ errors.push("Property is not valid! #{property}") if(!options[:super].match super_reg ) if(options[:super])
49
+
50
+ #actions
51
+ action_reg = /^[a-z]+[_a-zA-Z0-9]*(\,[a-z]+[_a-zA-Z0-9]*:[a-zA-Z]+[_a-zA-Z0-9])*$/
52
+ if(options[:action].length > 0)
53
+ options[:action].each do | a |
54
+ errors.push() if(!a.match action_reg)
55
+ end
56
+ end
57
+
58
+ raise ArgumentError, errors.join("\n") if errors.length > 0
59
+
60
+ end
61
+
62
+ def create_model_file
63
+ #path = "models/"
64
+ #path += options[:namespace].gsub(/\./, "\/") if(options[:namespace])
65
+ path = folderPath("app/models") + "/#{name.capitalize}ViewModel.java"
66
+ template('templates/model.erb', path)
67
+ end
68
+
69
+ def create_controller_file
70
+ if(options[:action].length > 0)
71
+ path = folderPath("app/controllers") + "/#{name.capitalize}Controller.java"
72
+ template('templates/controller.erb', path)
73
+ end
74
+ end
75
+
76
+ def create_helper_file
77
+
78
+ if(options[:action].length > 0)
79
+ path = folderPath("app/helpers") + "/#{name.capitalize}Helper.java"
80
+ template('templates/helper.erb', path)
81
+ end
82
+ end
83
+
84
+ def create_view_file
85
+
86
+ path = folderPath("app/views") + "/"
87
+
88
+ if(options[:action].length > 0)
89
+ options[:action].each do |a|
90
+ actionname = a.split(',').first
91
+ #create_file(path + actionname + ".scala.html")
92
+ template('templates/view.erb', path + actionname + ".scala.html")
93
+ end
94
+ end
95
+ end
96
+
97
+ def add_route
98
+ if(options[:action].length > 0)
99
+ routes = ["\n# #{name}"]
100
+ options[:action].each do |a|
101
+ p_array = []
102
+ ap = a.split(',')
103
+ actionName = ap.shift
104
+ action = packgePath("controllers") + "." + name.capitalize + 'Controller.' + actionName + "("
105
+ action += ap.join(", ").gsub(/\:(\w)+/){|s|
106
+ ":" + POJOCLI::Pojo.getPackType(s[1..-1])
107
+ } if ap.length > 0
108
+ action += ")"
109
+
110
+ route = "/" + name+"/" + actionName
111
+ route = "/" + options[:namespace].gsub(/\./, "\/") + "/" + name + "/" +actionName if(options[:namespace])
112
+
113
+ routes.push("GET #{route} #{action}")
114
+ end
115
+ append_to_file "conf/routes", routes.join("\n");
116
+ end
117
+ end
118
+
119
+
120
+ def self.getPackType(type)
121
+
122
+ type_hash = {
123
+ 'char' => 'Character',
124
+ 'byte' => 'Byte',
125
+ 'short' => 'Short',
126
+ 'int' => 'Integer',
127
+ 'long' => 'Long',
128
+ 'float' => 'Float',
129
+ 'double' => 'Double',
130
+ 'boolean' => 'Boolean'
131
+ }
132
+
133
+ return type_hash[type] if(type_hash.has_key? type)
134
+ type
135
+
136
+ end
137
+
138
+ private
139
+ def folderPath(folder)
140
+ path = folder + "/"
141
+ path += options[:namespace].gsub(/\./, "\/") if(options[:namespace])
142
+ path
143
+ end
144
+
145
+ def packgePath(top)
146
+ top += "." + options[:namespace] if(options[:namespace])
147
+ top
148
+ end
149
+
150
+ end
151
+ end
152
+
153
+ #POJOCLI::Pojo.start(ARGV)
@@ -0,0 +1,3 @@
1
+ module Playmvc
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ package controllers<%='.' + options[:namespace] if(options[:namespace])%>;
2
+
3
+ import play.*;
4
+ import play.mvc.*;
5
+
6
+ import views.html.*;
7
+
8
+ import models<%='.' +options[:namespace] if(options[:namespace])%>.<%=name.capitalize%>ViewModel;
9
+ import helpers<%='.' + options[:namespace] if(options[:namespace])%>.<%=name.capitalize%>Helper;
10
+
11
+ public class <%=name.capitalize%>Controller extends Controller {
12
+
13
+ <% options[:action].each do |a|-%>
14
+ <% ap = a.split(',')-%>
15
+ <% actionName = ap.shift%>
16
+ public static Result <%=actionName%>(<% if(ap.length > 0) -%><% ap.each do |parameter|-%><% isLast = parameter == ap.last;ps = parameter.split(':')-%><%=(ps[1] + " " + ps[0] + (isLast ? "" : ", ")) if(ps.length > 1)%><% end -%><% end -%>){
17
+
18
+ /// TODO: write you code herer
19
+ return ok(<%=actionName.downcase%>.render(<%=name.capitalize%>Helper.<%=actionName%>(<% if(ap.length > 0) -%><% ap.each do |parameter|-%><% ps = parameter.split(':')-%><%=ps[0] if(ps.length > 1)%><%=", " if(parameter != ap.last && ps.length > 1) %><% end -%><% end -%>)));
20
+ }
21
+
22
+ <% end -%>}
@@ -0,0 +1,15 @@
1
+ package helpers<%='.' + options[:namespace] if(options[:namespace])%>;
2
+
3
+ import models<%='.' +options[:namespace] if(options[:namespace])%>.<%=name.capitalize%>ViewModel;
4
+
5
+ public class <%=name.capitalize%>Helper {
6
+
7
+ <% options[:action].each do |a|-%>
8
+ <% ap = a.split(',')-%>
9
+ <% actionName = ap.shift%>
10
+ public static <%=name.capitalize%>ViewModel <%=actionName%>(<% if(ap.length > 0) -%><% ap.each do |parameter|-%><% isLast = parameter == ap.last;ps = parameter.split(':')-%><%=(ps[1] + " " + ps[0] + (isLast ? "" : ", ")) if(ps.length > 1)%><% end -%><% end -%>){
11
+
12
+ return new <%=name.capitalize%>ViewModel();
13
+ }
14
+
15
+ <% end -%>}
@@ -0,0 +1,28 @@
1
+ package models<%='.' + options[:namespace] if(options[:namespace])%>;
2
+
3
+ public class <%=name.capitalize%>ViewModel <%if(options[:super]) -%> extends <%=options[:super]%><% end -%> {
4
+
5
+ <% properties.each do |property| -%>
6
+ <% ps = property.split(":")-%>
7
+ private <%=ps[1] + " " + ps[0] + ";\n"%>
8
+ <%end-%>
9
+
10
+ <% properties.each do |property| -%><% ps = property.split(":")-%>
11
+ /**
12
+ * @parameter set <%=ps[0]%>'s value
13
+ */
14
+ public void set<%=ps[0].capitalize%>(<%=ps[1]%> <%=ps[0]%>) {
15
+ this.<%=ps[0]%> = <%=ps[0]%>;
16
+ }
17
+
18
+ /**
19
+ * @return <%=ps[1]%>
20
+ */
21
+ public <%=ps[1]%> <%if(ps[1] == "boolean")-%>is<% else -%>get<% end -%><%=ps[0].capitalize%>() {
22
+ return this.<%=ps[0]%>;
23
+ }
24
+
25
+ <%end-%>
26
+
27
+
28
+ }
File without changes
@@ -0,0 +1 @@
1
+ @(model:<%=name.capitalize%>ViewModel)
data/playmvc.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'playmvc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "playmvc"
8
+ spec.version = Playmvc::VERSION
9
+ spec.authors = ["lincoln"]
10
+ spec.email = ["lincoln@umeng.com"]
11
+ spec.description = %q{这是一个用于在play framework下生成viewmodel controller views helpers的命令}
12
+ spec.summary = %q{这是一个用于在play framework下生成viewmodel controller views helpers的命令}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.executables = ["playmvc"]
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: playmvc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - lincoln
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 这是一个用于在play framework下生成viewmodel controller views helpers的命令
42
+ email:
43
+ - lincoln@umeng.com
44
+ executables:
45
+ - playmvc
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/playmvc
55
+ - lib/playmvc.rb
56
+ - lib/playmvc/version.rb
57
+ - lib/templates/controller.erb
58
+ - lib/templates/helper.erb
59
+ - lib/templates/model.erb
60
+ - lib/templates/route.erb
61
+ - lib/templates/view.erb
62
+ - playmvc.gemspec
63
+ homepage: ''
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: 这是一个用于在play framework下生成viewmodel controller views helpers的命令
87
+ test_files: []