rubigen 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +13 -0
- data/History.txt +14 -1
- data/Manifest.txt +11 -7
- data/{README.txt → README.rdoc} +21 -7
- data/Rakefile +20 -3
- data/Todo.txt +4 -2
- data/bin/install_rubigen_scripts +0 -0
- data/bin/rubigen +10 -0
- data/bin/ruby_app +0 -0
- data/features/development.feature +13 -0
- data/features/help.feature +14 -0
- data/features/rubigen_cli.feature +10 -0
- data/features/steps/common.rb +195 -0
- data/features/steps/env.rb +6 -0
- data/lib/rubigen/base.rb +11 -1
- data/lib/rubigen/cli.rb +31 -0
- data/lib/rubigen/commands.rb +76 -80
- data/lib/rubigen/lookup.rb +5 -7
- data/lib/rubigen/options.rb +7 -0
- data/lib/rubigen/scripts/destroy.rb +3 -0
- data/lib/rubigen/scripts.rb +15 -8
- data/lib/rubigen.rb +6 -1
- data/rubygems_generators/application_generator/USAGE +2 -2
- data/rubygems_generators/application_generator/application_generator_generator.rb +1 -1
- data/rubygems_generators/application_generator/templates/generator.rb +1 -1
- data/rubygems_generators/application_generator/templates/readme +2 -2
- data/rubygems_generators/component_generator/USAGE +3 -4
- data/rubygems_generators/component_generator/component_generator_generator.rb +1 -5
- data/rubygems_generators/component_generator/templates/generator.rb +1 -1
- data/rubygems_generators/component_generator/templates/readme +1 -1
- data/script/console +10 -0
- data/script/destroy +1 -1
- data/script/generate +1 -1
- data/test/test_component_generator_generator.rb +0 -26
- data/test/test_generator_helper.rb +3 -1
- data/test/test_helper.rb +2 -0
- data/test/test_install_rubigen_scripts_generator.rb +1 -1
- data/test/test_rubigen_cli.rb +71 -0
- data/website/index.html +5 -5
- data/website/index.txt +5 -5
- metadata +34 -16
- data/config/hoe.rb +0 -74
- data/config/requirements.rb +0 -17
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
data/.autotest
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Autotest.add_hook :initialize do |at|
|
2
|
+
at.clear_mappings
|
3
|
+
|
4
|
+
at.add_mapping(%r%^test/test_.*.rb$%) do |filename, _|
|
5
|
+
filename
|
6
|
+
end
|
7
|
+
at.add_mapping(/lib\/(.*)\.rb/) do |_, m|
|
8
|
+
["test/test_#{m[1]}.rb"]
|
9
|
+
end
|
10
|
+
# at.add_mapping(/.*_?generators\/(.*)\/(.*)_generator\.rb/) do |_, m|
|
11
|
+
# ["test/test_#{m[1]}.rb"]
|
12
|
+
# end
|
13
|
+
end
|
data/History.txt
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
== 1.
|
1
|
+
== 1.5.0 2008-12-27
|
2
|
+
|
3
|
+
* Preparation for integration back into Rails
|
4
|
+
* --git/-g option for generated files to be added via git commands
|
5
|
+
* after_generate hook for generators (used as rails' templates mechanism)
|
6
|
+
* bumped activesupport requirement to 2.2.2
|
7
|
+
* upgraded internal files to support latest newgem (removed config/ folder, moved config to Rakefile)
|
8
|
+
* support for RAILS_ROOT as a destination root
|
9
|
+
* removed references to Merb which now has its own generator system; can access any merb
|
10
|
+
generators via `rubigen` helper app
|
11
|
+
* RubiGen::Base.active can be changed to a RubiGen::Base subclass that will be used
|
12
|
+
for lookups (e.g. RubiGen::Base.active = Rails::Generator::Base)
|
13
|
+
|
14
|
+
== 1.4.0 2008-12-11
|
2
15
|
|
3
16
|
* rubigen tests now pass against ruby 1.9.0 and ruby 1.9.1(prerelease 2)
|
4
17
|
* puts are sent to an explicit #stdout which can be STDOUT or a StringIO passed from tests; test output is now clean!
|
data/Manifest.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
.autotest
|
1
2
|
History.txt
|
2
3
|
License.txt
|
3
4
|
Manifest.txt
|
4
|
-
README.
|
5
|
+
README.rdoc
|
5
6
|
Rakefile
|
6
7
|
Todo.txt
|
7
8
|
app_generators/ruby_app/USAGE
|
@@ -11,15 +12,20 @@ app_generators/ruby_app/templates/Rakefile
|
|
11
12
|
app_generators/ruby_app/templates/lib/module.rb
|
12
13
|
app_generators/ruby_app/templates/test/test_helper.rb.erb
|
13
14
|
bin/install_rubigen_scripts
|
15
|
+
bin/rubigen
|
14
16
|
bin/ruby_app
|
15
|
-
|
16
|
-
|
17
|
+
features/development.feature
|
18
|
+
features/help.feature
|
19
|
+
features/rubigen_cli.feature
|
20
|
+
features/steps/common.rb
|
21
|
+
features/steps/env.rb
|
17
22
|
generators/install_rubigen_scripts/install_rubigen_scripts_generator.rb
|
18
23
|
generators/install_rubigen_scripts/templates/script/destroy
|
19
24
|
generators/install_rubigen_scripts/templates/script/generate
|
20
25
|
generators/install_rubigen_scripts/templates/script/win_script.cmd
|
21
26
|
lib/rubigen.rb
|
22
27
|
lib/rubigen/base.rb
|
28
|
+
lib/rubigen/cli.rb
|
23
29
|
lib/rubigen/commands.rb
|
24
30
|
lib/rubigen/generated_attribute.rb
|
25
31
|
lib/rubigen/helpers/generator_test_helper.rb
|
@@ -48,13 +54,10 @@ rubygems_generators/component_generator/templates/readme
|
|
48
54
|
rubygems_generators/component_generator/templates/test.rb
|
49
55
|
rubygems_generators/component_generator/templates/test_generator_helper.rb
|
50
56
|
rubygems_generators/component_generator/templates/usage
|
57
|
+
script/console
|
51
58
|
script/destroy
|
52
59
|
script/generate
|
53
60
|
script/txt2html
|
54
|
-
setup.rb
|
55
|
-
tasks/deployment.rake
|
56
|
-
tasks/environment.rake
|
57
|
-
tasks/website.rake
|
58
61
|
test/test_application_generator_generator.rb
|
59
62
|
test/test_component_generator_generator.rb
|
60
63
|
test/test_generate_builtin_application.rb
|
@@ -63,6 +66,7 @@ test/test_generator_helper.rb
|
|
63
66
|
test/test_helper.rb
|
64
67
|
test/test_install_rubigen_scripts_generator.rb
|
65
68
|
test/test_lookup.rb
|
69
|
+
test/test_rubigen_cli.rb
|
66
70
|
test_unit_generators/test_unit/USAGE
|
67
71
|
test_unit_generators/test_unit/templates/test.rb
|
68
72
|
test_unit_generators/test_unit/test_unit_generator.rb
|
data/{README.txt → README.rdoc}
RENAMED
@@ -1,5 +1,9 @@
|
|
1
1
|
= RubiGen - Ruby Generator Framework
|
2
2
|
|
3
|
+
* http://rubigen.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
3
7
|
A framework to allow Ruby applications to generate file/folder stubs
|
4
8
|
(like the `rails` command does for Ruby on Rails, and the 'script/generate'
|
5
9
|
command within a Rails application during development).
|
@@ -15,7 +19,7 @@ and generally assumed it was the only generator framework within the Ruby world
|
|
15
19
|
So, any RubyGem whose name ended with '_generator' was assumed to be a generator for
|
16
20
|
a Rails application.
|
17
21
|
|
18
|
-
But if you are developing
|
22
|
+
But if you are developing an Adhearsion application, then you may want a different set of generators.
|
19
23
|
If you are developing a RubyGem, then you will want a different set of generators.
|
20
24
|
|
21
25
|
RubiGen exists to give different development environments their own generator framework.
|
@@ -27,15 +31,25 @@ Jeremy Kemper wrote the original Rails Generator, which is 95% of the basis of R
|
|
27
31
|
== Installation
|
28
32
|
|
29
33
|
RubiGen is only required at development time, and normally isn't required at deployment time
|
30
|
-
(unless your application uses it to generate files
|
34
|
+
(unless your application uses it to generate files at runtime).
|
31
35
|
|
32
36
|
On your development machine:
|
33
37
|
|
34
|
-
gem install rubigen
|
38
|
+
sudo gem install rubigen
|
35
39
|
|
36
40
|
== Usage
|
37
41
|
|
38
|
-
RubiGen
|
42
|
+
RubiGen comes with a stand-alone executable to allow you to invoke generators:
|
43
|
+
|
44
|
+
For example, to run the rails' `model` generator:
|
45
|
+
|
46
|
+
rubigen rails model Person name:string
|
47
|
+
|
48
|
+
would replace the normal
|
49
|
+
|
50
|
+
script/generate model Person name:string
|
51
|
+
|
52
|
+
RubiGen has been traditionally integrated into another project, such as `rails`, `newgem` or `camping`,
|
39
53
|
rather than be used on its own.
|
40
54
|
|
41
55
|
These frameworks might use RubiGen for two reasons:
|
@@ -57,9 +71,9 @@ So, there are two steps to integrating RubiGen into your framework:
|
|
57
71
|
generate components/extensions within the framework.
|
58
72
|
RubiGen allows you to restrict which generators are available. For example, within
|
59
73
|
RubyGem development environment (as generated by `newgem`), the `script/generator`
|
60
|
-
only shows `rubygem`-related generators.
|
61
|
-
to only show
|
62
|
-
2. Your framework RubyGem (e.g. `newgem` or `
|
74
|
+
only shows `rubygem`-related generators. Rails could restrict `script/generator`
|
75
|
+
to only show Rails related generators
|
76
|
+
2. Your framework RubyGem (e.g. `newgem` or `rails`) needs to add `rubigen` as a
|
63
77
|
dependency, so that users of your RubyGem can access the generator framework.
|
64
78
|
|
65
79
|
= Creating generators
|
data/Rakefile
CHANGED
@@ -1,4 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require '
|
1
|
+
%w[rubygems rake rake/clean newgem].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/rubigen'
|
3
3
|
|
4
|
-
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('rubigen', RubiGen::VERSION) do |p|
|
7
|
+
p.developer('Dr Nic Williams', 'drnicwilliams@gmail.com')
|
8
|
+
p.developer('Jeremy Kemper', 'jeremy@bitsweat.net')
|
9
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
|
+
p.extra_deps = [['activesupport','>= 2.2.2']]
|
11
|
+
p.extra_dev_deps = [['newgem', ">= #{::Newgem::VERSION}"]]
|
12
|
+
|
13
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
14
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
15
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
16
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
20
|
+
|
21
|
+
task :default => :features
|
data/Todo.txt
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
= TODO
|
2
2
|
|
3
|
-
*
|
3
|
+
* default #manifest to clone over any folders + files + apply erb to any *.erb files
|
4
|
+
* rspec examples generated for application_generator and component_generator as per newgem
|
5
|
+
* Labels for displays based on scope (common, rails, newgem), not rubygems, builtin, etc. Perhaps use one PathSource per scope.
|
4
6
|
See RubiGen::Scripts::Base#usage_message
|
5
|
-
* Local generators (~/.rubigen) can be scoped (~/.rubigen/
|
7
|
+
* Local generators (~/.rubigen) can be scoped (~/.rubigen/rails_generators)
|
data/bin/install_rubigen_scripts
CHANGED
File without changes
|
data/bin/rubigen
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-12-27.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/rubigen")
|
7
|
+
|
8
|
+
require "rubigen/cli"
|
9
|
+
|
10
|
+
Rubigen::CLI.execute(STDOUT, ARGV, :destination => File.expand_path("."))
|
data/bin/ruby_app
CHANGED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Development processes of newgem itself (rake tasks)
|
2
|
+
|
3
|
+
As a Newgem maintainer or contributor
|
4
|
+
I want rake tasks to maintain and release the gem
|
5
|
+
So that I can spend time on the tests and code, and not excessive time on maintenance processes
|
6
|
+
|
7
|
+
Scenario: Generate RubyGem
|
8
|
+
Given this project is active project folder
|
9
|
+
And 'pkg' folder is deleted
|
10
|
+
When task 'rake gem' is invoked
|
11
|
+
Then folder 'pkg' is created
|
12
|
+
And file with name matching 'pkg/*.gem' is created else you should run "rake manifest" to fix this
|
13
|
+
And gem spec key 'rdoc_options' contains /--mainREADME.rdoc/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Generators offer help/usage details
|
2
|
+
In order to reduce cost of learning about a new generator
|
3
|
+
As a generator user
|
4
|
+
I want help/usage details about generators
|
5
|
+
|
6
|
+
Scenario: List of visible generators for rubygems
|
7
|
+
Given a safe folder
|
8
|
+
When run local executable 'rubigen rubygems' with arguments ''
|
9
|
+
Then output does match /application_generator/
|
10
|
+
And output does match /component_generator/
|
11
|
+
And output does not match /migration/ # from rails scope
|
12
|
+
|
13
|
+
|
14
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: rubigen command-line interface to access generators anywhere
|
2
|
+
In order to reduce cost of using rubigen
|
3
|
+
As a Ruby developer
|
4
|
+
I want to execute generators anywhere without a script/generate helper script
|
5
|
+
|
6
|
+
Scenario: Run a component generator
|
7
|
+
Given a safe folder
|
8
|
+
When run local executable 'rubigen' with arguments 'rubygems component_generator foo bar'
|
9
|
+
Then file 'bar_generators/foo/foo_generator.rb' is created
|
10
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
def in_project_folder(&block)
|
2
|
+
project_folder = @active_project_folder || @tmp_root
|
3
|
+
FileUtils.chdir(project_folder, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def in_home_folder(&block)
|
7
|
+
FileUtils.chdir(@home_path, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
Given %r{^a safe folder} do
|
11
|
+
FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp"
|
12
|
+
FileUtils.mkdir_p @tmp_root
|
13
|
+
FileUtils.mkdir_p @home_path = File.expand_path(File.join(@tmp_root, "home"))
|
14
|
+
@lib_path = File.expand_path(File.dirname(__FILE__) + '/../../lib')
|
15
|
+
Given "env variable $HOME set to '#{@home_path}'"
|
16
|
+
end
|
17
|
+
|
18
|
+
Given %r{^this project is active project folder} do
|
19
|
+
Given "a safe folder"
|
20
|
+
@active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
|
21
|
+
end
|
22
|
+
|
23
|
+
Given %r{^env variable \$([\w_]+) set to '(.*)'} do |env_var, value|
|
24
|
+
ENV[env_var] = value
|
25
|
+
end
|
26
|
+
|
27
|
+
def force_local_lib_override(project_name = @project_name)
|
28
|
+
rakefile = File.read(File.join(project_name, 'Rakefile'))
|
29
|
+
File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
|
30
|
+
f << "$:.unshift('#{@lib_path}')\n"
|
31
|
+
f << rakefile
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_active_project_folder project_name
|
36
|
+
@active_project_folder = File.join(@tmp_root, project_name)
|
37
|
+
@project_name = project_name
|
38
|
+
end
|
39
|
+
|
40
|
+
Given %r{'(.*)' folder is deleted} do |folder|
|
41
|
+
in_project_folder do
|
42
|
+
FileUtils.rm_rf folder
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
When %r{^'(.*)' generator is invoked with arguments '(.*)'$} do |generator, arguments|
|
47
|
+
@stdout = StringIO.new
|
48
|
+
FileUtils.chdir(@active_project_folder) do
|
49
|
+
if Object.const_defined?("APP_ROOT")
|
50
|
+
APP_ROOT.replace(FileUtils.pwd)
|
51
|
+
else
|
52
|
+
APP_ROOT = FileUtils.pwd
|
53
|
+
end
|
54
|
+
run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
|
55
|
+
end
|
56
|
+
File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
|
57
|
+
@stdout.rewind
|
58
|
+
f << @stdout.read
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
When %r{run executable '(.*)' with arguments '(.*)'} do |executable, arguments|
|
63
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
64
|
+
in_project_folder do
|
65
|
+
system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
When %r{run project executable '(.*)' with arguments '(.*)'} do |executable, arguments|
|
70
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
71
|
+
in_project_folder do
|
72
|
+
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
When %r{run local executable '(.*)' with arguments '(.*)'} do |executable, arguments|
|
77
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
78
|
+
@stderr = File.expand_path(File.join(@tmp_root, "executable.err"))
|
79
|
+
executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
|
80
|
+
in_project_folder do
|
81
|
+
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stderr}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
When %r{^task 'rake (.*)' is invoked$} do |task|
|
86
|
+
@stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
|
87
|
+
FileUtils.chdir(@active_project_folder) do
|
88
|
+
system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
Then %r{^folder '(.*)' (is|is not) created} do |folder, is|
|
93
|
+
in_project_folder do
|
94
|
+
File.exists?(folder).should(is == 'is' ? be_true : be_false)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Then %r{^file '(.*)' (is|is not) created} do |file, is|
|
99
|
+
in_project_folder do
|
100
|
+
File.exists?(file).should(is == 'is' ? be_true : be_false)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
Then %r{^file with name matching '(.*)' is created} do |pattern|
|
105
|
+
in_project_folder do
|
106
|
+
Dir[pattern].should_not be_empty
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Then %r{gem file '(.*)' and generated file '(.*)' should be the same} do |gem_file, project_file|
|
111
|
+
File.exists?(gem_file).should be_true
|
112
|
+
File.exists?(project_file).should be_true
|
113
|
+
gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
|
114
|
+
project_file_contents = File.read(File.join(@active_project_folder, project_file))
|
115
|
+
project_file_contents.should == gem_file_contents
|
116
|
+
end
|
117
|
+
|
118
|
+
Then %r{^output same as contents of '(.*)'$} do |file|
|
119
|
+
expected_output = File.read(File.join(File.dirname(__FILE__) + "/../expected_outputs", file))
|
120
|
+
actual_output = File.read(File.dirname(__FILE__) + "/../../tmp/#{@stdout}")
|
121
|
+
actual_output.should == expected_output
|
122
|
+
end
|
123
|
+
|
124
|
+
Then %r{^(does|does not) invoke generator '(.*)'$} do |does_invoke, generator|
|
125
|
+
actual_output = File.read(@stdout)
|
126
|
+
does_invoke == "does" ?
|
127
|
+
actual_output.should(match(/dependency\s+#{generator}/)) :
|
128
|
+
actual_output.should_not(match(/dependency\s+#{generator}/))
|
129
|
+
end
|
130
|
+
|
131
|
+
Then %r{help options '(.*)' and '(.*)' are displayed} do |opt1, opt2|
|
132
|
+
actual_output = File.read(@stdout)
|
133
|
+
actual_output.should match(/#{opt1}/)
|
134
|
+
actual_output.should match(/#{opt2}/)
|
135
|
+
end
|
136
|
+
|
137
|
+
Then %r{^output (does|does not) match \/(.*)\/} do |does, regex|
|
138
|
+
actual_output = File.read(@stdout)
|
139
|
+
(does == 'does') ?
|
140
|
+
actual_output.should(match(/#{regex}/)) :
|
141
|
+
actual_output.should_not(match(/#{regex}/))
|
142
|
+
end
|
143
|
+
|
144
|
+
Then %r{^contents of file '(.*)' (does|does not) match \/(.*)\/} do |file, does, regex|
|
145
|
+
in_project_folder do
|
146
|
+
actual_output = File.read(file)
|
147
|
+
(does == 'does') ?
|
148
|
+
actual_output.should(match(/#{regex}/)) :
|
149
|
+
actual_output.should_not(match(/#{regex}/))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
Then %r{^all (\d+) tests pass} do |expected_test_count|
|
154
|
+
expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
|
155
|
+
actual_output = File.read(@stdout)
|
156
|
+
actual_output.should match(expected)
|
157
|
+
end
|
158
|
+
|
159
|
+
Then %r{^all (\d+) examples pass} do |expected_test_count|
|
160
|
+
expected = %r{^#{expected_test_count} examples?, 0 failures}
|
161
|
+
actual_output = File.read(@stdout)
|
162
|
+
actual_output.should match(expected)
|
163
|
+
end
|
164
|
+
|
165
|
+
Then %r{^yaml file '(.*)' contains (\{.*\})} do |file, yaml|
|
166
|
+
in_project_folder do
|
167
|
+
yaml = eval yaml
|
168
|
+
YAML.load(File.read(file)).should == yaml
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
Then %r{^Rakefile can display tasks successfully} do
|
173
|
+
@stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
|
174
|
+
FileUtils.chdir(@active_project_folder) do
|
175
|
+
system "rake -T > #{@stdout} 2> #{@stdout}"
|
176
|
+
end
|
177
|
+
actual_output = File.read(@stdout)
|
178
|
+
actual_output.should match(/^rake\s+\w+\s+#\s.*/)
|
179
|
+
end
|
180
|
+
|
181
|
+
Then %r{^task 'rake (.*)' is executed successfully} do |task|
|
182
|
+
@stdout.should_not be_nil
|
183
|
+
actual_output = File.read(@stdout)
|
184
|
+
actual_output.should_not match(/^Don't know how to build task '#{task}'/)
|
185
|
+
actual_output.should_not match(/Error/i)
|
186
|
+
end
|
187
|
+
|
188
|
+
Then %r{^gem spec key '(.*)' contains \/(.*)\/} do |key, regex|
|
189
|
+
in_project_folder do
|
190
|
+
gem_file = Dir["pkg/*.gem"].first
|
191
|
+
gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
|
192
|
+
spec_value = gem_spec.send(key.to_sym)
|
193
|
+
spec_value.to_s.should match(/#{regex}/)
|
194
|
+
end
|
195
|
+
end
|
data/lib/rubigen/base.rb
CHANGED
@@ -35,7 +35,7 @@ require File.dirname(__FILE__) + '/generated_attribute'
|
|
35
35
|
# directory.
|
36
36
|
#
|
37
37
|
# The filenames of the templates don't matter, but choose something that
|
38
|
-
# will be self-
|
38
|
+
# will be self-explanatory since you will be referencing these in the
|
39
39
|
# +manifest+ method inside your generator subclass.
|
40
40
|
#
|
41
41
|
#
|
@@ -86,6 +86,11 @@ module RubiGen
|
|
86
86
|
# A logger instance available everywhere in the generator.
|
87
87
|
cattr_accessor :logger
|
88
88
|
|
89
|
+
# Either RubiGen::Base, or a subclass (e.g. Rails::Generator::Base)
|
90
|
+
# Currently used to determine the lookup paths via the overriden const_missing mechansim
|
91
|
+
# in lookup.rb
|
92
|
+
cattr_accessor :active
|
93
|
+
|
89
94
|
# Every generator that is dynamically looked up is tagged with a
|
90
95
|
# Spec describing where it was found.
|
91
96
|
class_inheritable_accessor :spec
|
@@ -102,6 +107,8 @@ module RubiGen
|
|
102
107
|
@destination_root = options[:destination]
|
103
108
|
elsif defined? ::APP_ROOT
|
104
109
|
@destination_root = ::APP_ROOT
|
110
|
+
elsif defined? ::RAILS_ROOT
|
111
|
+
@destination_root = ::RAILS_ROOT
|
105
112
|
end
|
106
113
|
|
107
114
|
# Silence the logger if requested.
|
@@ -163,6 +170,9 @@ module RubiGen
|
|
163
170
|
name
|
164
171
|
end
|
165
172
|
|
173
|
+
def after_generate
|
174
|
+
end
|
175
|
+
|
166
176
|
protected
|
167
177
|
# Convenience method for generator subclasses to record a manifest.
|
168
178
|
def record
|
data/lib/rubigen/cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Rubigen
|
4
|
+
class CLI
|
5
|
+
attr_reader :stdout
|
6
|
+
|
7
|
+
def self.execute(stdout, arguments, runtime_arguments = {})
|
8
|
+
self.new.execute(stdout, arguments, runtime_arguments)
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(stdout, arguments, runtime_arguments = {})
|
12
|
+
@stdout = stdout
|
13
|
+
main_usage and return unless scope = arguments.shift
|
14
|
+
scopes = scope.split(",").map(&:to_sym)
|
15
|
+
|
16
|
+
runtime_arguments.merge!(:stdout => stdout, :no_exit => true)
|
17
|
+
RubiGen::Base.logger = RubiGen::SimpleLogger.new(stdout)
|
18
|
+
|
19
|
+
require 'rubigen/scripts/generate'
|
20
|
+
RubiGen::Base.use_component_sources!(scopes)
|
21
|
+
RubiGen::Scripts::Generate.new.run(arguments, runtime_arguments)
|
22
|
+
end
|
23
|
+
|
24
|
+
def main_usage
|
25
|
+
stdout.puts <<-USAGE.gsub(/^ /, '')
|
26
|
+
Usage: $0 scope generator [options for generator]
|
27
|
+
USAGE
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|