pattern 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/DOCS/todolist.txt +10 -0
- data/LICENSE +0 -0
- data/README +32 -0
- data/README.cn +26 -0
- data/Rakefile +8 -0
- data/bin/pattern +12 -0
- data/etc/templates_path.conf +2 -0
- data/lib/code.rb +34 -0
- data/lib/command.rb +51 -0
- data/lib/compositecode.rb +80 -0
- data/lib/patterncode.rb +7 -0
- data/lib/version.rb +9 -0
- data/pattern.gemspec +27 -0
- data/templates/ruby.composite/component.rb +10 -0
- data/templates/ruby.composite/composite.rb +10 -0
- data/templates/ruby.composite/compositeobject.rb +10 -0
- data/templates/ruby.composite/leaf.rb +10 -0
- data/templates/ruby.composite/operations +3 -0
- data/templates/ruby.composite/readme +5 -0
- data/test/code_spec.rb +33 -0
- data/test/command_spec.rb +27 -0
- data/test/compositecode_spec.rb +103 -0
- data/test/patterncode_spec.rb +33 -0
- metadata +95 -0
data/DOCS/todolist.txt
ADDED
data/LICENSE
ADDED
File without changes
|
data/README
ADDED
@@ -0,0 +1,32 @@
|
|
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 [-t tempate_dir] [main_class_name]
|
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 -t ruby.composite Task
|
19
|
+
*pattern -t ruby.composite -d target -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute
|
20
|
+
complex model(pattern_file):
|
21
|
+
|
22
|
+
== Future
|
23
|
+
Sharing pattern templates on website.
|
24
|
+
|
25
|
+
== Author
|
26
|
+
|
27
|
+
Copyright 2010 @ weizhao
|
28
|
+
mailto: azhao.1981@gmail.com
|
29
|
+
|
30
|
+
== licese
|
31
|
+
|
32
|
+
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
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
== EasyPattern
|
2
|
+
这是一个用于自动生成设计模式/数据结构的rubygem工具,其特点是支持自定义模板,这使您学习设计模式和数据结构更加方便。
|
3
|
+
|
4
|
+
== Useage
|
5
|
+
简单模式
|
6
|
+
pattern [-t tempate_dir] [main_class_name]
|
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 -t ruby.composite Task
|
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
ADDED
data/bin/pattern
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
current_dir = File.dirname(__FILE__)
|
4
|
+
|
5
|
+
require current_dir + '/../lib/version'
|
6
|
+
if %w(--version -v).include? ARGV.first
|
7
|
+
puts "pattern #{Pattern::VERSION::STRING}"
|
8
|
+
exit(0)
|
9
|
+
end
|
10
|
+
require current_dir + '/../lib/compositecode'
|
11
|
+
pattern = CompositeCode.new(Command.new(ARGV))
|
12
|
+
pattern.execute
|
data/lib/code.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010 weizhao
|
3
|
+
#
|
4
|
+
class Code
|
5
|
+
attr_accessor :template_file_name,:target_file_name,:replace_values
|
6
|
+
def initialize(template_file_name,target_file_bame,replace_values)
|
7
|
+
@template_file_name = template_file_name
|
8
|
+
@target_file_name = target_file_bame
|
9
|
+
@replace_values = replace_values
|
10
|
+
end
|
11
|
+
def replace_template
|
12
|
+
template_string = File.open(@template_file_name).readlines.join
|
13
|
+
|
14
|
+
@replace_values.each do |key,value|
|
15
|
+
template_string = template_string.gsub("##{key}#",value)
|
16
|
+
end
|
17
|
+
return template_string
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_code
|
21
|
+
if File.exist?(@target_file_name)
|
22
|
+
puts "* File #{@target_file_name} exist."
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
File.open(@target_file_name,"w") do |file|
|
26
|
+
puts "* Create new file #{@target_file_name}."
|
27
|
+
file.puts replace_template
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute
|
32
|
+
generate_code
|
33
|
+
end
|
34
|
+
end
|
data/lib/command.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# commad for send parameter to CompositeCode
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
class Command
|
5
|
+
attr_accessor :template_dir,:target_dir,:classes,:operations,:base_name
|
6
|
+
def initialize(params)
|
7
|
+
@params = params
|
8
|
+
get_template_dir
|
9
|
+
get_target_dir
|
10
|
+
get_classes
|
11
|
+
get_operations
|
12
|
+
end
|
13
|
+
def get_template_dir
|
14
|
+
get_templates_dirs(get_template_dir_from_params).each do |dir|
|
15
|
+
@template_dir = dir if File.directory?(dir)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def get_classes
|
19
|
+
classes = get_param("-c")
|
20
|
+
if classes
|
21
|
+
@classes = parse_string( classes )
|
22
|
+
else
|
23
|
+
@base_name = @params[1]
|
24
|
+
@classes = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def get_operations
|
28
|
+
@operations = parse_string( operations = get_param("-op") || " " )
|
29
|
+
end
|
30
|
+
def get_templates_dirs(template)
|
31
|
+
File.open("#{File.dirname(__FILE__)}/../etc/templates_path.conf").readlines.collect do |line|
|
32
|
+
line = absolute_path(File.join(line.chomp,template),File.dirname(__FILE__))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def get_target_dir
|
36
|
+
@target_dir = absolute_path(get_param("-d") || ".")
|
37
|
+
end
|
38
|
+
def get_template_dir_from_params
|
39
|
+
return get_param("-t") || @params[0]
|
40
|
+
end
|
41
|
+
def get_param(option)
|
42
|
+
index = @params.index(option)
|
43
|
+
return index ? @params[index+1] : nil
|
44
|
+
end
|
45
|
+
def absolute_path(path,dir=Dir.pwd)
|
46
|
+
Pathname.new(path).relative? ? File.expand_path(path,dir) : path
|
47
|
+
end
|
48
|
+
def parse_string(string)
|
49
|
+
string.split(';').collect { |classes| classes.split(',') }
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,80 @@
|
|
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["operations"] = ""
|
43
|
+
operations.each do |operation|
|
44
|
+
replace_values["operations"] << operations_template.gsub("#operation#",operation) unless operation == " "
|
45
|
+
end
|
46
|
+
|
47
|
+
@codes << Code.new( template,
|
48
|
+
File.join(@target_dir,"#{class_name.downcase}#{File.extname(template)}"),
|
49
|
+
replace_values )
|
50
|
+
end
|
51
|
+
end
|
52
|
+
return @codes
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_default_replace_values
|
56
|
+
x = -1
|
57
|
+
default_replace_values = Hash.new
|
58
|
+
@template_replace_keys.each do |key|
|
59
|
+
default_replace_values["#{key}"] = @classes[x+=1][0]
|
60
|
+
end
|
61
|
+
return default_replace_values
|
62
|
+
end
|
63
|
+
|
64
|
+
def template(template_name,replace_key)
|
65
|
+
@template_files << File.join(@template_dir,template_name)
|
66
|
+
@template_replace_keys << replace_key
|
67
|
+
end
|
68
|
+
def default(*classes_name)
|
69
|
+
@default_classes = []
|
70
|
+
classes_name.each do |class_name|
|
71
|
+
@default_classes << [class_name]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
def execute
|
75
|
+
load_readme
|
76
|
+
classes_to_codes
|
77
|
+
@codes.each { |code| code.execute }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/lib/patterncode.rb
ADDED
data/lib/version.rb
ADDED
data/pattern.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rake'
|
2
|
+
spec = Gem::Specification.new
|
3
|
+
#-----------------------------
|
4
|
+
# Package information
|
5
|
+
#-----------------------------
|
6
|
+
spec.name = 'pattern'
|
7
|
+
spec.version = '0.9.0'
|
8
|
+
spec.executables << 'pattern'
|
9
|
+
spec.has_rdoc = true
|
10
|
+
spec.rdoc_options << '--title' << 'Pattern' <<
|
11
|
+
'--line-numbers'
|
12
|
+
spec.rubyforge_project = 'pattern'
|
13
|
+
spec.homepage = 'http://pattern.rubyforge.org'
|
14
|
+
spec.files = FileList['lib/*.rb', 'bin/*', '[A-Z]*', 'test/*','templates/**/*','etc/*','DOCS/*'].to_a
|
15
|
+
spec.test_files = Dir.glob('test/*_spec.rb')
|
16
|
+
spec.summary = 'auto code tools.'
|
17
|
+
spec.description = <<-EOF
|
18
|
+
Tool for coding/learning pattern/data structure
|
19
|
+
EOF
|
20
|
+
#-----------------------------
|
21
|
+
# Author information
|
22
|
+
#-----------------------------
|
23
|
+
spec.author = 'weizhao'
|
24
|
+
spec.email = 'azhao.1981@gmail.com'
|
25
|
+
|
26
|
+
|
27
|
+
|
data/test/code_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010 weizhao
|
3
|
+
#
|
4
|
+
require File.dirname(__FILE__) + '/../lib/code'
|
5
|
+
|
6
|
+
describe Code do
|
7
|
+
before(:each) do
|
8
|
+
template_file_name = "E:/dev/easypattern/templates/ruby.composite/component.rb"
|
9
|
+
target_file_name = "E:/dev/easypattern/temp/task.rb"
|
10
|
+
@target_file_name_test = target_file_name
|
11
|
+
replace_values = {"class_name"=>"Task","operations"=>" def execute\n \t\n end\n"}
|
12
|
+
@component_code = Code.new(template_file_name,target_file_name,replace_values)
|
13
|
+
end
|
14
|
+
it "1. replace_template should return template contain 'Task' & 'execute' " do
|
15
|
+
template = @component_code.replace_template
|
16
|
+
(/Task/ =~ template).should > 0
|
17
|
+
(/execute/ =~ template).should > 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "2. generate_code should create a new file" do
|
21
|
+
@component_code.generate_code
|
22
|
+
template = File.open(@target_file_name_test).readlines.join
|
23
|
+
(/Task/ =~ template).should be > 0
|
24
|
+
(/execute/ =~ template).should be > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it "3. execute will do generate_code " do
|
28
|
+
@component_code.execute
|
29
|
+
template = File.open(@target_file_name_test).readlines.join
|
30
|
+
(/Task/ =~ template).should be > 0
|
31
|
+
(/execute/ =~ template).should be > 0
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/command'
|
2
|
+
|
3
|
+
describe Command do
|
4
|
+
before(:each) do
|
5
|
+
params = "-t ruby.composite -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute".split(" ")
|
6
|
+
@command = Command.new(params)
|
7
|
+
end
|
8
|
+
it "1. get_template_dir_from_params should return 'ruby.composite' " do
|
9
|
+
@command.get_template_dir_from_params.should == "ruby.composite"
|
10
|
+
end
|
11
|
+
it "2. get_templates_dirs should return ['../templates','../templates2']" do
|
12
|
+
@command.get_templates_dirs(@command.get_template_dir_from_params).should ==
|
13
|
+
['E:/dev/easypattern/templates/ruby.composite',
|
14
|
+
'E:/dev/easypattern/templates2/ruby.composite']
|
15
|
+
end
|
16
|
+
it "3. Command.new should get right parameter form param" do
|
17
|
+
@command.template_dir.should == "E:/dev/easypattern/templates/ruby.composite"
|
18
|
+
@command.classes.should == [["Task"],["compositeTask"],
|
19
|
+
["AddDryIngredientsTask","MixTask"],["MakeBatterTask"]]
|
20
|
+
@command.operations.should == [['execute']]
|
21
|
+
@command.target_dir.should == "E:/dev/easypattern"
|
22
|
+
end
|
23
|
+
it "4. absolute_path should return absolute path " do
|
24
|
+
@command.absolute_path("../templates/ruby.composite","./bin/../lib").should == "E:/dev/easypattern/templates/ruby.composite"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/compositecode'
|
2
|
+
|
3
|
+
describe CompositeCode do
|
4
|
+
before(:each) do
|
5
|
+
params = "-t ruby.composite -d E:/dev/easypattern/target -c Task;CompositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute,test".split(" ")
|
6
|
+
@command = Command.new(params)
|
7
|
+
@target_dir = "E:/dev/easypattern/target"
|
8
|
+
@compositecode = CompositeCode.new(@command)
|
9
|
+
end
|
10
|
+
it "1. classes_to_codes should return codes " do
|
11
|
+
@compositecode.load_readme
|
12
|
+
@compositecode.classes_to_codes.length.should == 5
|
13
|
+
code = @compositecode.codes[0]
|
14
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/component.rb"
|
15
|
+
code.target_file_name.should == "E:/dev/easypattern/target/task.rb"
|
16
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
17
|
+
"leaf_name"=>"AddDryIngredientsTask",
|
18
|
+
"composite_object_name"=>"MakeBatterTask",
|
19
|
+
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
20
|
+
}
|
21
|
+
code = @compositecode.codes[1]
|
22
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/composite.rb"
|
23
|
+
code.target_file_name.should == "E:/dev/easypattern/target/compositetask.rb"
|
24
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
25
|
+
"leaf_name"=>"AddDryIngredientsTask",
|
26
|
+
"composite_object_name"=>"MakeBatterTask",
|
27
|
+
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
28
|
+
}
|
29
|
+
code = @compositecode.codes[2]
|
30
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/leaf.rb"
|
31
|
+
code.target_file_name.should == "E:/dev/easypattern/target/adddryingredientstask.rb"
|
32
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
33
|
+
"leaf_name"=>"AddDryIngredientsTask",
|
34
|
+
"composite_object_name"=>"MakeBatterTask",
|
35
|
+
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
36
|
+
}
|
37
|
+
code = @compositecode.codes[3]
|
38
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/leaf.rb"
|
39
|
+
code.target_file_name.should == "E:/dev/easypattern/target/mixtask.rb"
|
40
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
41
|
+
"leaf_name"=>"MixTask",
|
42
|
+
"composite_object_name"=>"MakeBatterTask",
|
43
|
+
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
44
|
+
}
|
45
|
+
code = @compositecode.codes[4]
|
46
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/compositeobject.rb"
|
47
|
+
code.target_file_name.should == "E:/dev/easypattern/target/makebattertask.rb"
|
48
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
49
|
+
"leaf_name"=>"AddDryIngredientsTask",
|
50
|
+
"composite_object_name"=>"MakeBatterTask",
|
51
|
+
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
it "2. default params should return base_name and default_classes " do
|
55
|
+
params = "ruby.composite Task -d E:/dev/easypattern/target".split(" ")
|
56
|
+
@compositecode = CompositeCode.new(Command.new(params))
|
57
|
+
@compositecode.load_readme
|
58
|
+
@compositecode.classes_to_codes.length.should == 4
|
59
|
+
code = @compositecode.codes[0]
|
60
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/component.rb"
|
61
|
+
code.target_file_name.should == "E:/dev/easypattern/target/task.rb"
|
62
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
63
|
+
"leaf_name"=>"LeafTask",
|
64
|
+
"composite_object_name"=>"CompositeObjectTask",
|
65
|
+
"operations"=>""
|
66
|
+
}
|
67
|
+
code = @compositecode.codes[1]
|
68
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/composite.rb"
|
69
|
+
code.target_file_name.should == "E:/dev/easypattern/target/compositetask.rb"
|
70
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
71
|
+
"leaf_name"=>"LeafTask",
|
72
|
+
"composite_object_name"=>"CompositeObjectTask",
|
73
|
+
"operations"=>""
|
74
|
+
}
|
75
|
+
code = @compositecode.codes[2]
|
76
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/leaf.rb"
|
77
|
+
code.target_file_name.should == "E:/dev/easypattern/target/leaftask.rb"
|
78
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
79
|
+
"leaf_name"=>"LeafTask",
|
80
|
+
"composite_object_name"=>"CompositeObjectTask",
|
81
|
+
"operations"=>""
|
82
|
+
}
|
83
|
+
code = @compositecode.codes[3]
|
84
|
+
code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/compositeobject.rb"
|
85
|
+
code.target_file_name.should == "E:/dev/easypattern/target/compositeobjecttask.rb"
|
86
|
+
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
87
|
+
"leaf_name"=>"LeafTask",
|
88
|
+
"composite_object_name"=>"CompositeObjectTask",
|
89
|
+
"operations"=>""
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010 weizhao
|
3
|
+
#
|
4
|
+
require File.dirname(__FILE__) + '/../lib/patterncode'
|
5
|
+
|
6
|
+
describe PatternCode do
|
7
|
+
before(:each) do
|
8
|
+
template_file_name = "E:/dev/easypattern/templates/ruby.composite/component.rb"
|
9
|
+
target_file_name = "E:/dev/easypattern/temp/task.rb"
|
10
|
+
@target_file_name_test = target_file_name
|
11
|
+
replace_values = {"class_name"=>"Task","operations"=>" def execute\n \t\n end\n"}
|
12
|
+
@component_code = PatternCode.new(template_file_name,target_file_name,replace_values)
|
13
|
+
end
|
14
|
+
it "1. replace_template should return template contain 'Task' & 'execute' " do
|
15
|
+
template = @component_code.replace_template
|
16
|
+
(/Task/ =~ template).should be > 0
|
17
|
+
(/execute/ =~ template).should be > 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "2. generate_code should create a new file" do
|
21
|
+
@component_code.generate_code
|
22
|
+
template = File.open(@target_file_name_test).readlines.join
|
23
|
+
(/Task/ =~ template).should be > 0
|
24
|
+
(/execute/ =~ template).should be > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it "3. execute will do generate_code " do
|
28
|
+
@component_code.execute
|
29
|
+
template = File.open(@target_file_name_test).readlines.join
|
30
|
+
(/Task/ =~ template).should be > 0
|
31
|
+
(/execute/ =~ template).should be > 0
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pattern
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- weizhao
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-05 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: " Tool for coding/learning pattern/data structure\n"
|
23
|
+
email: azhao.1981@gmail.com
|
24
|
+
executables:
|
25
|
+
- pattern
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/code.rb
|
32
|
+
- lib/command.rb
|
33
|
+
- lib/compositecode.rb
|
34
|
+
- lib/patterncode.rb
|
35
|
+
- lib/version.rb
|
36
|
+
- bin/pattern
|
37
|
+
- LICENSE
|
38
|
+
- pattern-0.9.0.gem
|
39
|
+
- pattern.gemspec
|
40
|
+
- Rakefile
|
41
|
+
- README
|
42
|
+
- README.cn
|
43
|
+
- test/code_spec.rb
|
44
|
+
- test/command_spec.rb
|
45
|
+
- test/compositecode_spec.rb
|
46
|
+
- test/patterncode_spec.rb
|
47
|
+
- templates/ruby.composite/component.rb
|
48
|
+
- templates/ruby.composite/composite.rb
|
49
|
+
- templates/ruby.composite/compositeobject.rb
|
50
|
+
- templates/ruby.composite/leaf.rb
|
51
|
+
- templates/ruby.composite/operations
|
52
|
+
- templates/ruby.composite/readme
|
53
|
+
- etc/templates_path.conf
|
54
|
+
- DOCS/todolist.txt
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://pattern.rubyforge.org
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --title
|
62
|
+
- Pattern
|
63
|
+
- --line-numbers
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: pattern
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: auto code tools.
|
91
|
+
test_files:
|
92
|
+
- test/code_spec.rb
|
93
|
+
- test/command_spec.rb
|
94
|
+
- test/compositecode_spec.rb
|
95
|
+
- test/patterncode_spec.rb
|