jdl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
+ jdl.js
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jdl.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 shiren1118
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,54 @@
1
+ # Jdl
2
+
3
+ <!-- TODO: Write a gem description -->
4
+ 根据指定目录,扫描内部扩展名为*的所有文件,并输出到jdl.js内,主要用于js测试
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'jdl'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install jdl
19
+
20
+ ## Usage
21
+
22
+
23
+ ➜ jdl git:(master) ✗ jdl --help
24
+ import js from directory loader .
25
+ -p, --path Set options as path
26
+ -e, --file_ex Set options as file_ex
27
+ -o, --output Set options as :output_name
28
+
29
+
30
+ - '-p' 指定扫描路径 : 默认值 .
31
+ - '-e' 指定扫描文件的扩展名 : 默认值 js
32
+ - '-o' 指定输出文件名称 : 默认值 jdl.js
33
+
34
+ ## Test
35
+
36
+ ruby -Ilib bin/jdl
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
45
+
46
+ ## License
47
+
48
+ this project is released under the MIT license:
49
+
50
+ http://www.opensource.org/licenses/mit-license.php
51
+
52
+
53
+ ## 欢迎fork和反馈
54
+ 在issue提问或邮件shiren1118@126.com
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/jdl ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'jdl'
5
+
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ option_parser = OptionParser.new do |opts|
10
+ # 这里是这个命令行工具的帮助信息
11
+ opts.banner = 'import js from directory loader .'
12
+
13
+ # opts.on('-f sourceFileNAME', '--name sourceFileNAME', 'Pass-in source file name') do |value|
14
+ # # options[:fname] = value
15
+ #
16
+ # # Mdpreview.hi(path+'/'+value)
17
+ # end
18
+ options[:path] = '.'
19
+ options[:file_ex] = 'js'
20
+ options[:output_name] = 'jdl.js'
21
+ # Option 作为flag,带一组用逗号分割的arguments,用于将arguments作为数组解析
22
+ opts.on('-t path,file_ex,output_name', '--tranfer path,file_ex,output_name', Array, 'List of 3 arguments') do |value|
23
+ options[:array] = value
24
+ # p 'start'
25
+ #Dir.foreach(".") {|x| puts "Got #{x}" }
26
+ options[:path] = options[:array][0]
27
+ options[:file_ex] = options[:array][1]
28
+ options[:output_name] = options[:array][2]
29
+ end
30
+
31
+ opts.on('-p', '--path', 'Set options as path') do |value|
32
+ # 这个部分就是使用这个Option后执行的代码
33
+ options[:path] = value
34
+
35
+ end
36
+ opts.on('-e', '--file_ex', 'Set options as file_ex') do |value|
37
+ # 这个部分就是使用这个Option后执行的代码
38
+ options[:file_ex] = value
39
+ end
40
+
41
+ opts.on('-o', '--output', 'Set options as output_name') do |value|
42
+ # 这个部分就是使用这个Option后执行的代码
43
+ options[:output_name] = value
44
+ end
45
+
46
+
47
+ path = options[:path]
48
+ file_ex = options[:file_ex]
49
+ output_name = options[:output_name]
50
+
51
+ File.delete(output_name) if File.exist?(output_name)
52
+ Jdl.getfiles(path ,file_ex ,output_name)
53
+
54
+ end.parse!
55
+
56
+ # puts options.inspect
57
+
58
+
59
+
60
+
data/jdl.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jdl/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jdl"
8
+ spec.version = Jdl::VERSION
9
+ spec.authors = ["shiren1118"]
10
+ spec.email = ["shiren1118@126.com"]
11
+ spec.description = %q{根据指定目录,扫描内部扩展名为*的所有文件,并输出到jdl.js内}
12
+ spec.summary = %q{根据指定目录,扫描内部扩展名为*的所有文件,并输出到jdl.js内,主要用于js测试}
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.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Jdl
2
+ VERSION = "0.0.1"
3
+ end
data/lib/jdl.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "jdl/version"
2
+
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)
11
+ re = []
12
+ allre = []
13
+ ff = []
14
+ Dir.foreach(path) do |f|
15
+ allre << f
16
+ end
17
+ allre.each do |f|
18
+ fullfilename = path + "/" + f
19
+
20
+ # p fullfilename
21
+
22
+ if f == "." or f == ".."
23
+
24
+ elsif File.directory?(fullfilename)
25
+ resub = []
26
+ resub = getfiles(fullfilename,fname,output_name)
27
+
28
+ if resub.length > 0
29
+ ref = {}
30
+ ref[f] = resub
31
+ re << ref
32
+ end
33
+
34
+ elsif File.exist?(fullfilename) and (f =~ /\.#{fname}$/) # only rb file
35
+ self.print_arr(fullfilename,output_name)
36
+ # p ff
37
+ re << f
38
+ ff << fullfilename
39
+ end
40
+ end
41
+
42
+ # p extname
43
+ return re
44
+ # return ff
45
+ end
46
+
47
+
48
+ def self.print_arr(content,filename='jdl.js')
49
+ f=open(filename,"a")
50
+ f.puts(content)
51
+ f.close
52
+ end
53
+ end