tap-gen 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History +11 -0
- data/lib/tap/generator/base.rb +28 -5
- data/lib/tap/generator/destroy.rb +5 -0
- data/lib/tap/generator/exe.rb +9 -3
- data/lib/tap/generator/generate.rb +6 -1
- data/lib/tap/generator/generators/command.rb +2 -0
- data/lib/tap/generator/generators/config.rb +2 -0
- data/lib/tap/generator/generators/generator.rb +2 -2
- data/lib/tap/generator/generators/middleware.rb +10 -0
- data/lib/tap/generator/generators/resource.rb +23 -0
- data/lib/tap/generator/generators/root.rb +1 -1
- data/lib/tap/generator/generators/task.rb +2 -19
- data/lib/tap/generator/preview.rb +4 -0
- data/templates/tap/generator/generators/generator/{task.erb → resource.erb} +2 -2
- data/templates/tap/generator/generators/middleware/resource.erb +18 -0
- data/templates/tap/generator/generators/middleware/test.erb +15 -0
- data/templates/tap/generator/generators/root/gemspec +1 -2
- data/templates/tap/generator/generators/task/resource.erb +15 -0
- metadata +9 -5
- data/templates/tap/generator/generators/task/task.erb +0 -16
data/History
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 0.2.0 / 2009-06-17
|
2
|
+
|
3
|
+
Updates for Tap-0.18.0
|
4
|
+
|
5
|
+
* added actions to generators (via on)
|
6
|
+
* fixed handling of generators with no template dir
|
7
|
+
* fixed logging of paths not relative to pwd
|
8
|
+
* reworked task, generator generators as variations of
|
9
|
+
a resource generator
|
10
|
+
* added middleware generator
|
11
|
+
|
1
12
|
== 0.1.3 / 2009-06-06
|
2
13
|
|
3
14
|
* bug fix for tap-0.17.1
|
data/lib/tap/generator/base.rb
CHANGED
@@ -142,38 +142,61 @@ module Tap
|
|
142
142
|
# Makes (or destroys) the root and each of the targets, relative
|
143
143
|
# to root. Options are passed onto directory.
|
144
144
|
def directories(root, targets, options={})
|
145
|
-
directory(root, options)
|
145
|
+
results = [directory(root, options)]
|
146
146
|
targets.each do |target|
|
147
|
-
directory(File.join(root, target), options)
|
147
|
+
results << directory(File.join(root, target), options)
|
148
148
|
end
|
149
|
+
results
|
149
150
|
end
|
150
151
|
|
151
152
|
# Makes (or destroys) the target by templating the source using
|
152
153
|
# the specified attributes. Source is expanded relative to
|
153
154
|
# template_dir. Options are passed onto file.
|
154
155
|
def template(target, source, attributes={}, options={})
|
156
|
+
raise "no template dir is set" unless template_dir
|
157
|
+
|
155
158
|
template_path = File.expand_path(source, template_dir)
|
156
|
-
templater =
|
159
|
+
templater = Templater.new(File.read(template_path), attributes)
|
157
160
|
|
158
161
|
file(target, options) do |file|
|
159
|
-
file << templater.build
|
162
|
+
file << templater.build(nil, template_path)
|
160
163
|
end
|
161
164
|
end
|
162
165
|
|
163
166
|
# Yields each source file under template_dir to the block, with
|
164
167
|
# a target path of the source relative to template_dir.
|
165
168
|
def template_files
|
169
|
+
raise "no template dir is set" unless template_dir
|
170
|
+
|
171
|
+
targets = []
|
166
172
|
Dir.glob(template_dir + "/**/*").sort.each do |source|
|
167
173
|
next unless File.file?(source)
|
168
174
|
|
169
175
|
target = Tap::Root::Utils.relative_path(template_dir, source)
|
170
176
|
yield(source, target)
|
177
|
+
targets << target
|
178
|
+
end
|
179
|
+
targets
|
180
|
+
end
|
181
|
+
|
182
|
+
# Calls the block when specified by the action for self.
|
183
|
+
def on(*actions, &block)
|
184
|
+
if actions.include?(action)
|
185
|
+
block.call
|
186
|
+
else
|
187
|
+
nil
|
171
188
|
end
|
172
189
|
end
|
173
190
|
|
191
|
+
# Returns the action for self (ie :generate or :destroy)
|
192
|
+
def action
|
193
|
+
raise NotImplementedError
|
194
|
+
end
|
195
|
+
|
174
196
|
# Logs the action with the relative filepath from Dir.pwd to path.
|
175
197
|
def log_relative(action, path)
|
176
|
-
|
198
|
+
relative_path = Tap::Root::Utils.relative_path(Dir.pwd, path)
|
199
|
+
log(action, relative_path || path)
|
177
200
|
end
|
178
201
|
end
|
179
202
|
end
|
data/lib/tap/generator/exe.rb
CHANGED
@@ -12,14 +12,20 @@ module Tap
|
|
12
12
|
end
|
13
13
|
|
14
14
|
name = argv.shift
|
15
|
-
env, const =
|
15
|
+
env, const = seek('generator', name, false)
|
16
16
|
|
17
17
|
unless const
|
18
18
|
raise "unknown generator: #{name}"
|
19
19
|
end
|
20
20
|
|
21
|
-
generator = const.constantize.parse(argv)
|
22
|
-
|
21
|
+
generator = const.constantize.parse!(argv)
|
22
|
+
|
23
|
+
# do not reassign dir unless a template directory
|
24
|
+
# is found, otherwise you get an error
|
25
|
+
if template_dir = env.class_path(:templates, generator) {|dir| File.directory?(dir) }
|
26
|
+
generator.template_dir = template_dir
|
27
|
+
end
|
28
|
+
|
23
29
|
generator.extend(mod).process(*argv)
|
24
30
|
end
|
25
31
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'tempfile'
|
2
2
|
|
3
3
|
module Tap
|
4
4
|
module Generator
|
@@ -62,6 +62,11 @@ module Tap
|
|
62
62
|
target
|
63
63
|
end
|
64
64
|
|
65
|
+
# Returns :generate
|
66
|
+
def action
|
67
|
+
:generate
|
68
|
+
end
|
69
|
+
|
65
70
|
protected
|
66
71
|
|
67
72
|
# Ask the user interactively whether to force collision.
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'tap/generator/generators/
|
1
|
+
require 'tap/generator/generators/resource'
|
2
2
|
|
3
3
|
module Tap::Generator::Generators
|
4
4
|
|
5
5
|
# :startdoc::generator a generator task and test
|
6
6
|
#
|
7
7
|
# Generates a new generator.
|
8
|
-
class Generator <
|
8
|
+
class Generator < Resource
|
9
9
|
|
10
10
|
def manifest(m, const_name)
|
11
11
|
super
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'tap/generator/base'
|
2
|
+
require 'tap/env'
|
3
|
+
|
4
|
+
module Tap::Generator::Generators
|
5
|
+
class Resource < Tap::Generator::Base
|
6
|
+
|
7
|
+
config :test, true, &c.switch # Specifies creation of a test file
|
8
|
+
|
9
|
+
def manifest(m, const_name)
|
10
|
+
const = Tap::Env::Constant.new(const_name.camelize)
|
11
|
+
|
12
|
+
task_path = path('lib', "#{const.path}.rb")
|
13
|
+
m.directory File.dirname(task_path)
|
14
|
+
m.template task_path, "resource.erb", :const => const
|
15
|
+
|
16
|
+
if test
|
17
|
+
test_path = path('test', "#{const.path}_test.rb")
|
18
|
+
m.directory File.dirname(test_path)
|
19
|
+
m.template test_path, "test.erb", :const => const
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,27 +1,10 @@
|
|
1
|
-
require 'tap/
|
1
|
+
require 'tap/generator/generators/resource'
|
2
2
|
|
3
3
|
module Tap::Generator::Generators
|
4
4
|
|
5
5
|
# :startdoc::generator a task and test
|
6
6
|
#
|
7
7
|
# Generates a new Tap::Task and an associated test file.
|
8
|
-
class Task <
|
9
|
-
|
10
|
-
config :test, true, &c.switch # Specifies creation of a test file
|
11
|
-
|
12
|
-
def manifest(m, const_name)
|
13
|
-
const = Tap::Env::Constant.new(const_name.camelize)
|
14
|
-
|
15
|
-
task_path = path('lib', "#{const.path}.rb")
|
16
|
-
m.directory File.dirname(task_path)
|
17
|
-
m.template task_path, "task.erb", :const => const
|
18
|
-
|
19
|
-
if test
|
20
|
-
test_path = path('test', "#{const.path}_test.rb")
|
21
|
-
m.directory File.dirname(test_path)
|
22
|
-
m.template test_path, "test.erb", :const => const
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
8
|
+
class Task < Resource
|
26
9
|
end
|
27
10
|
end
|
@@ -34,8 +34,12 @@ module Tap
|
|
34
34
|
# content built to files.
|
35
35
|
attr_accessor :preview
|
36
36
|
|
37
|
+
# The action for self (default :preview)
|
38
|
+
attr_accessor :action
|
39
|
+
|
37
40
|
def self.extended(base) # :nodoc:
|
38
41
|
base.instance_variable_set(:@preview, {})
|
42
|
+
base.instance_variable_set(:@action, :preview)
|
39
43
|
end
|
40
44
|
|
41
45
|
# Returns the path of path, relative to destination_root. If path
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'tap/generator/base'
|
2
2
|
|
3
|
-
<% redirect do |target| %># :startdoc::generator <replace with
|
4
|
-
# <replace with
|
3
|
+
<% redirect do |target| %># :startdoc::generator <replace with summary>
|
4
|
+
# <replace with description>
|
5
5
|
|
6
6
|
# <%= const.name %> Documentation
|
7
7
|
class <%= const.name %> < Tap::Generator::Base
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'tap/middleware'
|
2
|
+
|
3
|
+
<% redirect do |target| %># :startdoc::middleware <replace with summary>
|
4
|
+
# <replace with description>
|
5
|
+
|
6
|
+
# <%= const.name %> Documentation
|
7
|
+
class <%= const.name %> < Tap::Middleware
|
8
|
+
|
9
|
+
attr_reader :stack
|
10
|
+
|
11
|
+
def initialize(stack)
|
12
|
+
@stack = stack
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(node, inputs=[])
|
16
|
+
stack.call(node, inputs)
|
17
|
+
end
|
18
|
+
end <% module_nest(const.nesting, ' ') { target } end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '<%= '../' * const.nesting_depth %>tap_test_helper.rb')
|
2
|
+
require '<%= const.path %>'
|
3
|
+
|
4
|
+
class <%= const.name %>Test < Test::Unit::TestCase
|
5
|
+
acts_as_tap_test
|
6
|
+
|
7
|
+
def test_<%= const.basename %>_calls_stack
|
8
|
+
runlist = []
|
9
|
+
n = app.node {|input| runlist << input}
|
10
|
+
m = app.use(<%= const.const_name %>)
|
11
|
+
|
12
|
+
m.call(n, ['input'])
|
13
|
+
assert_equal ['input'], runlist
|
14
|
+
end
|
15
|
+
end
|
@@ -20,8 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
<%= license ? " MIT-LICENSE\n" : '' %>
|
21
21
|
}
|
22
22
|
|
23
|
-
# list the files you want to include here.
|
24
|
-
# check this manifest using 'rap print_manifest'
|
23
|
+
# list the files you want to include here.
|
25
24
|
s.files = %W{
|
26
25
|
tap.yml
|
27
26
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'tap/task'
|
2
|
+
|
3
|
+
<% redirect do |target| %># :startdoc::task <replace with summary>
|
4
|
+
# <replace with description>
|
5
|
+
|
6
|
+
# <%= const.name %> Documentation
|
7
|
+
class <%= const.name %> < Tap::Task
|
8
|
+
|
9
|
+
config :message, 'goodnight' # A sample config
|
10
|
+
|
11
|
+
def process(name)
|
12
|
+
log message, name
|
13
|
+
"#{message} #{name}"
|
14
|
+
end
|
15
|
+
end <% module_nest(const.nesting, ' ') { target } end %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tap-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Chiang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-17 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.18.0
|
24
24
|
version:
|
25
25
|
description:
|
26
26
|
email: simon.a.chiang@gmail.com
|
@@ -43,21 +43,25 @@ files:
|
|
43
43
|
- lib/tap/generator/generators/command.rb
|
44
44
|
- lib/tap/generator/generators/config.rb
|
45
45
|
- lib/tap/generator/generators/generator.rb
|
46
|
+
- lib/tap/generator/generators/middleware.rb
|
47
|
+
- lib/tap/generator/generators/resource.rb
|
46
48
|
- lib/tap/generator/generators/root.rb
|
47
49
|
- lib/tap/generator/generators/task.rb
|
48
50
|
- lib/tap/generator/manifest.rb
|
49
51
|
- lib/tap/generator/preview.rb
|
50
52
|
- tap.yml
|
51
53
|
- templates/tap/generator/generators/command/command.erb
|
52
|
-
- templates/tap/generator/generators/generator/
|
54
|
+
- templates/tap/generator/generators/generator/resource.erb
|
53
55
|
- templates/tap/generator/generators/generator/test.erb
|
56
|
+
- templates/tap/generator/generators/middleware/resource.erb
|
57
|
+
- templates/tap/generator/generators/middleware/test.erb
|
54
58
|
- templates/tap/generator/generators/root/MIT-LICENSE
|
55
59
|
- templates/tap/generator/generators/root/README
|
56
60
|
- templates/tap/generator/generators/root/Rakefile
|
57
61
|
- templates/tap/generator/generators/root/Rapfile
|
58
62
|
- templates/tap/generator/generators/root/gemspec
|
59
63
|
- templates/tap/generator/generators/root/test/tap_test_helper.rb
|
60
|
-
- templates/tap/generator/generators/task/
|
64
|
+
- templates/tap/generator/generators/task/resource.erb
|
61
65
|
- templates/tap/generator/generators/task/test.erb
|
62
66
|
- History
|
63
67
|
- README
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'tap/task'
|
2
|
-
|
3
|
-
<% redirect do |target| %># :startdoc::task <replace with manifest summary>
|
4
|
-
# <replace with command line description>
|
5
|
-
|
6
|
-
# <%= const.name %> Documentation
|
7
|
-
class <%= const.name %> < Tap::Task
|
8
|
-
|
9
|
-
# <config file documentation>
|
10
|
-
config :message, 'goodnight' # a sample config
|
11
|
-
|
12
|
-
def process(name)
|
13
|
-
log message, name
|
14
|
-
"#{message} #{name}"
|
15
|
-
end
|
16
|
-
end <% module_nest(const.nesting, ' ') { target } end %>
|