pattern 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,43 +1,43 @@
1
- == EasyPattern
2
-
3
- Rubygem for building Pattern/Data Structure .
4
- Supports custom templates by any language.
5
- Good tools for learning Pattern/Data Structure.
6
-
7
- == Useage
8
-
9
- simple model
10
- *pattern [tempate_dir] [main_class_name] [-d target_dir]
11
- *pattern [-t tempate_dir] [-d target_dir("." is default)] [-c classes_name] [-op operations_name]
12
- complex model (not support now.)
13
- *pattern -f pattern_file
14
-
15
- == example:
16
-
17
- simple model:
18
- * pattern ruby.composite Task -d target
19
- * pattern -t ruby.composite -d target -c Task;CompositeTask;AddDryIngredientsTask,MixTask,AddLiquidsTask;MakeBatterTask,MakeCakeTask -op get_time_required
20
- complex model(pattern_file):
21
-
22
- == Future
23
- Sharing pattern templates on website.
24
-
25
- == Version
26
- 0.9.4
27
- 1. Refactoring the code
28
- 2. Template of ruby.composite work
29
- 3. Getting help with no parameter
30
- 4. Replacing lower_case name . Example: class_name:Task lc_class_name:task
31
-
32
-
33
- == Question
34
- If you get some Questions. Mailto :azhao.1981@gmail.com
35
-
36
- == Author
37
-
38
- Copyright 2010 @ weizhao
39
- mailto: azhao.1981@gmail.com
40
-
41
- == licese
42
-
43
- This library and all associated materials are releassse under the terms of version 2 of the GNU Public License(http://www.gnu.org/copyleft/gpl.html).
1
+ == EasyPattern
2
+
3
+ Rubygem for building Pattern/Data Structure .
4
+ Supports custom templates by any language.
5
+ Good tools for learning Pattern/Data Structure.
6
+
7
+ == Useage
8
+
9
+ simple model
10
+ *pattern [tempate_dir] [main_class_name] [-d target_dir]
11
+ *pattern [-t tempate_dir] [-d target_dir("." is default)] [-c classes_name] [-op operations_name]
12
+ complex model (not support now.)
13
+ *pattern -f pattern_file
14
+
15
+ == example:
16
+
17
+ simple model:
18
+ * pattern ruby.composite Task -d target
19
+ * pattern -t ruby.composite -d target -c Task;CompositeTask;AddDryIngredientsTask,MixTask,AddLiquidsTask;MakeBatterTask,MakeCakeTask -op get_time_required
20
+ complex model(pattern_file):
21
+
22
+ == Future
23
+ Sharing pattern templates on website.
24
+
25
+ == Version
26
+ 0.9.4
27
+ 1. Refactoring the code
28
+ 2. Template of ruby.composite work
29
+ 3. Getting help with no parameter
30
+ 4. Replacing lower_case name . Example: class_name:Task lc_class_name:task
31
+
32
+
33
+ == Question
34
+ If you get some Questions. Mailto :azhao.1981@gmail.com
35
+
36
+ == Author
37
+
38
+ Copyright 2010 @ weizhao
39
+ mailto: azhao.1981@gmail.com
40
+
41
+ == licese
42
+
43
+ This library and all associated materials are releassse under the terms of version 2 of the GNU Public License(http://www.gnu.org/copyleft/gpl.html).
data/README.cn CHANGED
@@ -1,26 +1,26 @@
1
- == EasyPattern
2
- 这是一个用于自动生成设计模式/数据结构的rubygem工具,其特点是支持自定义模板,这使您学习设计模式和数据结构更加方便。
3
-
4
- == Useage
5
- 简单模式
6
- pattern [tempate_dir] [main_class_name] [-d target_dir]
7
- pattern [-t tempate_dir] [-d target_dir("." is default)] [-c classes_name] [-op operations_name]
8
- 复杂模式 (未支持)
9
- pattern -f pattern_file
10
-
11
- == 命令示例:
12
- 简单模式:
13
- * pattern ruby.composite Task -d target
14
- * pattern -t ruby.composite -d target -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute
15
- 复杂模式(pattern_file):
16
-
17
- == 未来工作
18
- 1. 支持复杂模式
19
- 2. 通过网站支持模板分享
20
-
21
- == Author
22
- Copyright @ weizhao 2010
23
- mailto: azhao.1981@gmail.com
24
-
25
- == licese
26
- This library and all associated materials are releassse under the terms of version 2 of the GNU Public License(http://www.gnu.org/copyleft/gpl.html).
1
+ == EasyPattern
2
+ 这是一个用于自动生成设计模式/数据结构的rubygem工具,其特点是支持自定义模板,这使您学习设计模式和数据结构更加方便。
3
+
4
+ == Useage
5
+ 简单模式
6
+ pattern [tempate_dir] [main_class_name] [-d target_dir]
7
+ pattern [-t tempate_dir] [-d target_dir("." is default)] [-c classes_name] [-op operations_name]
8
+ 复杂模式 (未支持)
9
+ pattern -f pattern_file
10
+
11
+ == 命令示例:
12
+ 简单模式:
13
+ * pattern ruby.composite Task -d target
14
+ * pattern -t ruby.composite -d target -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute
15
+ 复杂模式(pattern_file):
16
+
17
+ == 未来工作
18
+ 1. 支持复杂模式
19
+ 2. 通过网站支持模板分享
20
+
21
+ == Author
22
+ Copyright @ weizhao 2010
23
+ mailto: azhao.1981@gmail.com
24
+
25
+ == licese
26
+ This library and all associated materials are releassse under the terms of version 2 of the GNU Public License(http://www.gnu.org/copyleft/gpl.html).
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- task :install do
5
- `cp -R lib /usr/lib/ruby/gems/1.8/gems/pattern-0.9.0/`
6
- `cp bin/pattern /usr/bin`
7
- end
8
-
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ task :install do
5
+ `cp -R lib /usr/lib/ruby/gems/1.8/gems/pattern-0.9.0/`
6
+ `cp bin/pattern /usr/bin`
7
+ end
8
+
data/bin/pattern CHANGED
@@ -1,31 +1,31 @@
1
- #!/usr/bin/env ruby
2
- current_dir = File.dirname(__FILE__)
3
-
4
- require current_dir + '/../lib/version'
5
- puts "#{Pattern::HELP::WELLCOME}"
6
- if %w(--version -v).include? ARGV.first
7
- puts "pattern #{Pattern::VERSION::STRING}"
8
- exit(0)
9
- end
10
- require current_dir + '/../lib/configuration'
11
-
12
- if %w(--set -s).include? ARGV.first
13
- configuration = Configuration.new
14
- configuration.execute(ARGV)
15
- exit(0)
16
- end
17
-
18
- if %w(--list -l).include? ARGV.first
19
- configuration = Configuration.new
20
- configuration.list
21
- exit(0)
22
- end
23
-
24
- if (ARGV.empty? || (%w(--help -h).include? ARGV.first))
25
- puts Pattern::HELP::STRING
26
- exit(0)
27
- end
28
-
29
- require current_dir + '/../lib/compositecode'
30
- pattern = CompositeCode.new(Command.new(ARGV))
1
+ #!/usr/bin/env ruby
2
+ current_dir = File.dirname(__FILE__)
3
+
4
+ require current_dir + '/../lib/version'
5
+ puts "#{Pattern::HELP::WELLCOME}"
6
+ if %w(--version -v).include? ARGV.first
7
+ puts "pattern #{Pattern::VERSION::STRING}"
8
+ exit(0)
9
+ end
10
+ require current_dir + '/../lib/configuration'
11
+
12
+ if %w(--set -s).include? ARGV.first
13
+ configuration = Configuration.new
14
+ configuration.execute(ARGV)
15
+ exit(0)
16
+ end
17
+
18
+ if %w(--list -l).include? ARGV.first
19
+ configuration = Configuration.new
20
+ configuration.list
21
+ exit(0)
22
+ end
23
+
24
+ if (ARGV.empty? || (%w(--help -h).include? ARGV.first))
25
+ puts Pattern::HELP::STRING
26
+ exit(0)
27
+ end
28
+
29
+ require current_dir + '/../lib/compositecode'
30
+ pattern = CompositeCode.new(Command.new(ARGV))
31
31
  pattern.execute
@@ -1,25 +1,27 @@
1
-
2
- 2011-01-10
3
- 1. refactoring the code OK
4
- 2. Adding 2or3 template of ruby pattern code.
5
- 3. when no parameter,get help OK
6
- 4. lower_case replace OK
7
- before
8
-
9
- 1. 制作为rubygem
10
- 1.1. 添加可执行文件 OK
11
- 1.2. 添加环境路径 OK
12
- 1.3. 一些bugs OK
13
- 2. 上传 OK
14
- 3. 如果文件已经存在,不进行覆盖 OK
15
- 4. 支持建立文件夹 X
16
- 5. 支持默认模式 OK
17
- 6. 支持添加template目录 OK
18
- 6.1. config类来处理
19
- 6.2. 添加一个
20
- 6.3. 删除一个
21
- 7. 添加新的templates
22
- 8. 列出可用的template OK
23
- 9. help功能 Ok
24
-
25
-
1
+ 2012-01-13
2
+ 1. adding template pattern code
3
+ pattern -t ruby.template -c Report;HTMLReport,PlainTextReport -d target -op output_report,output_body,output_start,output_head,output_body_start,output_line,output_body_end,output_end;output_start,output_head,output_body_start,output_line,output_body_end,output_end
4
+ 2011-01-10
5
+ 1. refactoring the code OK
6
+ 2. Adding 2or3 template of ruby pattern code. just1
7
+ 3. when no parameter,get help OK
8
+ 4. lower_case replace OK
9
+ before
10
+
11
+ 1. 制作为rubygem
12
+ 1.1. 添加可执行文件 OK
13
+ 1.2. 添加环境路径 OK
14
+ 1.3. 一些bugs OK
15
+ 2. 上传 OK
16
+ 3. 如果文件已经存在,不进行覆盖 OK
17
+ 4. 支持建立文件夹 X
18
+ 5. 支持默认模式 OK
19
+ 6. 支持添加template目录 OK
20
+ 6.1. config类来处理
21
+ 6.2. 添加一个
22
+ 6.3. 删除一个
23
+ 7. 添加新的templates
24
+ 8. 列出可用的template OK
25
+ 9. help功能 Ok
26
+
27
+
@@ -1 +1 @@
1
- ../templates
1
+ ../templates
data/lib/command.rb CHANGED
@@ -1,47 +1,47 @@
1
- # commad for send parameter to CompositeCode
2
- # PathCommon is in common.rb
3
-
4
- require File.dirname(__FILE__)+'/common'
5
-
6
- class Command
7
- include PathCommon
8
- attr_accessor :template_dir,:target_dir,:classes,:operations,:base_name
9
-
10
- def initialize(params)
11
- @params = params
12
- get_template_dir
13
- get_target_dir
14
- get_classes
15
- get_operations
16
- end
17
- def get_template_dir
18
- template = get_param("-t") || @params[0]
19
- get_templates(template).each do |dir|
20
- @template_dir = dir if File.directory?(dir)
21
- end
22
- end
23
- def get_target_dir
24
- @target_dir = absolute_path(get_param("-d") || ".")
25
- end
26
- def get_classes
27
- classes = get_param("-c")
28
- if classes
29
- @classes = parse_string( classes )
30
- else
31
- @base_name = @params[1]
32
- @classes = nil
33
- end
34
- end
35
- def get_operations
36
- @operations = parse_string( operations = get_param("-op") || " " )
37
- end
38
-
39
- private
40
- def get_templates(template)
41
- get_path.collect { |dir| dir = join(dir,template) }
42
- end
43
- def get_param(option)
44
- index = @params.index(option)
45
- return index ? @params[index+1] : nil
46
- end
1
+ # commad for send parameter to CompositeCode
2
+ # PathCommon is in common.rb
3
+
4
+ require File.dirname(__FILE__)+'/common'
5
+
6
+ class Command
7
+ include PathCommon
8
+ attr_accessor :template_dir,:target_dir,:classes,:operations,:base_name
9
+
10
+ def initialize(params)
11
+ @params = params
12
+ get_template_dir
13
+ get_target_dir
14
+ get_classes
15
+ get_operations
16
+ end
17
+ def get_template_dir
18
+ template = get_param("-t") || @params[0]
19
+ get_templates(template).each do |dir|
20
+ @template_dir = dir if File.directory?(dir)
21
+ end
22
+ end
23
+ def get_target_dir
24
+ @target_dir = absolute_path(get_param("-d") || ".")
25
+ end
26
+ def get_classes
27
+ classes = get_param("-c")
28
+ if classes
29
+ @classes = parse_string( classes )
30
+ else
31
+ @base_name = @params[1]
32
+ @classes = nil
33
+ end
34
+ end
35
+ def get_operations
36
+ @operations = parse_string( operations = get_param("-op") || " " )
37
+ end
38
+
39
+ private
40
+ def get_templates(template)
41
+ get_path.collect { |dir| dir = join(dir,template) }
42
+ end
43
+ def get_param(option)
44
+ index = @params.index(option)
45
+ return index ? @params[index+1] : nil
46
+ end
47
47
  end
data/lib/common.rb CHANGED
@@ -1,21 +1,21 @@
1
- require 'pathname'
2
-
3
- module PathCommon
4
- PROJECT_DIR = "#{File.dirname(__FILE__)}/../"
5
- CONFIG_FILE = "#{PROJECT_DIR}etc/templates_path.conf"
6
-
7
- def absolute_path(path,dir=Dir.pwd)
8
- Pathname.new(path).relative? ? File.expand_path(path,dir) : path
9
- end
10
- def parse_string(string)
11
- string.split(';').collect { |classes| classes.split(',') }
12
- end
13
- def get_path
14
- File.open(CONFIG_FILE).readlines.collect do |path|
15
- path = absolute_path(path.chomp,File.dirname(__FILE__))
16
- end
17
- end
18
- def join(path,file=".")
19
- File.join(path,file)
20
- end
1
+ require 'pathname'
2
+
3
+ module PathCommon
4
+ PROJECT_DIR = "#{File.dirname(__FILE__)}/../"
5
+ CONFIG_FILE = "#{PROJECT_DIR}etc/templates_path.conf"
6
+
7
+ def absolute_path(path,dir=Dir.pwd)
8
+ Pathname.new(path).relative? ? File.expand_path(path,dir) : path
9
+ end
10
+ def parse_string(string)
11
+ string.split(';').collect { |classes| classes.split(',') }
12
+ end
13
+ def get_path
14
+ File.open(CONFIG_FILE).readlines.collect do |path|
15
+ path = absolute_path(path.chomp,File.dirname(__FILE__))
16
+ end
17
+ end
18
+ def join(path,file=".")
19
+ File.join(path,file)
20
+ end
21
21
  end
data/lib/compositecode.rb CHANGED
@@ -1,82 +1,82 @@
1
- #--
2
- # Copyright (c) 2010 weizhao
3
- #
4
- require File.dirname(__FILE__)+'/code'
5
- require File.dirname(__FILE__)+'/command'
6
-
7
- class CompositeCode < Code
8
- attr_accessor :codes
9
-
10
- def initialize(command)
11
- @template_dir = command.template_dir
12
- @classes = command.classes
13
- @operations = command.operations
14
- @target_dir = command.target_dir
15
- @base_name = command.base_name
16
-
17
- @template_files = Array.new
18
- @template_replace_keys = Array.new
19
-
20
- @codes = []
21
- end
22
- def load_readme
23
- eval(File.read( File.join(@template_dir,"readme") ))
24
- end
25
-
26
- def classes_to_codes
27
- @classes = @classes || @default_classes
28
- default_replace_values = get_default_replace_values
29
- operations = @operations[0]
30
- operations_template = File.open(File.join(@template_dir,"operations")).readlines.join
31
- x = 0
32
-
33
- @classes.each do |template_classes|
34
- template = @template_files[x] || template
35
- key = @template_replace_keys[x] || key
36
- operations = @operations[x] || operations
37
- x+=1
38
-
39
- template_classes.each do |class_name|
40
- replace_values = default_replace_values.clone
41
- replace_values["#{key}"] = class_name
42
- replace_values["lc_#{key}"] = class_name.downcase
43
- replace_values["operations"] = ""
44
- operations.each do |operation|
45
- replace_values["operations"] << operations_template.gsub("#operation#",operation) unless operation == " "
46
- end
47
-
48
- @codes << Code.new( template,
49
- File.join(@target_dir,"#{class_name.downcase}#{File.extname(template)}"),
50
- replace_values )
51
- end
52
- end
53
- return @codes
54
- end
55
-
56
- def get_default_replace_values
57
- x = -1
58
- default_replace_values = Hash.new
59
- @template_replace_keys.each do |key|
60
- default_replace_values["#{key}"] = @classes[x+=1][0]
61
- default_replace_values["lc_#{key}"] = @classes[x][0].downcase
62
- end
63
- return default_replace_values
64
- end
65
-
66
- def template(template_name,replace_key)
67
- @template_files << File.join(@template_dir,template_name)
68
- @template_replace_keys << replace_key
69
- end
70
- def default(*classes_name)
71
- @default_classes = []
72
- classes_name.each do |class_name|
73
- @default_classes << [class_name]
74
- end
75
- end
76
- def execute
77
- load_readme
78
- classes_to_codes
79
- @codes.each { |code| code.execute }
80
- end
81
- end
82
-
1
+ #--
2
+ # Copyright (c) 2010 weizhao
3
+ #
4
+ require File.dirname(__FILE__)+'/code'
5
+ require File.dirname(__FILE__)+'/command'
6
+
7
+ class CompositeCode < Code
8
+ attr_accessor :codes
9
+
10
+ def initialize(command)
11
+ @template_dir = command.template_dir
12
+ @classes = command.classes
13
+ @operations = command.operations
14
+ @target_dir = command.target_dir
15
+ @base_name = command.base_name
16
+
17
+ @template_files = Array.new
18
+ @template_replace_keys = Array.new
19
+
20
+ @codes = []
21
+ end
22
+ def load_readme
23
+ eval(File.read( File.join(@template_dir,"readme") ))
24
+ end
25
+
26
+ def classes_to_codes
27
+ @classes = @classes || @default_classes
28
+ default_replace_values = get_default_replace_values
29
+ operations = @operations[0]
30
+ operations_template = File.open(File.join(@template_dir,"operations")).readlines.join
31
+ x = 0
32
+
33
+ @classes.each do |template_classes|
34
+ template = @template_files[x] || template
35
+ key = @template_replace_keys[x] || key
36
+ operations = @operations[x] || operations
37
+ x+=1
38
+
39
+ template_classes.each do |class_name|
40
+ replace_values = default_replace_values.clone
41
+ replace_values["#{key}"] = class_name
42
+ replace_values["lc_#{key}"] = class_name.downcase
43
+ replace_values["operations"] = ""
44
+ operations.each do |operation|
45
+ replace_values["operations"] << operations_template.gsub("#operation#",operation) unless operation == " "
46
+ end
47
+
48
+ @codes << Code.new( template,
49
+ File.join(@target_dir,"#{class_name.downcase}#{File.extname(template)}"),
50
+ replace_values )
51
+ end
52
+ end
53
+ return @codes
54
+ end
55
+
56
+ def get_default_replace_values
57
+ x = -1
58
+ default_replace_values = Hash.new
59
+ @template_replace_keys.each do |key|
60
+ default_replace_values["#{key}"] = @classes[x+=1][0]
61
+ default_replace_values["lc_#{key}"] = @classes[x][0].downcase
62
+ end
63
+ return default_replace_values
64
+ end
65
+
66
+ def template(template_name,replace_key)
67
+ @template_files << File.join(@template_dir,template_name)
68
+ @template_replace_keys << replace_key
69
+ end
70
+ def default(*classes_name)
71
+ @default_classes = []
72
+ classes_name.each do |class_name|
73
+ @default_classes << [class_name]
74
+ end
75
+ end
76
+ def execute
77
+ load_readme
78
+ classes_to_codes
79
+ @codes.each { |code| code.execute }
80
+ end
81
+ end
82
+
data/lib/configuration.rb CHANGED
@@ -1,47 +1,47 @@
1
- # config templates_path
2
- # class Config is using
3
-
4
- require File.dirname(__FILE__)+'/common'
5
-
6
- class Configuration
7
- include PathCommon
8
-
9
- def initialize
10
- end
11
- def add_path(path)
12
- File.open(CONFIG_FILE,"a") do |file|
13
- path.each { |p| file.puts absolute_path(p) }
14
- end
15
- list_templates_path
16
- end
17
- def remove_path(path)
18
- path_set = get_path - path.collect { |p| p= absolute_path(p) }
19
- File.open(CONFIG_FILE,"w") do |file|
20
- path_set.each { |p| file.puts p }
21
- end
22
- list_templates_path
23
- end
24
- def list
25
- list = []
26
- get_path.uniq.each do |path|
27
- list += Dir.entries(path)
28
- end
29
- puts list-[".",".."]
30
- end
31
- def execute(argv)
32
- parameters = argv[2..100] || [Dir.pwd]
33
- action = argv[1]
34
- add_path(parameters) if action=="add"
35
- remove_path(parameters) if action == "remove"
36
- get_default if action == "default"
37
- end
38
- def get_default
39
- File.open(CONFIG_FILE,"w") do |file|
40
- file.puts "../templates"
41
- end
42
- end
43
- def list_templates_path
44
- puts "\nNow you get templates path:"
45
- puts get_path
46
- end
1
+ # config templates_path
2
+ # class Config is using
3
+
4
+ require File.dirname(__FILE__)+'/common'
5
+
6
+ class Configuration
7
+ include PathCommon
8
+
9
+ def initialize
10
+ end
11
+ def add_path(path)
12
+ File.open(CONFIG_FILE,"a") do |file|
13
+ path.each { |p| file.puts absolute_path(p) }
14
+ end
15
+ list_templates_path
16
+ end
17
+ def remove_path(path)
18
+ path_set = get_path - path.collect { |p| p= absolute_path(p) }
19
+ File.open(CONFIG_FILE,"w") do |file|
20
+ path_set.each { |p| file.puts p }
21
+ end
22
+ list_templates_path
23
+ end
24
+ def list
25
+ list = []
26
+ get_path.uniq.each do |path|
27
+ list += Dir.entries(path)
28
+ end
29
+ puts list-[".",".."]
30
+ end
31
+ def execute(argv)
32
+ parameters = argv[2..100] || [Dir.pwd]
33
+ action = argv[1]
34
+ add_path(parameters) if action=="add"
35
+ remove_path(parameters) if action == "remove"
36
+ get_default if action == "default"
37
+ end
38
+ def get_default
39
+ File.open(CONFIG_FILE,"w") do |file|
40
+ file.puts "../templates"
41
+ end
42
+ end
43
+ def list_templates_path
44
+ puts "\nNow you get templates path:"
45
+ puts get_path
46
+ end
47
47
  end