merb-gen 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +14 -2
- data/Rakefile +43 -27
- data/TODO +13 -0
- data/bin/merb-gen +5 -93
- data/lib/generators/controller.rb +44 -0
- data/lib/generators/freezer.rb +19 -0
- data/lib/generators/helper.rb +31 -0
- data/lib/generators/layout.rb +27 -0
- data/lib/generators/merb.rb +24 -0
- data/lib/generators/merb/merb_flat.rb +27 -0
- data/lib/generators/merb/merb_full.rb +35 -0
- data/lib/generators/merb/merb_very_flat.rb +29 -0
- data/lib/generators/merb_plugin.rb +29 -0
- data/lib/generators/migration.rb +54 -0
- data/lib/generators/model.rb +47 -0
- data/lib/generators/part_controller.rb +33 -0
- data/lib/generators/resource.rb +32 -0
- data/lib/generators/resource_controller.rb +78 -0
- data/lib/generators/session_migration.rb +34 -0
- data/lib/generators/templates/application/merb/Rakefile +75 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/controllers/application.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/controllers/exceptions.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/helpers/global_helpers.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/views/exceptions/internal_server_error.html.erb +1 -1
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/views/exceptions/not_acceptable.html.erb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/views/exceptions/not_found.html.erb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/autotest/discover.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/autotest/merb.rb +2 -2
- data/lib/generators/templates/application/merb/autotest/merb_rspec.rb +166 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/development.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/production.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/rake.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/test.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/init.rb +38 -27
- data/lib/generators/templates/application/merb/config/rack.rb +12 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/router.rb +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/public/images/merb.jpg +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/public/merb.fcgi +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/public/stylesheets/master.css +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/spec/spec.opts +0 -0
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/spec/spec_helper.rb +3 -1
- data/{app_generators/merb/templates → lib/generators/templates/application/merb}/test/test_helper.rb +0 -0
- data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/README.txt +0 -0
- data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/application.rb +0 -0
- data/lib/generators/templates/application/merb_flat/config/framework.rb +7 -0
- data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/config/init.rb +0 -1
- data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/views/foo.html.erb +0 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/LICENSE +0 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/README +0 -0
- data/lib/generators/templates/application/merb_plugin/Rakefile +59 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/TODO +0 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/lib/%base_name%.rb +1 -1
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/lib/%base_name%/merbtasks.rb +1 -1
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/spec/%base_name%_spec.rb +0 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/spec/spec_helper.rb +0 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/test/%base_name%_test.rb +0 -0
- data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/test/test_helper.rb +0 -0
- data/lib/generators/templates/application/merb_very_flat/application.rbt +17 -0
- data/lib/generators/templates/component/controller/app/controllers/%file_name%.rb +11 -0
- data/lib/generators/templates/component/controller/app/views/%file_name%/index.html.erb +1 -0
- data/lib/generators/templates/component/controller/spec/controllers/%file_name%_spec.rb +7 -0
- data/lib/generators/templates/component/controller/test/controllers/%file_name%_test.rb +17 -0
- data/lib/generators/templates/component/freezer/script/frozen_merb +43 -0
- data/lib/generators/templates/component/helper/app/helpers/%file_name%_helper.rb +7 -0
- data/lib/generators/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +5 -0
- data/{app_generators/merb/templates/app/views/layout/application.html.erb → lib/generators/templates/component/layout/app/views/layout/%file_name%.html.erb} +0 -0
- data/lib/generators/templates/component/layout/spec/views/layout/%file_name%.html.erb_spec.rb +1 -0
- data/lib/generators/templates/component/model/app/models/%file_name%.rb +7 -0
- data/lib/generators/templates/component/model/spec/models/%file_name%_spec.rb +7 -0
- data/lib/generators/templates/component/model/test/models/%file_name%_test.rb +9 -0
- data/lib/generators/templates/component/part_controller/app/parts/%file_name%_part.rb +9 -0
- data/lib/generators/templates/component/part_controller/app/parts/views/%file_name%_part/index.html.erb +3 -0
- data/lib/generators/templates/component/resource_controller/app/controllers/%file_name%.rb +44 -0
- data/lib/generators/templates/component/resource_controller/app/views/%file_name%/edit.html.erb +3 -0
- data/lib/generators/templates/component/resource_controller/app/views/%file_name%/index.html.erb +3 -0
- data/lib/generators/templates/component/resource_controller/app/views/%file_name%/new.html.erb +3 -0
- data/lib/generators/templates/component/resource_controller/app/views/%file_name%/show.html.erb +3 -0
- data/lib/generators/templates/component/resource_controller/spec/controllers/%file_name%_spec.rb +7 -0
- data/lib/generators/templates/component/resource_controller/test/controllers/%file_name%_test.rb +17 -0
- data/lib/merb-gen.rb +34 -36
- data/lib/merb-gen/generator.rb +54 -0
- data/lib/merb-gen/named_generator.rb +33 -0
- data/lib/merb-gen/namespaced_generator.rb +47 -0
- data/lib/merb-gen/spec_helper.rb +65 -0
- data/spec/controller_spec.rb +106 -0
- data/spec/fixtures/results/no_modules.test +1 -0
- data/spec/fixtures/results/some_modules.test +5 -0
- data/spec/fixtures/templates/no_modules.test +3 -0
- data/spec/fixtures/templates/some_modules.test +3 -0
- data/spec/freezer_spec.rb +17 -0
- data/spec/generator_spec.rb +51 -0
- data/spec/helper_spec.rb +43 -0
- data/spec/layout_spec.rb +25 -0
- data/spec/merb_flat_spec.rb +21 -0
- data/spec/merb_full_spec.rb +31 -0
- data/spec/merb_plugin_spec.rb +21 -0
- data/spec/merb_spec.rb +20 -0
- data/spec/merb_very_flat_spec.rb +19 -0
- data/spec/migration_spec.rb +47 -0
- data/spec/model_spec.rb +66 -0
- data/spec/named_generator_spec.rb +11 -0
- data/spec/namespaced_generator_spec.rb +11 -0
- data/spec/part_controller_spec.rb +74 -0
- data/spec/resource_controller_spec.rb +102 -0
- data/spec/resource_spec.rb +18 -0
- data/spec/session_migration_spec.rb +15 -0
- data/spec/spec_helper.rb +271 -0
- metadata +246 -181
- data/app_generators/merb/USAGE +0 -0
- data/app_generators/merb/merb_generator.rb +0 -40
- data/app_generators/merb/templates/Rakefile +0 -34
- data/app_generators/merb/templates/autotest/merb_rspec.rb +0 -223
- data/app_generators/merb/templates/config/rack.rb +0 -1
- data/app_generators/merb_flat/merb_flat_generator.rb +0 -22
- data/app_generators/merb_flat/templates/config/framework.rb +0 -5
- data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -22
- data/app_generators/merb_plugin/templates/Rakefile +0 -44
- data/app_generators/merb_very_flat/merb_very_flat_generator.rb +0 -37
- data/app_generators/merb_very_flat/templates/%app_file_name%.rb +0 -15
- data/app_generators/merb_very_flat/templates/README.txt +0 -9
- data/lib/merb-gen/base.rb +0 -66
- data/lib/merb-gen/helpers.rb +0 -108
- data/merb_default_generators/model/USAGE +0 -0
- data/merb_default_generators/model/model_generator.rb +0 -40
- data/merb_default_generators/model/templates/app/models/%model_file_name%.rb +0 -5
- data/merb_default_generators/resource_controller/USAGE +0 -0
- data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -74
- data/merb_default_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +0 -46
- data/merb_default_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +0 -16
- data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/delete.html.erb +0 -3
- data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +0 -3
- data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +0 -3
- data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +0 -3
- data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +0 -3
- data/merb_generators/controller/USAGE +0 -0
- data/merb_generators/controller/controller_generator.rb +0 -59
- data/merb_generators/controller/templates/app/controllers/%controller_file_name%.rb +0 -18
- data/merb_generators/controller/templates/app/helpers/%controller_file_name%_helper.rb +0 -16
- data/merb_generators/controller/templates/app/views/%controller_file_name%/index.html.erb +0 -1
- data/merb_generators/part_controller/USAGE +0 -0
- data/merb_generators/part_controller/part_controller_generator.rb +0 -58
- data/merb_generators/part_controller/templates/app/helpers/%controller_file_name%_part_helper.rb +0 -16
- data/merb_generators/part_controller/templates/app/parts/%controller_file_name%_part.rb +0 -18
- data/merb_generators/part_controller/templates/app/parts/views/%controller_file_name%_part/index.html.erb +0 -3
- data/merb_generators/resource/USAGE +0 -0
- data/merb_generators/resource/resource_generator.rb +0 -48
- data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -49
- data/rspec_generators/merb_controller_test/templates/spec/controllers/%controller_full_file_path%_spec.rb +0 -7
- data/rspec_generators/merb_controller_test/templates/spec/helpers/%controller_full_file_path%_helper_spec.rb +0 -5
- data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -35
- data/rspec_generators/merb_model_test/templates/spec/models/%model_file_name%_spec.rb +0 -7
- data/rspec_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +0 -49
- data/rspec_generators/merb_resource_controller_test/templates/spec/controllers/%controller_full_file_path%_spec.rb +0 -7
- data/rspec_generators/merb_resource_controller_test/templates/spec/helpers/%controller_full_file_path%_helpers.rb +0 -5
- data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/delete.html.erb_spec.rb +0 -1
- data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/edit.html.erb_spec.rb +0 -1
- data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/index.html.erb_spec.rb +0 -1
- data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/new.html.erb_spec.rb +0 -1
- data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/show.html.erb_spec.rb +0 -1
- data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -47
- data/test_unit_generators/merb_controller_test/templates/test/functional/%controller_full_file_path%_test.rb +0 -17
- data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -34
- data/test_unit_generators/merb_model_test/templates/test/unit/%model_file_name%_test.rb +0 -9
- data/test_unit_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +0 -31
data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/TODO
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# run very flat apps with merb -I <app file>.
|
2
|
+
|
3
|
+
Merb::Config.use { |c|
|
4
|
+
c[:framework] = { :public => [Merb.root / "public", nil] },
|
5
|
+
c[:session_store] = 'none',
|
6
|
+
c[:exception_details] = true
|
7
|
+
}
|
8
|
+
|
9
|
+
Merb::Router.prepare do |r|
|
10
|
+
r.match('/').to(:controller => '<%= base_name %>', :action =>'index')
|
11
|
+
end
|
12
|
+
|
13
|
+
class <%= class_name %> < Merb::Controller
|
14
|
+
def index
|
15
|
+
"hi"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
You're in index of the <%= class_name %> controller.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, "test_helper")
|
2
|
+
|
3
|
+
# Re-raise errors caught by the controller.
|
4
|
+
class <%= full_class_name %>; def rescue_action(e) raise e end; end
|
5
|
+
|
6
|
+
class <%= full_class_name %>Test < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@controller = <%= full_class_name %>.build(fake_request)
|
10
|
+
@controller.dispatch('index')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Replace this with your real tests.
|
14
|
+
def test_should_be_setup
|
15
|
+
assert false
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
__DIR__ = File.join(File.dirname(__FILE__),"..")
|
4
|
+
|
5
|
+
framework = File.join(__DIR__,"framework")
|
6
|
+
|
7
|
+
if File.directory?(framework)
|
8
|
+
puts "Running from frozen framework"
|
9
|
+
core = File.join(framework,"merb-core")
|
10
|
+
if File.directory?(core)
|
11
|
+
$:.push File.join(core,"lib")
|
12
|
+
end
|
13
|
+
more = File.join(framework,"merb-more")
|
14
|
+
if File.directory?(more)
|
15
|
+
Dir.new(more).select {|d| d =~ /merb-/}.each do |d|
|
16
|
+
$:.push File.join(more,d,'lib')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
plugins = File.join(framework,"merb-plugins")
|
20
|
+
if File.directory?(plugins)
|
21
|
+
Dir.new(plugins).select {|d| d =~ /merb_/}.each do |d|
|
22
|
+
$:.push File.join(plugins,d,'lib')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
require "merb-core/core_ext/kernel"
|
26
|
+
require "merb-core/core_ext/rubygems"
|
27
|
+
else
|
28
|
+
gem = Dir.glob(__DIR__ + "/gems/gems/merb-core-*").last
|
29
|
+
raise "Can't run frozen without framework/ or local gem" unless gem
|
30
|
+
require gem + "/lib/merb-core/core_ext/kernel"
|
31
|
+
require gem + "/lib/merb-core/core_ext/rubygems"
|
32
|
+
|
33
|
+
Gem.clear_paths
|
34
|
+
Gem.path.unshift(__DIR__+"/gems")
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'merb-core'
|
38
|
+
unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
|
39
|
+
ARGV.push *%w[-a mongrel]
|
40
|
+
end
|
41
|
+
|
42
|
+
Merb.frozen!
|
43
|
+
Merb.start
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# TODO: Add a view spec stub here.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<% with_modules(modules) do -%>
|
2
|
+
class <%= class_name %> < Application
|
3
|
+
|
4
|
+
# GET /<%= symbol_name %>
|
5
|
+
def index
|
6
|
+
render
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /<%= symbol_name %>/:id
|
10
|
+
def show
|
11
|
+
render
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /<%= symbol_name %>/new
|
15
|
+
def new
|
16
|
+
render
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /<%= symbol_name %>/:id/edit
|
20
|
+
def edit
|
21
|
+
render
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /<%= symbol_name %>/:id/delete
|
25
|
+
def delete
|
26
|
+
render
|
27
|
+
end
|
28
|
+
|
29
|
+
# POST /<%= symbol_name %>
|
30
|
+
def create
|
31
|
+
render
|
32
|
+
end
|
33
|
+
|
34
|
+
# PUT /<%= symbol_name %>/:id
|
35
|
+
def update
|
36
|
+
render
|
37
|
+
end
|
38
|
+
|
39
|
+
# DELETE /<%= symbol_name %>/:id
|
40
|
+
def destroy
|
41
|
+
render
|
42
|
+
end
|
43
|
+
end
|
44
|
+
<% end -%>
|
data/lib/generators/templates/component/resource_controller/test/controllers/%file_name%_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, "test_helper")
|
2
|
+
|
3
|
+
# Re-raise errors caught by the controller.
|
4
|
+
class <%= full_class_name %>; def rescue_action(e) raise e end; end
|
5
|
+
|
6
|
+
class <%= full_class_name %>Test < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@controller = <%= full_class_name %>.build(fake_request)
|
10
|
+
@controller.dispatch('index')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Replace this with your real tests.
|
14
|
+
def test_should_be_setup
|
15
|
+
assert false
|
16
|
+
end
|
17
|
+
end
|
data/lib/merb-gen.rb
CHANGED
@@ -1,38 +1,36 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
RubiGen::Scripts.const_get(command.capitalize).new.run(argv, :generator => generator, :destination => app_root)
|
36
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'merb-core'
|
3
|
+
require 'sha1'
|
4
|
+
gem 'templater', '>= 0.1.4'
|
5
|
+
require 'templater'
|
6
|
+
|
7
|
+
path = File.join(File.dirname(__FILE__))
|
8
|
+
|
9
|
+
require path / "merb-gen" / "generator"
|
10
|
+
require path / "merb-gen" / "named_generator"
|
11
|
+
require path / "merb-gen" / "namespaced_generator"
|
12
|
+
require path / "merb-gen" / "spec_helper"
|
13
|
+
require path / "generators" / "merb"
|
14
|
+
require path / "generators" / "merb" / "merb_full"
|
15
|
+
require path / "generators" / "merb" / "merb_flat"
|
16
|
+
require path / "generators" / "merb" / "merb_very_flat"
|
17
|
+
require path / "generators" / "merb_plugin"
|
18
|
+
require path / "generators" / "controller"
|
19
|
+
require path / "generators" / "helper"
|
20
|
+
require path / "generators" / "part_controller"
|
21
|
+
require path / "generators" / "migration"
|
22
|
+
require path / "generators" / "session_migration"
|
23
|
+
require path / "generators" / "model"
|
24
|
+
require path / "generators" / "resource_controller"
|
25
|
+
require path / "generators" / "resource"
|
26
|
+
require path / "generators" / "freezer"
|
27
|
+
require path / "generators" / "layout"
|
28
|
+
|
29
|
+
Templater::Discovery.discover!("merb-gen")
|
30
|
+
|
31
|
+
# Require all generators that plugins have added to merb, after the app has loaded.
|
32
|
+
Merb::BootLoader.after_app_loads do
|
33
|
+
Merb.generators.each do |file|
|
34
|
+
require file
|
37
35
|
end
|
38
36
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
extend Templater::Manifold
|
6
|
+
|
7
|
+
desc <<-DESC
|
8
|
+
Generate components for your application or entirely new applications.
|
9
|
+
DESC
|
10
|
+
|
11
|
+
class Generator < Templater::Generator
|
12
|
+
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
options[:orm] ||= Merb.orm_generator_scope
|
16
|
+
options[:testing_framework] ||= Merb.test_framework_generator_scope
|
17
|
+
|
18
|
+
options[:orm] = :none if options[:orm] == :merb_default # FIXME: temporary until this is fixed in merb-core
|
19
|
+
end
|
20
|
+
|
21
|
+
# Inside a template, wraps a block of code properly in modules, keeping the indentation correct
|
22
|
+
#
|
23
|
+
# @param modules<Array[#to_s]> an array of modules to use for nesting
|
24
|
+
# @option indent<Integer> number of integers to indent the modules by
|
25
|
+
def with_modules(modules, options={}, &block)
|
26
|
+
indent = options[:indent] || 0
|
27
|
+
text = capture(&block)
|
28
|
+
modules.each_with_index do |mod, i|
|
29
|
+
concat((" " * (indent + i)) + "module #{mod}\n", block.binding)
|
30
|
+
end
|
31
|
+
text = text.to_a.map{ |line| (" " * modules.size) + line }.join
|
32
|
+
concat(text, block.binding)
|
33
|
+
modules.reverse.each_with_index do |mod, i|
|
34
|
+
concat((" " * (indent + modules.size - i - 1)) + "end # #{mod}\n", block.binding)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a string of num times '..', useful for example in tests for namespaced generators
|
39
|
+
# to find the spec_helper higher up in the directory structure.
|
40
|
+
#
|
41
|
+
# @param num<Integer> number of directories up
|
42
|
+
# @return <String> concatenated string
|
43
|
+
def go_up(num)
|
44
|
+
(["'..'"] * num).join(', ')
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.source_root
|
48
|
+
File.join(File.dirname(__FILE__), '..', 'generators', 'templates')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Merb
|
2
|
+
module Generators
|
3
|
+
|
4
|
+
class NamedGenerator < Generator
|
5
|
+
|
6
|
+
# NOTE: Currently this is not inherited, it will have to be declared in each generator
|
7
|
+
# that inherits from this.
|
8
|
+
first_argument :name, :required => true
|
9
|
+
|
10
|
+
def class_name
|
11
|
+
name.gsub('-', '_').camel_case
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :module_name, :class_name
|
15
|
+
|
16
|
+
def test_class_name
|
17
|
+
class_name + "Test"
|
18
|
+
end
|
19
|
+
|
20
|
+
def file_name
|
21
|
+
name.snake_case
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :base_name, :file_name
|
25
|
+
|
26
|
+
def symbol_name
|
27
|
+
file_name.gsub('-', '_')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|