jdl 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.md +39 -0
  2. data/bin/jdl +6 -9
  3. data/lib/jdl/version.rb +1 -1
  4. data/lib/jdl.rb +35 -17
  5. data/t.txt +1 -0
  6. metadata +4 -3
data/README.md CHANGED
@@ -3,6 +3,13 @@
3
3
  <!-- TODO: Write a gem description -->
4
4
  根据指定目录,扫描内部扩展名为*的所有文件,并输出到jdl.js内,主要用于js测试
5
5
 
6
+ TODO:
7
+
8
+
9
+ 已完成:
10
+
11
+ - 增加生成模板,可以从本地读取(v0.0.4已实现)
12
+
6
13
  ## Installation
7
14
 
8
15
  Add this line to your application's Gemfile:
@@ -25,11 +32,43 @@ Or install it yourself as:
25
32
  -p, --path Set options as path
26
33
  -e, --file_ex Set options as file_ex
27
34
  -o, --output Set options as :output_name
35
+ -d. --verbose print debug log
28
36
 
29
37
 
30
38
  - '-p' 指定扫描路径 : 默认值 .
31
39
  - '-e' 指定扫描文件的扩展名 : 默认值 js
32
40
  - '-o' 指定输出文件名称 : 默认值 jdl.js
41
+ - '-t' 指定模板名称 : 默认值 无
42
+ - '-d' 是否打印日志 : 默认值 false
43
+
44
+
45
+ ### 模板用法
46
+
47
+ 创建t.txt
48
+
49
+ <aa>##item##<aa>
50
+
51
+ 生成的文件
52
+
53
+ ➜ jdl git:(master) ✗ cat jdl.js
54
+ <aa>./test/collection.js<aa>
55
+ <aa>./test/environment.js<aa>
56
+ <aa>./test/events.js<aa>
57
+ <aa>./test/model.js<aa>
58
+ <aa>./test/noconflict.js<aa>
59
+ <aa>./test/router.js<aa>
60
+ <aa>./test/sync.js<aa>
61
+ <aa>./test/vendor/backbone.js<aa>
62
+ <aa>./test/vendor/jquery.js<aa>
63
+ <aa>./test/vendor/json2.js<aa>
64
+ <aa>./test/vendor/qunit.js<aa>
65
+ <aa>./test/vendor/runner.js<aa>
66
+ <aa>./test/vendor/underscore.js<aa>
67
+ <aa>./test/view.js<aa>
68
+
69
+ 测试方法
70
+
71
+ ruby -Ilib bin/jdl -p . -t t.txt
33
72
 
34
73
  ## Test
35
74
 
data/bin/jdl CHANGED
@@ -38,6 +38,11 @@ option_parser = OptionParser.new do |opts|
38
38
  options[:file_ex] = value
39
39
  end
40
40
 
41
+ opts.on('-t t_name', '--template t_name', 'Set options as template_name') do |value|
42
+ # 这个部分就是使用这个Option后执行的代码
43
+ options[:template_name] = value
44
+ end
45
+
41
46
  opts.on('-o output', '--output output', 'Set options as output_name') do |value|
42
47
  # 这个部分就是使用这个Option后执行的代码
43
48
  options[:output_name] = value
@@ -50,13 +55,5 @@ option_parser = OptionParser.new do |opts|
50
55
  end.parse!
51
56
 
52
57
  # puts options.inspect
53
- path = options[:path]
54
- file_ex = options[:file_ex]
55
- output_name = options[:output_name]
56
-
57
- p "path = #{path}" if(options[:debug])
58
- p "fname = #{file_ex}" if(options[:debug])
59
- p "output_name = #{output_name}" if(options[:debug])
60
58
 
61
- File.delete(output_name) if File.exist?(output_name)
62
- Jdl.getfiles(path ,file_ex ,output_name)
59
+ Jdl.parse(options)
data/lib/jdl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jdl
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/jdl.rb CHANGED
@@ -1,14 +1,24 @@
1
1
  require "jdl/version"
2
2
 
3
3
  module Jdl
4
- # Your code goes here...
5
- # create runtest.rb for rails.
6
- # e.g. :(the name of this file is createruntest.rb)
7
- # #>ruby createruntest.rb ./test > runtest.sh
8
- # #>chmod 777 runtest.sh
9
- #
10
- def self.getfiles(path,fname,output_name)
4
+
5
+ def self.parse(options)
6
+ path = options[:path]
7
+ file_ex = options[:file_ex]
8
+ output_name = options[:output_name]
9
+ template_name = options[:template_name]
11
10
 
11
+ p "path = #{path}" if(options[:debug])
12
+ p "file_ex = #{file_ex}" if(options[:debug])
13
+ p "output_name = #{output_name}" if(options[:debug])
14
+
15
+ File.delete(options[:output_name]) if File.exist?(options[:output_name])
16
+
17
+ self.getfiles(path,file_ex,output_name,template_name);
18
+
19
+ end
20
+
21
+ def self.getfiles(path,fname,output_name,template_name)
12
22
  re = []
13
23
  allre = []
14
24
  Dir.foreach(path) do |f|
@@ -16,15 +26,12 @@ module Jdl
16
26
  end
17
27
  allre.each do |f|
18
28
  fullfilename = path + "/" + f
19
-
20
- # p fullfilename
21
-
22
29
  if f == "." or f == ".."
23
30
 
24
31
  elsif File.directory?(fullfilename)
25
32
  resub = []
26
- resub = getfiles(fullfilename,fname,output_name)
27
-
33
+ resub = getfiles(fullfilename,fname,output_name,template_name)
34
+
28
35
  if resub.length > 0
29
36
  ref = {}
30
37
  ref[f] = resub
@@ -32,21 +39,32 @@ module Jdl
32
39
  end
33
40
 
34
41
  elsif File.exist?(fullfilename) and (f =~ /\.#{fname}$/) # only rb file
35
- self.print_arr(fullfilename,output_name)
42
+ self.print_arr(fullfilename,output_name,template_name)
36
43
  # p ff
37
44
  re << f
38
45
  # p fullfilename
39
46
  end
40
47
  end
41
48
 
42
- # p extname
43
49
  return re
44
50
  end
45
-
46
51
 
47
- def self.print_arr(content,filename='jdl.js')
52
+ def self.print_arr(content,filename='jdl.js',template_name)
48
53
  f=open(filename,"a")
49
- f.puts("<script src='#{content}'></script>")
54
+
55
+ if(template_name)
56
+ #如果有模板名称,则读取模板内容,替换内部的item
57
+ t_content = ''
58
+ IO.foreach(template_name) {|x|
59
+ t_content << x
60
+ }
61
+
62
+ # p t_content
63
+ f.puts(t_content.gsub(/##item##/, content))
64
+ else
65
+ f.puts("<script src='#{content}'></script>")
66
+ end
67
+
50
68
  f.close
51
69
  end
52
70
  end
data/t.txt ADDED
@@ -0,0 +1 @@
1
+ <aa>##item##<aa>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,6 +60,7 @@ files:
60
60
  - jdl.gemspec
61
61
  - lib/jdl.rb
62
62
  - lib/jdl/version.rb
63
+ - t.txt
63
64
  - test/collection.js
64
65
  - test/environment.js
65
66
  - test/events.js
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
93
  version: '0'
93
94
  segments:
94
95
  - 0
95
- hash: 2541092676907615134
96
+ hash: -3982637811865650994
96
97
  required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  none: false
98
99
  requirements:
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  version: '0'
102
103
  segments:
103
104
  - 0
104
- hash: 2541092676907615134
105
+ hash: -3982637811865650994
105
106
  requirements: []
106
107
  rubyforge_project:
107
108
  rubygems_version: 1.8.25