source-tools 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGES +10 -0
- data/README +54 -0
- data/Rakefile +53 -0
- data/TODO +4 -0
- data/bin/source-tools +3 -0
- data/lib/source-tools.rb +112 -0
- data/lib/source-tools/bin.rb +7 -0
- data/lib/source-tools/default.rb +5 -0
- data/lib/source-tools/tasks.rb +4 -0
- data/lib/source-tools/tasks/chmod.rb +19 -0
- data/lib/source-tools/tasks/html_wrap.rb +15 -0
- data/lib/source-tools/tasks/ruby_magic_encoding.rb +17 -0
- data/lib/source-tools/tasks/strip.rb +31 -0
- data/lib/source-tools/tasks/template.rb +29 -0
- data/lib/source-tools/templates/t.bashrc.erb +5 -0
- data/lib/source-tools/templates/t.config/fish/config.fish.erb +6 -0
- data/lib/source-tools/templates/t.gemrc.erb +4 -0
- data/lib/source-tools/templates/t.git/hooks/post-receive.erb +7 -0
- data/lib/source-tools/templates/t.gitconfig.erb +14 -0
- data/lib/source-tools/templates/t.gitignore.erb +15 -0
- data/lib/source-tools/templates/t.profile.erb +39 -0
- data/lib/source-tools/templates/t.screenrc.erb +1 -0
- data/lib/source-tools/templates/t.vimrc.erb +37 -0
- data/lib/source-tools/templates/tRakefile.erb +47 -0
- data/lib/source-tools/templates/tconfig/mime.types.erb +104 -0
- data/lib/source-tools/templates/tconfig/nginx.conf.erb +178 -0
- data/lib/source-tools/version.rb +3 -0
- data/source-tools.gemspec +35 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- metadata +126 -0
data/CHANGES
ADDED
data/README
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= source-tools 0.6
|
2
|
+
by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
|
3
|
+
godfat (XD) godfat.org
|
4
|
+
|
5
|
+
== LINKS:
|
6
|
+
|
7
|
+
* github-project[http://github.com/godfat/source-tools]
|
8
|
+
* rubyforge-project[http://rubyforge.org/projects/ludy]
|
9
|
+
|
10
|
+
== DESCRIPTION:
|
11
|
+
|
12
|
+
source code tools collection
|
13
|
+
|
14
|
+
== FEATURES:
|
15
|
+
|
16
|
+
$ source-tools
|
17
|
+
source-tools st:chmod # fix files(644) and directories(755) permission recursively.
|
18
|
+
source-tools st:html_wrap[glob] # Wrap html with comments at the beginning and the end of file (for tracking partial template on generated html)
|
19
|
+
source-tools st:strip[spaces] # Strip trailing whitespace from source files, also normalize tabs to spaces, and an newline at end of file
|
20
|
+
source-tools st:t:.bashrc # create a common .bashrc file
|
21
|
+
source-tools st:t:.gemrc[project] # create a user gem only .gemrc file
|
22
|
+
source-tools st:t:.gitconfig[project] # create a common .gitconfig file
|
23
|
+
source-tools st:t:.gitignore # create a common .gitignore file
|
24
|
+
source-tools st:t:.vimrc # create a common .vimrc file
|
25
|
+
source-tools st:t:Rakefile[project] # create a Rakefile template for bones.
|
26
|
+
source-tools st:t:config.fish # create a common config.fish file
|
27
|
+
source-tools st:t:mime.types # create a common mime.types file
|
28
|
+
source-tools st:t:nginx.conf[project] # create an nginx config file
|
29
|
+
|
30
|
+
== SYNOPSIS:
|
31
|
+
|
32
|
+
== REQUIREMENTS:
|
33
|
+
|
34
|
+
== INSTALL:
|
35
|
+
|
36
|
+
* gem install source-tools
|
37
|
+
|
38
|
+
== LICENSE:
|
39
|
+
|
40
|
+
Apache License 2.0
|
41
|
+
|
42
|
+
Copyright (c) 2008-2009, Lin Jen-Shin (a.k.a. godfat 真常)
|
43
|
+
|
44
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
45
|
+
you may not use this file except in compliance with the License.
|
46
|
+
You may obtain a copy of the License at
|
47
|
+
|
48
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
49
|
+
|
50
|
+
Unless required by applicable law or agreed to in writing, software
|
51
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
52
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
53
|
+
See the License for the specific language governing permissions and
|
54
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
SUDO = '' # this prevent `rake gem:install` to use sudo
|
4
|
+
|
5
|
+
gem 'bones', '<3.0'
|
6
|
+
require 'bones'
|
7
|
+
Bones.setup
|
8
|
+
|
9
|
+
PROJ.name = 'source-tools'
|
10
|
+
PROJ.authors = 'Lin Jen-Shin (a.k.a. godfat 真常)'
|
11
|
+
PROJ.email = 'godfat (XD) godfat.org'
|
12
|
+
PROJ.url = 'http://github.com/godfat/source-tools'
|
13
|
+
PROJ.rubyforge.name = 'ludy'
|
14
|
+
|
15
|
+
# begin workaround
|
16
|
+
# PROJ.include << 'lib/.+'
|
17
|
+
PROJ.gem.files = manifest << 'lib/source-tools/templates/t.git/hooks/post-receive.erb'
|
18
|
+
# end workaround
|
19
|
+
|
20
|
+
# PROJ.gem.dependencies << ['source-tools', '>=0.5.0']
|
21
|
+
# PROJ.gem.development_dependencies << ['minitest', '>=1.3.0']
|
22
|
+
PROJ.gem.executables = ["bin/#{PROJ.name}"]
|
23
|
+
|
24
|
+
# PROJ.ruby_opts.delete '-w'
|
25
|
+
|
26
|
+
PROJ.description = PROJ.summary = paragraphs_of('README', 'description').join("\n\n")
|
27
|
+
PROJ.changes = paragraphs_of('CHANGES', 0..1).join("\n\n")
|
28
|
+
PROJ.version = File.read("lib/#{PROJ.name}/version.rb").gsub(/.*VERSION = '(.*)'.*/m, '\1')
|
29
|
+
|
30
|
+
PROJ.exclude += ['^tmp', 'tmp$', '^pkg', '^\.gitignore$',
|
31
|
+
'^ann-', '\.sqlite3$', '\.db$']
|
32
|
+
|
33
|
+
PROJ.rdoc.remote_dir = PROJ.name
|
34
|
+
|
35
|
+
PROJ.readme_file = 'README'
|
36
|
+
PROJ.rdoc.main = 'README'
|
37
|
+
PROJ.rdoc.exclude += ['Rakefile', '^tasks', '^test']
|
38
|
+
PROJ.rdoc.include << '\w+'
|
39
|
+
# PROJ.rdoc.opts << '--diagram' if !Rake::Win32 and `which dot` =~ %r/\/dot/
|
40
|
+
PROJ.rdoc.opts += ['--charset=utf-8', '--inline-source',
|
41
|
+
'--line-numbers', '--promiscuous']
|
42
|
+
|
43
|
+
PROJ.spec.opts << '--color'
|
44
|
+
|
45
|
+
PROJ.ann.file = "ann-#{PROJ.name}-#{PROJ.version}"
|
46
|
+
PROJ.ann.paragraphs.concat %w[LINKS SYNOPSIS REQUIREMENTS INSTALL LICENSE]
|
47
|
+
|
48
|
+
CLEAN.include Dir['**/*.rbc']
|
49
|
+
|
50
|
+
task :default do
|
51
|
+
Rake.application.options.show_task_pattern = /./
|
52
|
+
Rake.application.display_tasks_and_comments
|
53
|
+
end
|
data/TODO
ADDED
data/bin/source-tools
ADDED
data/lib/source-tools.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
|
2
|
+
module SourceTools
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def strip file, spaces = ' '
|
6
|
+
strip_utf8_bom(
|
7
|
+
file.map{ |line| line.gsub("\t", spaces).rstrip }.join("\n") + "\n"
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def strip_utf8_bom str
|
12
|
+
str[0..2] == "\xEF\xBB\xBF" ? str[3..-1] : str
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate path, args = [], task_args = nil, &block
|
16
|
+
require 'fileutils'
|
17
|
+
|
18
|
+
args.each{ |arg|
|
19
|
+
if task_args[arg].nil?
|
20
|
+
puts 'please fill your arguments like:'
|
21
|
+
puts " > source-tools st:t:#{File.basename(path)}[#{args.join(',').upcase}]"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
if File.exist?(path)
|
27
|
+
puts "#{path} exists."
|
28
|
+
exit(1)
|
29
|
+
end
|
30
|
+
|
31
|
+
FileUtils.mkdir_p(File.dirname(path))
|
32
|
+
content = ''
|
33
|
+
File.open(path, 'w'){ |file|
|
34
|
+
require 'erb'
|
35
|
+
args = task_args.to_hash
|
36
|
+
block.call(args) if block_given?
|
37
|
+
|
38
|
+
directory = "#{File.dirname(__FILE__)}/source-tools/templates/"
|
39
|
+
template = "t#{path}.erb"
|
40
|
+
|
41
|
+
content = File.read(directory + template)
|
42
|
+
file << ERB.new(content).result(binding)
|
43
|
+
}
|
44
|
+
if content =~ /\A#!/
|
45
|
+
puts "chmod #{path} to 755"
|
46
|
+
File.chmod(0755, path)
|
47
|
+
end
|
48
|
+
|
49
|
+
puts "#{path} generated."
|
50
|
+
end
|
51
|
+
|
52
|
+
def task_template path, *args, &block
|
53
|
+
task(*args.dup.unshift(File.basename(path))) do |t, task_args|
|
54
|
+
SourceTools.generate(path, args, task_args, &block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def each_source_path
|
59
|
+
require 'pathname'
|
60
|
+
|
61
|
+
Pathname.getwd.find{ |path|
|
62
|
+
# skip unreadable, unwritable, .git and .svn directories
|
63
|
+
skip_dir = path.directory? && (!path.readable? || !path.writable?)
|
64
|
+
Find.prune if skip_dir || %w[.git .svn].include?(path.basename.to_s)
|
65
|
+
|
66
|
+
# skip non-files, zero-sized files, files not matching specific names, or files without the matching extensions
|
67
|
+
match = files.include?(path.basename.to_s) || extensions.include?(path.extname[1..-1])
|
68
|
+
next unless path.file? && path.size? && match && path.readable? && path.writable?
|
69
|
+
|
70
|
+
yield(path)
|
71
|
+
}
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def files
|
76
|
+
# files and extensions to process
|
77
|
+
%w[ CHANGELOG HISTORY MIT-LICENSE LICENSE README README_FOR_APP
|
78
|
+
RUNNING_UNIT_TESTS TODO USAGE INSTALL NOTICE .autotest .gitignore
|
79
|
+
Makefile Rakefile capfile ]
|
80
|
+
end
|
81
|
+
|
82
|
+
def extensions
|
83
|
+
source_codes = %w[ rb ru rake sake php pl py js sh c cpp cxx h hpp hs ml java cs d y as ]
|
84
|
+
templates = %w[ haml builder erb eruby rxml rhtml rjs ratom rcsv ]
|
85
|
+
markup = %w[ css htm html xml rdf yml yaml ]
|
86
|
+
others = %w[ cgi fcgi conf deploy example htc key opts rpdf sql txt vcf log ]
|
87
|
+
|
88
|
+
(source_codes + templates + markup + others)
|
89
|
+
end
|
90
|
+
|
91
|
+
def glob glob_str
|
92
|
+
if glob_str.nil?
|
93
|
+
puts 'Please provide a glob to indicate which files you want to append the comment'
|
94
|
+
exit(1)
|
95
|
+
end
|
96
|
+
|
97
|
+
require 'pathname'
|
98
|
+
Pathname.glob(glob_str).each{ |path|
|
99
|
+
next unless path.writable? && !path.directory?
|
100
|
+
yield(path)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def wrap_source path, content, args = {}
|
105
|
+
path.open('w'){ |f|
|
106
|
+
f.puts(args[:header]) if args[:header]
|
107
|
+
f.print(content)
|
108
|
+
f.puts(args[:footer]) if args[:footer]
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
namespace :st do
|
3
|
+
desc 'fix files(644) and directories(755) permission recursively.'
|
4
|
+
task :chmod do
|
5
|
+
require 'pathname'
|
6
|
+
Pathname.glob("**/*").each{ |path|
|
7
|
+
next unless path.writable?
|
8
|
+
|
9
|
+
if path.directory?
|
10
|
+
path.chmod(0755)
|
11
|
+
|
12
|
+
else
|
13
|
+
path.chmod(0644)
|
14
|
+
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
namespace :st do
|
3
|
+
desc 'Wrap html with comments at the beginning and the end of file (for tracking partial template on generated html)'
|
4
|
+
task :html_wrap, :glob do |t, args|
|
5
|
+
SourceTools.glob(args[:glob]){ |path|
|
6
|
+
content = path.read
|
7
|
+
next if content =~ /\A<!-- begin/
|
8
|
+
|
9
|
+
puts "Processing #{path}"
|
10
|
+
SourceTools.wrap_source( path, content,
|
11
|
+
:header => "<!-- begin #{path} -->",
|
12
|
+
:footer => "<!-- end #{path} -->")
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
namespace :st do
|
3
|
+
desc 'Add magic comment for source encoding for ruby 1.9'
|
4
|
+
task :ruby_magic_encoding, :glob, :encoding do |t, args|
|
5
|
+
encoding = args[:encoding] || 'utf-8'
|
6
|
+
|
7
|
+
SourceTools.glob(args[:glob]){ |path|
|
8
|
+
header = path.readlines.first
|
9
|
+
next if header =~ /\A# ?encoding:/
|
10
|
+
content = path.read
|
11
|
+
|
12
|
+
puts "Processing #{path}"
|
13
|
+
SourceTools.wrap_source( path, content,
|
14
|
+
:header => "# encoding: #{encoding}")
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
# forked from http://github.com/dkubb/dm-dev
|
3
|
+
|
4
|
+
namespace :st do
|
5
|
+
desc 'Strip trailing whitespace from source files, also normalize tabs to spaces, and an newline at end of file'
|
6
|
+
task :strip, :spaces, :glob do |t, args|
|
7
|
+
require 'source-tools'
|
8
|
+
require 'zlib'
|
9
|
+
|
10
|
+
spaces = ' ' * (args[:spaces] || 2).to_i
|
11
|
+
|
12
|
+
kind = if args[:glob]
|
13
|
+
[:glob, args[:glob]]
|
14
|
+
else
|
15
|
+
[:each_source_path]
|
16
|
+
end
|
17
|
+
|
18
|
+
SourceTools.send(*kind){ |path|
|
19
|
+
# strat striping unnecessary whitespaces
|
20
|
+
result = path.open('r:binary'){ |f| SourceTools.strip(f, spaces) }
|
21
|
+
|
22
|
+
# skip the file if it was not modified
|
23
|
+
next if Zlib.crc32(result) == Zlib.crc32(path.read)
|
24
|
+
|
25
|
+
puts "Stripping #{args[:glob] ? path
|
26
|
+
: path.relative_path_from(Pathname.new(Dir.pwd))}"
|
27
|
+
path.open('w'){ |f| f.write result }
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require 'source-tools'
|
3
|
+
|
4
|
+
namespace :st do
|
5
|
+
namespace :t do
|
6
|
+
desc 'create a Rakefile template for bones.'
|
7
|
+
SourceTools.task_template('Rakefile', :project){ |args|
|
8
|
+
args[:author] = `whoami`.chop
|
9
|
+
}
|
10
|
+
|
11
|
+
desc 'create a common .gitconfig file'
|
12
|
+
SourceTools.task_template('.gitconfig', :project)
|
13
|
+
|
14
|
+
desc 'create a user gem only .gemrc file'
|
15
|
+
SourceTools.task_template('.gemrc', :project)
|
16
|
+
|
17
|
+
desc 'create an nginx config file'
|
18
|
+
SourceTools.task_template('config/nginx.conf', :project)
|
19
|
+
|
20
|
+
%w[ .gitignore .vimrc .bashrc .config/fish/config.fish
|
21
|
+
config/mime.types .git/hooks/post-receive .screenrc
|
22
|
+
].each{ |path|
|
23
|
+
|
24
|
+
desc "create a common #{File.basename(path)} file"
|
25
|
+
SourceTools.task_template(path)
|
26
|
+
}
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|