source-tools 0.6.0

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.
Files changed (43) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGES +10 -0
  3. data/README +54 -0
  4. data/Rakefile +53 -0
  5. data/TODO +4 -0
  6. data/bin/source-tools +3 -0
  7. data/lib/source-tools.rb +112 -0
  8. data/lib/source-tools/bin.rb +7 -0
  9. data/lib/source-tools/default.rb +5 -0
  10. data/lib/source-tools/tasks.rb +4 -0
  11. data/lib/source-tools/tasks/chmod.rb +19 -0
  12. data/lib/source-tools/tasks/html_wrap.rb +15 -0
  13. data/lib/source-tools/tasks/ruby_magic_encoding.rb +17 -0
  14. data/lib/source-tools/tasks/strip.rb +31 -0
  15. data/lib/source-tools/tasks/template.rb +29 -0
  16. data/lib/source-tools/templates/t.bashrc.erb +5 -0
  17. data/lib/source-tools/templates/t.config/fish/config.fish.erb +6 -0
  18. data/lib/source-tools/templates/t.gemrc.erb +4 -0
  19. data/lib/source-tools/templates/t.git/hooks/post-receive.erb +7 -0
  20. data/lib/source-tools/templates/t.gitconfig.erb +14 -0
  21. data/lib/source-tools/templates/t.gitignore.erb +15 -0
  22. data/lib/source-tools/templates/t.profile.erb +39 -0
  23. data/lib/source-tools/templates/t.screenrc.erb +1 -0
  24. data/lib/source-tools/templates/t.vimrc.erb +37 -0
  25. data/lib/source-tools/templates/tRakefile.erb +47 -0
  26. data/lib/source-tools/templates/tconfig/mime.types.erb +104 -0
  27. data/lib/source-tools/templates/tconfig/nginx.conf.erb +178 -0
  28. data/lib/source-tools/version.rb +3 -0
  29. data/source-tools.gemspec +35 -0
  30. data/tasks/ann.rake +80 -0
  31. data/tasks/bones.rake +20 -0
  32. data/tasks/gem.rake +201 -0
  33. data/tasks/git.rake +40 -0
  34. data/tasks/notes.rake +27 -0
  35. data/tasks/post_load.rake +34 -0
  36. data/tasks/rdoc.rake +51 -0
  37. data/tasks/rubyforge.rake +55 -0
  38. data/tasks/setup.rb +292 -0
  39. data/tasks/spec.rake +54 -0
  40. data/tasks/svn.rake +47 -0
  41. data/tasks/test.rake +40 -0
  42. data/tasks/zentest.rake +36 -0
  43. metadata +126 -0
@@ -0,0 +1,6 @@
1
+ tmp
2
+ pkg
3
+ doc
4
+ ann-*
5
+
6
+ *.rbc
data/CHANGES ADDED
@@ -0,0 +1,10 @@
1
+ = source-tools changes history
2
+
3
+ == source-tools 0.6 / 2009-11-21
4
+
5
+ * first rubyforge and gemcutter release
6
+
7
+ == source-tools 0.5 / 2008-12-12
8
+
9
+ * 1 major enhancement
10
+ * Birthday!
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.
@@ -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
@@ -0,0 +1,4 @@
1
+ = source-tools todo list
2
+
3
+ * adding --verbose option.
4
+ * adding task that generate all template.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'source-tools/bin'
@@ -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,7 @@
1
+
2
+ require 'rake'
3
+ require 'source-tools/tasks'
4
+ require 'source-tools/default'
5
+
6
+ Rake.application.init('source-tools')
7
+ Rake.application.top_level
@@ -0,0 +1,5 @@
1
+
2
+ task :default do
3
+ Rake.application.options.show_task_pattern = /./
4
+ Rake.application.display_tasks_and_comments
5
+ end
@@ -0,0 +1,4 @@
1
+
2
+ %w[strip template chmod html_wrap ruby_magic_encoding].each{ |task|
3
+ require "source-tools/tasks/#{task}"
4
+ }
@@ -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
@@ -0,0 +1,5 @@
1
+ #export GEM_HOME=$HOME/.gem/ruby/1.8
2
+ #export GEM_PATH=$GEM_HOME
3
+ export LC_ALL=en_US.utf-8
4
+ export LANG=en_US.utf-8
5
+ umask g+w
@@ -0,0 +1,6 @@
1
+ set GEM_HOME $HOME/.gem/ruby/1.8
2
+ set GEM_PATH $GEM_HOME
3
+ set PATH $PATH:$HOME/.gem/ruby/1.8/bin
4
+ set LC_ALL en_US.utf-8
5
+ set LANG en_US.utf-8
6
+ umask g+w
@@ -0,0 +1,4 @@
1
+ #gemhome: /home/<%= args[:project] %>/.gem/ruby/1.8
2
+ #gempath: - /home/<%= args[:project] %>/.gem/ruby/1.8
3
+ # - /home/<%= args[:project] %>/.gem/ruby/1.9.1
4
+ gem: --no-rdoc --no-ri --user-install --format-executable
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ # /home/user/.git => user
4
+ # /home/user/.git => /home/user
5
+
6
+ chgrp --silent `pwd | ruby -e 'puts gets.scan(/\w+/)[1]'` -R \
7
+ `pwd | ruby -e 'puts gets.scan(/\/\w+/).join'`
@@ -0,0 +1,14 @@
1
+ [color]
2
+ branch = auto
3
+ diff = auto
4
+ interactive = auto
5
+ status = auto
6
+ ui = auto
7
+ [diff]
8
+ renames = copy
9
+ [user]
10
+ name = <%= args[:project] %>
11
+ [push]
12
+ default = tracking
13
+ [merge]
14
+ log = true
@@ -0,0 +1,15 @@
1
+ tmp
2
+ pkg
3
+ doc
4
+ ann-*
5
+
6
+ *.rbc
7
+ *.log
8
+ *.sqlite3
9
+ *.gz
10
+
11
+ .bash_history
12
+ .bash_logout
13
+ .bash_profile
14
+ .gem
15
+ .viminfo