tap-gen 0.3.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History +4 -0
- data/MIT-LICENSE +1 -1
- data/README +1 -4
- data/lib/tap/generator/base.rb +99 -33
- data/lib/tap/generator/destroy.rb +20 -4
- data/lib/tap/generator/generate.rb +20 -4
- data/lib/tap/generator/generators/config.rb +5 -17
- data/lib/tap/generator/generators/env.rb +106 -0
- data/lib/tap/generator/generators/resource.rb +3 -3
- data/lib/tap/generator/generators/root.rb +25 -38
- data/lib/tap/generator/generators/tap.rb +49 -0
- data/lib/tap/generator/helpers.rb +49 -0
- data/lib/tap/generator/preview.rb +1 -1
- data/lib/tap/generator/version.rb +1 -1
- data/tap-gen.gemspec +67 -0
- data/templates/tap/generator/generators/generator/resource.erb +6 -3
- data/templates/tap/generator/generators/generator/test.erb +3 -3
- data/templates/tap/generator/generators/middleware/test.erb +2 -2
- data/templates/tap/generator/generators/root/README +1 -1
- data/templates/tap/generator/generators/root/gemspec +11 -11
- data/templates/tap/generator/generators/root/tap.yml +0 -0
- data/templates/tap/generator/generators/root/{Rakefile → tapfile} +28 -36
- data/templates/tap/generator/generators/root/test/{tap_test_helper.rb → test_helper.rb} +0 -0
- data/templates/tap/generator/generators/tap/profile.erb +9 -0
- data/templates/tap/generator/generators/tap/tap.erb +3 -0
- data/templates/tap/generator/generators/task/resource.erb +0 -1
- data/templates/tap/generator/generators/task/test.erb +2 -2
- metadata +43 -16
- data/cmd/destroy.rb +0 -27
- data/cmd/generate.rb +0 -27
- data/lib/tap/generator/generators/command.rb +0 -21
- data/templates/tap/generator/generators/command/command.erb +0 -30
- data/templates/tap/generator/generators/root/Rapfile +0 -11
@@ -7,14 +7,14 @@ module Tap::Generator::Generators
|
|
7
7
|
config :test, true, &c.switch # Specifies creation of a test file
|
8
8
|
|
9
9
|
def manifest(m, const_name)
|
10
|
-
const = Tap::Env::Constant.new(const_name.camelize)
|
10
|
+
const = ::Tap::Env::Constant.new(const_name.camelize)
|
11
11
|
|
12
|
-
task_path = path('lib', "#{const.
|
12
|
+
task_path = path('lib', "#{const.relative_path}.rb")
|
13
13
|
m.directory File.dirname(task_path)
|
14
14
|
m.template task_path, "resource.erb", :const => const
|
15
15
|
|
16
16
|
if test
|
17
|
-
test_path = path('test', "#{const.
|
17
|
+
test_path = path('test', "#{const.relative_path}_test.rb")
|
18
18
|
m.directory File.dirname(test_path)
|
19
19
|
m.template test_path, "test.erb", :const => const
|
20
20
|
end
|
@@ -11,12 +11,12 @@ module Tap::Generator::Generators
|
|
11
11
|
# project
|
12
12
|
# |- MIT-LICENSE
|
13
13
|
# |- README
|
14
|
-
# |- Rakefile
|
15
14
|
# |- lib
|
16
15
|
# |- project.gemspec
|
17
16
|
# |- tap.yml
|
17
|
+
# |- tapfile
|
18
18
|
# `- test
|
19
|
-
# `-
|
19
|
+
# `- test_helper.rb
|
20
20
|
#
|
21
21
|
class Root < Tap::Generator::Base
|
22
22
|
|
@@ -28,25 +28,32 @@ module Tap::Generator::Generators
|
|
28
28
|
config :summary, "" # The project summary
|
29
29
|
end
|
30
30
|
|
31
|
-
config :env, false, &c.switch
|
32
|
-
config :license, true, &c.switch
|
33
|
-
config :history, true, &c.switch
|
34
|
-
config :
|
35
|
-
|
31
|
+
config :env, false, &c.switch # Create a full tap.yml file
|
32
|
+
config :license, true, &c.switch # Create an MIT-LICENSE
|
33
|
+
config :history, true, &c.switch # Create History file
|
34
|
+
config :tapfile, true, &c.switch # Create a Tapfile
|
35
|
+
|
36
|
+
helper do
|
37
|
+
def titleize(str)
|
38
|
+
str.split(/[-_]+/).collect do |sub|
|
39
|
+
sub.capitalize
|
40
|
+
end.join('-')
|
41
|
+
end
|
42
|
+
end
|
36
43
|
|
37
44
|
# ::args ROOT, PROJECT_NAME=basename(ROOT)
|
38
45
|
def manifest(m, root, project_name=nil)
|
39
|
-
r =
|
40
|
-
project_name = File.basename(r.
|
46
|
+
r = destination_root.root(root)
|
47
|
+
project_name = File.basename(r.path) if project_name == nil
|
41
48
|
|
42
|
-
m.directory r.
|
43
|
-
m.directory r
|
44
|
-
m.directory r
|
49
|
+
m.directory r.path
|
50
|
+
m.directory r.path('lib')
|
51
|
+
m.directory r.path('test')
|
45
52
|
|
46
53
|
template_files do |source, target|
|
47
54
|
case
|
48
55
|
when File.directory?(source)
|
49
|
-
m.directory r
|
56
|
+
m.directory r.path(target)
|
50
57
|
next
|
51
58
|
when source =~ /gemspec$/
|
52
59
|
locals = gemspec.config.to_hash.merge(
|
@@ -54,38 +61,18 @@ module Tap::Generator::Generators
|
|
54
61
|
:license => license,
|
55
62
|
:history => history
|
56
63
|
)
|
57
|
-
m.template r
|
64
|
+
m.template r.path("#{project_name}.gemspec"), source, locals
|
58
65
|
next
|
59
|
-
when source =~ /
|
60
|
-
next unless
|
61
|
-
when source =~ /Rapfile$/
|
62
|
-
next unless rapfile
|
66
|
+
when source =~ /tapfile$/
|
67
|
+
next unless tapfile
|
63
68
|
when source =~ /MIT-LICENSE$/
|
64
69
|
next unless license
|
65
70
|
end
|
66
71
|
|
67
|
-
m.template r
|
72
|
+
m.template r.path(target), source, :project_name => project_name, :license => license
|
68
73
|
end
|
69
74
|
|
70
|
-
m.file(r
|
71
|
-
m.file(r['tap.yml']) do |file|
|
72
|
-
Configurable::Utils.dump(Tap::Env.configurations, file) do |key, config|
|
73
|
-
# get the description
|
74
|
-
desc = config.attributes[:desc]
|
75
|
-
doc = desc.to_s
|
76
|
-
doc = desc.comment if doc.empty?
|
77
|
-
|
78
|
-
# wrap as lines
|
79
|
-
lines = Lazydoc::Utils.wrap(doc, 78).collect {|line| "# #{line}"}
|
80
|
-
lines << "" unless lines.empty?
|
81
|
-
|
82
|
-
# setup formatting
|
83
|
-
default = config.default
|
84
|
-
leader = key == 'root' || default == nil ? '# ' : ''
|
85
|
-
config = YAML.dump({key => default})[5..-1].strip.gsub(/\n+/, "\n#{leader}")
|
86
|
-
"#{lines.join("\n")}#{leader}#{config}\n\n"
|
87
|
-
end if env
|
88
|
-
end
|
75
|
+
m.file(r.path('History')) if history
|
89
76
|
end
|
90
77
|
|
91
78
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'tap/generator/base'
|
2
|
+
|
3
|
+
module Tap
|
4
|
+
module Generator
|
5
|
+
module Generators
|
6
|
+
# :startdoc::generator make a faster tap
|
7
|
+
class Tap < Tap::Generator::Base
|
8
|
+
|
9
|
+
config :name, 'tap', &c.string # sets the tap executable name
|
10
|
+
config :profile, 'profile.sh', &c.string # sets the profile script name
|
11
|
+
|
12
|
+
def manifest(m)
|
13
|
+
load_paths = load_paths('lazydoc', 'configurable', 'tap')
|
14
|
+
bin_path = File.join(load_paths.last.chomp('lib'), 'bin/tapexe')
|
15
|
+
|
16
|
+
m.template name, 'tap.erb', {
|
17
|
+
:load_paths => load_paths,
|
18
|
+
:bin_path => bin_path
|
19
|
+
}
|
20
|
+
|
21
|
+
m.on(:generate) do
|
22
|
+
log :chmod, "0755 #{name}"
|
23
|
+
FileUtils.chmod(0755, name)
|
24
|
+
end
|
25
|
+
|
26
|
+
m.template profile, 'profile.erb', {
|
27
|
+
:generator => self.class,
|
28
|
+
:filename => profile
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_paths(*gem_names)
|
33
|
+
gem_names.collect! do |gem_name|
|
34
|
+
load_path = $LOAD_PATH.find do |path|
|
35
|
+
path =~ /\/#{gem_name}[-\d\.]*\/lib$/
|
36
|
+
end
|
37
|
+
|
38
|
+
if load_path.nil?
|
39
|
+
raise "could not determine load path for: #{gem_name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
File.expand_path(load_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Tap
|
2
|
+
module Generator
|
3
|
+
module Helpers
|
4
|
+
attr_reader :helper_registry
|
5
|
+
|
6
|
+
def helpers
|
7
|
+
return @helpers if @helpers
|
8
|
+
|
9
|
+
helpers = []
|
10
|
+
ancestors.each do |ancestor|
|
11
|
+
next unless ancestor.kind_of?(Helpers)
|
12
|
+
helpers.concat ancestor.helper_registry
|
13
|
+
end
|
14
|
+
|
15
|
+
helpers
|
16
|
+
end
|
17
|
+
|
18
|
+
def cache_helpers(on=true)
|
19
|
+
@helpers = nil
|
20
|
+
@helpers = self.helpers if on
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def helper(const_name='helper', &block)
|
26
|
+
helper = Module.new(&block)
|
27
|
+
const_set(const_name.to_s.camelize, helper) if const_name
|
28
|
+
helper_registry << helper
|
29
|
+
helper
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.initialize(base)
|
35
|
+
base.instance_variable_set(:@helper_registry, [])
|
36
|
+
base.instance_variable_set(:@helpers, nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.extended(base)
|
40
|
+
Helpers.initialize(base)
|
41
|
+
end
|
42
|
+
|
43
|
+
def inherited(base)
|
44
|
+
super
|
45
|
+
Helpers.initialize(base)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -45,7 +45,7 @@ module Tap
|
|
45
45
|
# Returns the path of path, relative to destination_root. If path
|
46
46
|
# is destination_root, '.' will be returned.
|
47
47
|
def relative_path(path)
|
48
|
-
path =
|
48
|
+
path = destination_root.relative_path(path) || path
|
49
49
|
path.empty? ? "." : path
|
50
50
|
end
|
51
51
|
|
data/tap-gen.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
$:.unshift File.expand_path('../../tap/lib', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../tap-test/lib', __FILE__)
|
3
|
+
$:.unshift File.expand_path('../../tap-gen/lib', __FILE__)
|
4
|
+
|
5
|
+
require 'tap/version'
|
6
|
+
require 'tap/test/version'
|
7
|
+
require 'tap/generator/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = 'tap-gen'
|
11
|
+
s.version = Tap::Generator::VERSION
|
12
|
+
s.author = 'Simon Chiang'
|
13
|
+
s.email = 'simon.a.chiang@gmail.com'
|
14
|
+
s.homepage = File.join(Tap::WEBSITE, 'tap-gen')
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.summary = 'Generators for Tap'
|
17
|
+
s.require_path = 'lib'
|
18
|
+
s.rubyforge_project = 'tap'
|
19
|
+
s.add_dependency('tap', ">= #{Tap::VERSION}")
|
20
|
+
s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}")
|
21
|
+
s.has_rdoc = true
|
22
|
+
s.rdoc_options.concat %W{--main README -S -N --title Tap-Generator}
|
23
|
+
|
24
|
+
# list extra rdoc files here.
|
25
|
+
s.extra_rdoc_files = %W{
|
26
|
+
History
|
27
|
+
README
|
28
|
+
MIT-LICENSE
|
29
|
+
}
|
30
|
+
|
31
|
+
# list the files you want to include here. you can
|
32
|
+
# check this manifest using 'rap print_manifest'
|
33
|
+
s.files = %W{
|
34
|
+
lib/tap/generator/arguments.rb
|
35
|
+
lib/tap/generator/base.rb
|
36
|
+
lib/tap/generator/destroy.rb
|
37
|
+
lib/tap/generator/generate.rb
|
38
|
+
lib/tap/generator/generators/config.rb
|
39
|
+
lib/tap/generator/generators/env.rb
|
40
|
+
lib/tap/generator/generators/generator.rb
|
41
|
+
lib/tap/generator/generators/middleware.rb
|
42
|
+
lib/tap/generator/generators/resource.rb
|
43
|
+
lib/tap/generator/generators/root.rb
|
44
|
+
lib/tap/generator/generators/tap.rb
|
45
|
+
lib/tap/generator/generators/task.rb
|
46
|
+
lib/tap/generator/helpers.rb
|
47
|
+
lib/tap/generator/manifest.rb
|
48
|
+
lib/tap/generator/preview.rb
|
49
|
+
lib/tap/generator/version.rb
|
50
|
+
tap-gen.gemspec
|
51
|
+
tap.yml
|
52
|
+
templates/tap/generator/generators/generator/resource.erb
|
53
|
+
templates/tap/generator/generators/generator/test.erb
|
54
|
+
templates/tap/generator/generators/middleware/resource.erb
|
55
|
+
templates/tap/generator/generators/middleware/test.erb
|
56
|
+
templates/tap/generator/generators/root/MIT-LICENSE
|
57
|
+
templates/tap/generator/generators/root/README
|
58
|
+
templates/tap/generator/generators/root/gemspec
|
59
|
+
templates/tap/generator/generators/root/tap.yml
|
60
|
+
templates/tap/generator/generators/root/tapfile
|
61
|
+
templates/tap/generator/generators/root/test/test_helper.rb
|
62
|
+
templates/tap/generator/generators/tap/profile.erb
|
63
|
+
templates/tap/generator/generators/tap/tap.erb
|
64
|
+
templates/tap/generator/generators/task/resource.erb
|
65
|
+
templates/tap/generator/generators/task/test.erb
|
66
|
+
}
|
67
|
+
end
|
@@ -13,17 +13,20 @@ class <%= const.name %> < Tap::Generator::Base
|
|
13
13
|
def manifest(m, *inputs)
|
14
14
|
|
15
15
|
# make a directory
|
16
|
-
# m.directory path
|
16
|
+
# m.directory 'path'
|
17
17
|
|
18
18
|
# make a file
|
19
|
-
# m.file path do |file|
|
19
|
+
# m.file 'path' do |file|
|
20
20
|
# file << content
|
21
21
|
# end
|
22
22
|
|
23
23
|
# template a file in the templates directory using ERB.
|
24
24
|
# The last argument defines a hash of local variables
|
25
25
|
# for use in the template (here config is used).
|
26
|
-
m.template "<%= const.const_name.underscore %>_file.txt",
|
26
|
+
m.template "<%= const.const_name.underscore %>_file.txt", 'template_file.erb', config.to_hash
|
27
|
+
|
28
|
+
# do something only on generate/destroy
|
29
|
+
# on(:generate) {}
|
27
30
|
end
|
28
31
|
|
29
32
|
end <% module_nest(const.nesting, ' ') { target } end %>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.
|
2
|
-
require '<%= const.
|
3
|
-
require 'tap/generator/preview
|
1
|
+
require File.expand_path('<%= '../' * const.nesting_depth %>../test_helper', __FILE__)
|
2
|
+
require '<%= const.relative_path %>'
|
3
|
+
require 'tap/generator/preview'
|
4
4
|
|
5
5
|
class <%= const.name %>Test < Test::Unit::TestCase
|
6
6
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.
|
2
|
-
require '<%= const.
|
1
|
+
require File.expand_path('<%= '../' * const.nesting_depth %>../test_helper', __FILE__)
|
2
|
+
require '<%= const.relative_path %>'
|
3
3
|
|
4
4
|
class <%= const.name %>Test < Test::Unit::TestCase
|
5
5
|
acts_as_tap_test
|
@@ -1,17 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.version =
|
4
|
-
s.author =
|
5
|
-
s.email =
|
6
|
-
s.homepage =
|
2
|
+
s.name = '<%= project_name %>'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.author = '<%= name %>'
|
5
|
+
s.email = '<%= email %>'
|
6
|
+
s.homepage = '<%= homepage %>'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.summary =
|
9
|
-
s.require_path =
|
10
|
-
s.rubyforge_project =
|
11
|
-
s.add_dependency(
|
12
|
-
s.add_development_dependency(
|
8
|
+
s.summary = '<%= summary %>'
|
9
|
+
s.require_path = 'lib'
|
10
|
+
s.rubyforge_project = '<%= rubyforge_project %>'
|
11
|
+
s.add_dependency('tap', '= <%= Tap::VERSION %>')
|
12
|
+
s.add_development_dependency('tap-test')
|
13
13
|
s.has_rdoc = true
|
14
|
-
s.rdoc_options.concat %W{--main README -S -N --title <%= project_name
|
14
|
+
s.rdoc_options.concat %W{--main README -S -N --title <%= titleize(project_name) %>}
|
15
15
|
|
16
16
|
# list extra rdoc files here.
|
17
17
|
s.extra_rdoc_files = %W{
|
File without changes
|
@@ -1,21 +1,18 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
require 'rake/gempackagetask'
|
5
|
-
|
6
1
|
#
|
7
2
|
# Gem specification
|
8
3
|
#
|
9
4
|
|
10
5
|
def gemspec
|
11
|
-
|
12
|
-
spec = nil
|
13
|
-
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
14
|
-
spec
|
6
|
+
@gemspec ||= TOPLEVEL_BINDING.eval(File.read('<%= project_name %>.gemspec'))
|
15
7
|
end
|
16
8
|
|
17
|
-
|
18
|
-
|
9
|
+
desc 'build the gem'
|
10
|
+
task :gem, :dir => 'pkg' do |config|
|
11
|
+
output = `gem build '<%= project_name %>.gemspec'`
|
12
|
+
output =~ /File: (.*)$/
|
13
|
+
|
14
|
+
FileUtils.mkdir_p(config.dir) unless File.exists?(config.dir)
|
15
|
+
FileUtils.mv($1, File.join(config.dir, $1), :force => true)
|
19
16
|
end
|
20
17
|
|
21
18
|
desc 'Prints the gemspec manifest.'
|
@@ -27,18 +24,18 @@ task :print_manifest do
|
|
27
24
|
files[File.expand_path(file)] = [File.exists?(file), file]
|
28
25
|
files
|
29
26
|
end
|
30
|
-
|
27
|
+
|
31
28
|
# gather non-rdoc/pkg files for the project
|
32
29
|
# and add to the files list if they are not
|
33
30
|
# included already (marking by the absence
|
34
31
|
# of a label)
|
35
32
|
Dir.glob("**/*").each do |file|
|
36
|
-
next if file =~ /^(rdoc|pkg|
|
37
|
-
|
33
|
+
next if file =~ /^(rdoc|pkg|test)/ || File.directory?(file)
|
34
|
+
|
38
35
|
path = File.expand_path(file)
|
39
36
|
files[path] = ["", file] unless files.has_key?(path)
|
40
37
|
end
|
41
|
-
|
38
|
+
|
42
39
|
# sort and output the results
|
43
40
|
files.values.sort_by {|exists, file| file }.each do |entry|
|
44
41
|
puts "%-5s %s" % entry
|
@@ -50,36 +47,31 @@ end
|
|
50
47
|
#
|
51
48
|
|
52
49
|
desc 'Generate documentation.'
|
53
|
-
|
54
|
-
|
50
|
+
task :rdoc, :rebuild => false, :dir => 'rdoc' do |config|
|
51
|
+
require 'rdoc/rdoc'
|
52
|
+
require 'cdoc'
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
if config.rebuild && File.directory?(config.dir)
|
55
|
+
FileUtils.rm_r(config.dir)
|
56
|
+
end
|
59
57
|
|
60
|
-
files =
|
61
|
-
|
58
|
+
files = gemspec.files.select {|file| file =~ /^lib.*\.rb$/ }.uniq
|
59
|
+
files += gemspec.extra_rdoc_files
|
62
60
|
|
63
61
|
# Using CDoc to template your RDoc will result in configurations being
|
64
62
|
# listed with documentation in a subsection following attributes. Not
|
65
63
|
# necessary, but nice.
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
cdoc_options = ['--fmt', 'cdoc', '--template', 'cdoc/cdoc_html_template']
|
65
|
+
args = ['-o', config.dir] + cdoc_options + gemspec.rdoc_options + files
|
66
|
+
RDoc::RDoc.new.document(args)
|
69
67
|
end
|
70
68
|
|
71
69
|
#
|
72
70
|
# Test tasks
|
73
71
|
#
|
74
72
|
|
75
|
-
desc '
|
76
|
-
task :
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
t.test_files = Dir.glob( File.join('test', ENV['pattern'] || '**/*_test.rb') )
|
81
|
-
t.ruby_opts = ['-rubygems']
|
82
|
-
t.verbose = true
|
83
|
-
t.warning = true
|
84
|
-
end
|
85
|
-
|
73
|
+
desc 'Run the tests'
|
74
|
+
task :test do
|
75
|
+
tests = Dir.glob('test/**/*_test.rb')
|
76
|
+
sh('ruby', '-w', '-e', 'ARGV.dup.each {|test| load test}', *tests)
|
77
|
+
end
|