gemma 0.0.2 → 1.0.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.
- data/README.rdoc +85 -37
- data/bin/gemma +134 -0
- data/lib/gemma.rb +4 -9
- data/lib/gemma/conventions.rb +52 -0
- data/lib/gemma/gem_from_template.rb +134 -0
- data/lib/gemma/options.rb +3 -0
- data/lib/gemma/rake_tasks.rb +11 -11
- data/lib/gemma/rake_tasks/rcov_tasks.rb +19 -12
- data/lib/gemma/rake_tasks/rdoc_tasks.rb +11 -12
- data/lib/gemma/rake_tasks/run_tasks.rb +73 -0
- data/lib/gemma/rake_tasks/test_unit_tasks.rb +19 -7
- data/lib/gemma/rake_tasks/yard_tasks.rb +28 -30
- data/lib/gemma/utility.rb +41 -0
- data/lib/gemma/version.rb +1 -1
- data/template/base/.gitignore +6 -0
- data/template/base/README.rdoc.erb +49 -0
- data/template/base/Rakefile.rb.erb +10 -0
- data/template/base/gem_name.gemspec.erb +32 -0
- data/template/base/lib/gem_name.rb.erb +5 -0
- data/template/base/lib/gem_name/version.rb.erb +3 -0
- data/template/executable/bin/gem_name.erb +6 -0
- data/template/test_unit/test/test_gem_name.rb.erb +9 -0
- data/test/test_gemma.rb +64 -12
- metadata +57 -18
- data/lib/gemma/rake_tasks/gem_tasks.rb +0 -74
data/lib/gemma/options.rb
CHANGED
data/lib/gemma/rake_tasks.rb
CHANGED
@@ -53,7 +53,11 @@ module Gemma
|
|
53
53
|
block.call(self) if block_given?
|
54
54
|
|
55
55
|
@plugins.values.each do |plugin|
|
56
|
-
|
56
|
+
begin
|
57
|
+
plugin.create_rake_tasks
|
58
|
+
rescue
|
59
|
+
warn "plugin #{plugin.class} failed: #{$!}"
|
60
|
+
end
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -88,6 +92,11 @@ module Gemma
|
|
88
92
|
#
|
89
93
|
def rdoc; @plugins[:rdoc] end
|
90
94
|
|
95
|
+
#
|
96
|
+
# @return [RunTasks]
|
97
|
+
#
|
98
|
+
def run; @plugins[:run] end
|
99
|
+
|
91
100
|
#
|
92
101
|
# @return [TestUnitTasks]
|
93
102
|
#
|
@@ -98,23 +107,14 @@ module Gemma
|
|
98
107
|
#
|
99
108
|
def yard; @plugins[:yard] end
|
100
109
|
|
101
|
-
#
|
102
|
-
# @return [GemTasks]
|
103
|
-
#
|
104
|
-
#def gem; @plugins[:gem] end
|
105
|
-
|
106
110
|
protected
|
107
111
|
|
108
112
|
def create_default_plugins
|
109
113
|
@plugins[:rcov] = Gemma::RakeTasks::RcovTasks.new(gemspec)
|
110
114
|
@plugins[:rdoc] = Gemma::RakeTasks::RDocTasks.new(gemspec)
|
115
|
+
@plugins[:run] = Gemma::RakeTasks::RunTasks.new(gemspec)
|
111
116
|
@plugins[:test] = Gemma::RakeTasks::TestUnitTasks.new(gemspec)
|
112
117
|
@plugins[:yard] = Gemma::RakeTasks::YardTasks.new(gemspec)
|
113
|
-
|
114
|
-
# not that helpful yet
|
115
|
-
# @plugins[:gem] = Gemma::RakeTasks::GemTasks.new(gemspec,
|
116
|
-
# gemspec_file_name)
|
117
118
|
end
|
118
|
-
|
119
119
|
end
|
120
120
|
end
|
@@ -19,6 +19,7 @@ module Gemma
|
|
19
19
|
# Defaults.
|
20
20
|
@task_name = :rcov
|
21
21
|
@output = 'rcov'
|
22
|
+
@files = gemspec.test_files.dup
|
22
23
|
@with_rcov_task = nil
|
23
24
|
end
|
24
25
|
|
@@ -35,6 +36,13 @@ module Gemma
|
|
35
36
|
# @return [String]
|
36
37
|
#
|
37
38
|
attr_accessor :output
|
39
|
+
|
40
|
+
#
|
41
|
+
# The files to test; defaults to the +test_files+ from the gemspec.
|
42
|
+
#
|
43
|
+
# @return [Array<String>]
|
44
|
+
#
|
45
|
+
attr_accessor :files
|
38
46
|
|
39
47
|
#
|
40
48
|
# Customize the rcov task.
|
@@ -59,19 +67,18 @@ module Gemma
|
|
59
67
|
# @private
|
60
68
|
#
|
61
69
|
def create_rake_tasks
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@with_rcov_task.call(rcov) if @with_rcov_task
|
71
|
-
end
|
72
|
-
rescue LoadError
|
73
|
-
# Assume rcov is not installed.
|
70
|
+
require 'rcov/rcovtask'
|
71
|
+
Rcov::RcovTask.new(self.task_name) do |rcov|
|
72
|
+
rcov.libs = gemspec.require_paths
|
73
|
+
rcov.test_files = self.files
|
74
|
+
rcov.warning = true
|
75
|
+
rcov.rcov_opts << "-x ^/"
|
76
|
+
rcov.output_dir = self.output
|
77
|
+
@with_rcov_task.call(rcov) if @with_rcov_task
|
74
78
|
end
|
79
|
+
nil
|
80
|
+
rescue LoadError
|
81
|
+
# Assume rcov is not installed.
|
75
82
|
end
|
76
83
|
end
|
77
84
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Gemma
|
2
2
|
class RakeTasks
|
3
3
|
#
|
4
|
-
# Create tasks for generating
|
4
|
+
# Create tasks for generating +rdoc+ API documentation with settings from
|
5
5
|
# the gemspec.
|
6
6
|
#
|
7
|
-
# The default settings are based on the
|
8
|
-
#
|
9
|
-
# might be included in `files`) are not documented.
|
7
|
+
# The default settings are based on the +require_paths+, +rdoc_options+ and
|
8
|
+
# +extra_rdoc_files+ data in the gemspec.
|
10
9
|
#
|
11
10
|
# If an rdoc gem is installed, it will be used; otherwise, the built-in
|
12
|
-
# rdoc will be used.
|
11
|
+
# rdoc will be used (see {#use_gem_if_available}).
|
13
12
|
#
|
14
|
-
# This plugin is based on the
|
15
|
-
# If you need an option that isn't exposed by the plugin, you
|
16
|
-
#
|
13
|
+
# This plugin is based on the <tt>Rake::RDocTask</tt> that comes bundled
|
14
|
+
# with rake. If you need an option that isn't exposed by the plugin, you
|
15
|
+
# can modify the +RDocTask+ object directly in a block passed to
|
16
|
+
# {#with_rdoc_task}.
|
17
17
|
#
|
18
18
|
class RDocTasks < Plugin
|
19
19
|
#
|
@@ -38,8 +38,7 @@ module Gemma
|
|
38
38
|
@title, @options = Options.extract(%w(-t --title), @options).to_a
|
39
39
|
@template, @options = Options.extract(%w(-T --template), @options).to_a
|
40
40
|
|
41
|
-
|
42
|
-
@files = gemspec.files - gemspec.test_files
|
41
|
+
@files = gemspec.require_paths + gemspec.extra_rdoc_files
|
43
42
|
end
|
44
43
|
|
45
44
|
#
|
@@ -93,8 +92,8 @@ module Gemma
|
|
93
92
|
attr_accessor :use_gem_if_available
|
94
93
|
|
95
94
|
#
|
96
|
-
# Files to be processed by rdoc; extracted from gemspec;
|
97
|
-
#
|
95
|
+
# Files and directories to be processed by rdoc; extracted from gemspec;
|
96
|
+
# by default, these are the gem's +require_paths+ and +extra_rdoc_files+.
|
98
97
|
#
|
99
98
|
# @return [Array<String>]
|
100
99
|
#
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Gemma
|
2
|
+
class RakeTasks
|
3
|
+
#
|
4
|
+
# Run an executable script in the bin folder.
|
5
|
+
#
|
6
|
+
# There is one task per entry in the gemspec's +executables+ list.
|
7
|
+
# By default, warnings are enabled, the load path is set according to the
|
8
|
+
# +require_paths+ in the gemspec, and rubygems is included.
|
9
|
+
#
|
10
|
+
# To pass arguments to the script, you have to pass them as arguments to
|
11
|
+
# the rake task. The syntax for quoting the arguments will depend on your
|
12
|
+
# shell, but on bash it might look like:
|
13
|
+
#
|
14
|
+
# rake my_prog['foo --bar=baz --bat=hi']
|
15
|
+
#
|
16
|
+
class RunTasks < Plugin
|
17
|
+
#
|
18
|
+
# @param [Gem::Specification] gemspec
|
19
|
+
#
|
20
|
+
def initialize gemspec
|
21
|
+
super(gemspec)
|
22
|
+
|
23
|
+
# Defaults.
|
24
|
+
@task_prefix = ''
|
25
|
+
@program_names = gemspec.executables.dup
|
26
|
+
@ruby_args = ['-w', "-I#{gemspec.require_paths.join(':')}", '-rubygems']
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# The task names are formed by prepending this string onto each program
|
31
|
+
# name; defaults to the empty string.
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
#
|
35
|
+
attr_accessor :task_prefix
|
36
|
+
|
37
|
+
#
|
38
|
+
# Names of the executable (file in the bin directory) to run; by default,
|
39
|
+
# contains the +executables+ from the gemspec.
|
40
|
+
#
|
41
|
+
# @return [Array<String>] may be empty
|
42
|
+
#
|
43
|
+
attr_accessor :program_names
|
44
|
+
|
45
|
+
#
|
46
|
+
# Arguments to be passed to ruby; by default, warnings are enabled (-w)
|
47
|
+
# and the gemspec's +require_paths+ are on the load path (-I).
|
48
|
+
#
|
49
|
+
# @return [Array<String>]
|
50
|
+
#
|
51
|
+
attr_accessor :ruby_args
|
52
|
+
|
53
|
+
#
|
54
|
+
# Internal method; see {Plugin#create_rake_tasks}.
|
55
|
+
#
|
56
|
+
# @return [nil]
|
57
|
+
#
|
58
|
+
# @private
|
59
|
+
#
|
60
|
+
def create_rake_tasks
|
61
|
+
for program_name in program_names
|
62
|
+
desc "run #{program_name}"
|
63
|
+
task((task_prefix + program_name), :args) do |t, args|
|
64
|
+
args = (args[:args] || '').split(/\s/)
|
65
|
+
ruby(*(ruby_args + ["bin/#{program_name}"] + args))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -17,16 +17,24 @@ module Gemma
|
|
17
17
|
|
18
18
|
# Defaults.
|
19
19
|
@task_name = :test
|
20
|
+
@files = gemspec.test_files.dup
|
20
21
|
@with_test_task = nil
|
21
22
|
end
|
22
23
|
|
23
24
|
#
|
24
|
-
# Name of rake task used to
|
25
|
+
# Name of rake task used to run the test; defaults to test.
|
25
26
|
#
|
26
27
|
# @return [Symbol]
|
27
28
|
#
|
28
29
|
attr_accessor :task_name
|
29
30
|
|
31
|
+
#
|
32
|
+
# The files to test; defaults to the +test_files+ from the gemspec.
|
33
|
+
#
|
34
|
+
# @return [Array<String>]
|
35
|
+
#
|
36
|
+
attr_accessor :files
|
37
|
+
|
30
38
|
#
|
31
39
|
# Customize the test task.
|
32
40
|
#
|
@@ -50,14 +58,18 @@ module Gemma
|
|
50
58
|
# @private
|
51
59
|
#
|
52
60
|
def create_rake_tasks
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
unless self.files.empty?
|
62
|
+
require 'rake/testtask'
|
63
|
+
Rake::TestTask.new(self.task_name) do |tt|
|
64
|
+
tt.libs = gemspec.require_paths
|
65
|
+
tt.test_files = self.files
|
66
|
+
tt.warning = true
|
67
|
+
@with_test_task.call(tt) if @with_test_task
|
68
|
+
end
|
59
69
|
end
|
60
70
|
nil
|
71
|
+
rescue LoadError
|
72
|
+
# Assume the test task is not installed.
|
61
73
|
end
|
62
74
|
end
|
63
75
|
end
|
@@ -4,24 +4,25 @@ module Gemma
|
|
4
4
|
# Create tasks to generate documentation with yard (yardoc) if it is
|
5
5
|
# available.
|
6
6
|
#
|
7
|
-
# The
|
8
|
-
#
|
7
|
+
# The gemspec's +require_paths+ and +extra_rdoc_files+ are documented by
|
8
|
+
# default.
|
9
9
|
#
|
10
10
|
# Unfortunately, yardoc's command line options are largely incompatible with
|
11
|
-
# those for rdoc, but the
|
12
|
-
# are
|
13
|
-
#
|
14
|
-
# yardoc (note that
|
15
|
-
#
|
16
|
-
# also ignored.
|
11
|
+
# those for rdoc, but the <tt>--main</tt> and <tt>--title</tt> options from
|
12
|
+
# +rdoc_options+ are passed through to yardoc by default. The short forms
|
13
|
+
# <tt>-m</tt> and <tt>-t</tt> of these arguments are also passed on as
|
14
|
+
# <tt>--main</tt> and <tt>--title</tt> to yardoc (note that <tt>-m</tt> and
|
15
|
+
# <tt>-t</tt> mean different things to yardoc than to rdoc!). Note that any
|
16
|
+
# files (that is, non-options) in +rdoc_options+ are also ignored.
|
17
17
|
#
|
18
18
|
# If you want to further customize your yardoc output, you can add options
|
19
|
-
# in the {Gemma::RakeTasks.with_gemspec_file} configuration block
|
19
|
+
# in the {Gemma::RakeTasks.with_gemspec_file} configuration block or use a
|
20
|
+
# <tt>.yardopts</tt> file.
|
20
21
|
#
|
21
|
-
# This plugin is based on the
|
22
|
-
# with yard. If you need an option that isn't exposed by the
|
23
|
-
# can modify the
|
24
|
-
# {#with_yardoc_task}.
|
22
|
+
# This plugin is based on the <tt>YARD::Rake::YardocTask</tt> that comes
|
23
|
+
# bundled with yard. If you need an option that isn't exposed by the
|
24
|
+
# plugin, you can modify the +YardocTask+ object directly in a block passed
|
25
|
+
# to {#with_yardoc_task}.
|
25
26
|
#
|
26
27
|
class YardTasks < Plugin
|
27
28
|
#
|
@@ -43,9 +44,8 @@ module Gemma
|
|
43
44
|
|
44
45
|
@options = []
|
45
46
|
|
46
|
-
#
|
47
|
-
|
48
|
-
@files = gemspec.files - gemspec.test_files - gemspec.extra_rdoc_files
|
47
|
+
# Yard splits up the files from the 'extra' files.
|
48
|
+
@files = gemspec.require_paths.dup
|
49
49
|
@extra_files = gemspec.extra_rdoc_files.dup
|
50
50
|
@extra_files.delete(main) if main
|
51
51
|
end
|
@@ -82,7 +82,7 @@ module Gemma
|
|
82
82
|
|
83
83
|
#
|
84
84
|
# Ruby files to be processed by yard; these are extracted from the
|
85
|
-
# gemspec;
|
85
|
+
# gemspec; by default these are the +require_paths+.
|
86
86
|
#
|
87
87
|
# @return [Array<String>]
|
88
88
|
#
|
@@ -128,21 +128,19 @@ module Gemma
|
|
128
128
|
# @private
|
129
129
|
#
|
130
130
|
def create_rake_tasks
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
@with_yardoc_task.call(yd) if @with_yardoc_task
|
139
|
-
end
|
140
|
-
CLOBBER.include(self.output)
|
141
|
-
CLOBBER.include('.yardoc')
|
142
|
-
rescue LoadError
|
143
|
-
# Assume yard is not installed.
|
131
|
+
require 'yard'
|
132
|
+
YARD::Rake::YardocTask.new do |yd|
|
133
|
+
yd.name = self.task_name
|
134
|
+
yd.options = complete_options
|
135
|
+
yd.files = self.files
|
136
|
+
yd.files.push('-', *self.extra_files) unless self.extra_files.empty?
|
137
|
+
@with_yardoc_task.call(yd) if @with_yardoc_task
|
144
138
|
end
|
139
|
+
CLOBBER.include(self.output)
|
140
|
+
CLOBBER.include('.yardoc')
|
145
141
|
nil
|
142
|
+
rescue LoadError
|
143
|
+
# Assume yard is not installed.
|
146
144
|
end
|
147
145
|
|
148
146
|
private
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Gemma
|
2
|
+
module Utility
|
3
|
+
#
|
4
|
+
# If the usage information for a script is documented in a comment block at
|
5
|
+
# the top of the file, this method prints it out. If there is a shebang
|
6
|
+
# (#!) on the first line, it is not printed.
|
7
|
+
#
|
8
|
+
def self.print_usage_from_file_comment file, comment_char='#', io=$stdout
|
9
|
+
lines = File.readlines(file)
|
10
|
+
lines.shift if lines.first =~ /^#!/ # ignore shebang
|
11
|
+
for line in lines
|
12
|
+
line.strip!
|
13
|
+
break unless line =~ /^#{comment_char}(.*)/
|
14
|
+
io.puts $1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# A very simple recursive grep.
|
20
|
+
#
|
21
|
+
# @param [Regexp] tag
|
22
|
+
#
|
23
|
+
# @param [String] path
|
24
|
+
#
|
25
|
+
# @param [IO] io
|
26
|
+
#
|
27
|
+
# @return [nil]
|
28
|
+
#
|
29
|
+
def self.rgrep tag, path, io=$stdout
|
30
|
+
Dir.chdir path do
|
31
|
+
(Dir["**/*"] + Dir["**/.*"]).select {|f| File.file? f}.sort.each do |f|
|
32
|
+
File.readlines(f).each_with_index do |line, i|
|
33
|
+
io.puts "#{f}:#{i}: #{line}" if line =~ tag
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/lib/gemma/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
= <%= gem_name %>
|
2
|
+
|
3
|
+
* TODO url
|
4
|
+
|
5
|
+
== SYNOPSIS
|
6
|
+
|
7
|
+
TODO description
|
8
|
+
|
9
|
+
=== Usage
|
10
|
+
|
11
|
+
TODO (code sample of usage)
|
12
|
+
|
13
|
+
== REQUIREMENTS
|
14
|
+
|
15
|
+
* TODO (list of requirements)
|
16
|
+
|
17
|
+
== INSTALLATION
|
18
|
+
|
19
|
+
sudo gem install <%= gem_name %>
|
20
|
+
|
21
|
+
== DEVELOPMENT
|
22
|
+
|
23
|
+
TODO developer advice
|
24
|
+
|
25
|
+
== LICENSE
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) <%= Time.new.strftime("%Y") %> TODO
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
49
|
+
|