merb 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +25 -26
- data/Rakefile +48 -36
- data/app_generators/merb/USAGE +5 -0
- data/app_generators/merb/merb_generator.rb +107 -0
- data/app_generators/merb/templates/Rakefile +99 -0
- data/{examples/skeleton/dist → app_generators/merb/templates}/app/controllers/application.rb +1 -1
- data/app_generators/merb/templates/app/controllers/exceptions.rb +13 -0
- data/{examples/skeleton/dist → app_generators/merb/templates}/app/helpers/global_helper.rb +0 -0
- data/{examples/skeleton/dist/app/mailers → app_generators/merb/templates/app/mailers/views}/layout/application.erb +0 -0
- data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +207 -0
- data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +38 -0
- data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +40 -0
- data/app_generators/merb/templates/app/views/layout/application.html.erb +11 -0
- data/app_generators/merb/templates/config/boot.rb +11 -0
- data/app_generators/merb/templates/config/dependencies.rb +41 -0
- data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/development.rb +0 -0
- data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/production.rb +0 -0
- data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/test.rb +0 -0
- data/app_generators/merb/templates/config/merb.yml +64 -0
- data/app_generators/merb/templates/config/merb_init.rb +16 -0
- data/app_generators/merb/templates/config/plugins.yml +1 -0
- data/app_generators/merb/templates/config/router.rb +32 -0
- data/{lib/merb/core_ext/merb_array.rb → app_generators/merb/templates/config/upload.conf} +0 -0
- data/app_generators/merb/templates/public/images/merb.jpg +0 -0
- data/app_generators/merb/templates/public/merb.fcgi +6 -0
- data/app_generators/merb/templates/public/stylesheets/master.css +119 -0
- data/app_generators/merb/templates/script/destroy +28 -0
- data/app_generators/merb/templates/script/generate +28 -0
- data/{examples/skeleton → app_generators/merb/templates}/script/stop_merb +0 -0
- data/app_generators/merb/templates/script/win_script.cmd +1 -0
- data/app_generators/merb/templates/spec/spec.opts +6 -0
- data/app_generators/merb/templates/spec/spec_helper.rb +10 -0
- data/app_generators/merb/templates/test/test_helper.rb +13 -0
- data/app_generators/merb_plugin/USAGE +5 -0
- data/app_generators/merb_plugin/merb_plugin_generator.rb +64 -0
- data/app_generators/merb_plugin/templates/LICENSE +20 -0
- data/app_generators/merb_plugin/templates/README +4 -0
- data/app_generators/merb_plugin/templates/Rakefile +35 -0
- data/app_generators/merb_plugin/templates/TODO +5 -0
- data/app_generators/merb_plugin/templates/merbtasks.rb +6 -0
- data/app_generators/merb_plugin/templates/sampleplugin.rb +10 -0
- data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +7 -0
- data/app_generators/merb_plugin/templates/spec_helper.rb +2 -0
- data/bin/merb +1 -1
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/merb_rspec.rb +79 -0
- data/lib/merb.rb +72 -93
- data/lib/merb/{merb_abstract_controller.rb → abstract_controller.rb} +28 -5
- data/lib/merb/caching/action_cache.rb +65 -29
- data/lib/merb/caching/fragment_cache.rb +9 -4
- data/lib/merb/caching/store/file_cache.rb +22 -14
- data/lib/merb/caching/store/memory_cache.rb +26 -8
- data/lib/merb/{merb_constants.rb → constants.rb} +9 -7
- data/lib/merb/controller.rb +178 -0
- data/lib/merb/core_ext.rb +13 -11
- data/lib/merb/core_ext/array.rb +0 -0
- data/lib/merb/core_ext/{merb_class.rb → class.rb} +0 -0
- data/lib/merb/core_ext/{merb_enumerable.rb → enumerable.rb} +0 -0
- data/lib/merb/core_ext/get_args.rb +52 -0
- data/lib/merb/core_ext/{merb_hash.rb → hash.rb} +40 -11
- data/lib/merb/core_ext/{merb_inflections.rb → inflections.rb} +0 -0
- data/lib/merb/core_ext/{merb_inflector.rb → inflector.rb} +1 -1
- data/lib/merb/core_ext/{merb_kernel.rb → kernel.rb} +56 -3
- data/lib/merb/core_ext/mash.rb +88 -0
- data/lib/merb/core_ext/{merb_module.rb → module.rb} +0 -0
- data/lib/merb/core_ext/{merb_numeric.rb → numeric.rb} +0 -0
- data/lib/merb/core_ext/{merb_object.rb → object.rb} +10 -47
- data/lib/merb/core_ext/string.rb +56 -0
- data/lib/merb/core_ext/{merb_symbol.rb → symbol.rb} +0 -0
- data/lib/merb/dispatcher.rb +109 -0
- data/lib/merb/{merb_drb_server.rb → drb_server.rb} +0 -0
- data/lib/merb/erubis_ext.rb +10 -0
- data/lib/merb/exceptions.rb +173 -0
- data/lib/merb/generators/merb_app/merb_app.rb +5 -25
- data/lib/merb/generators/merb_generator_helpers.rb +317 -0
- data/lib/merb/generators/merb_plugin.rb +19 -0
- data/lib/merb/logger.rb +65 -0
- data/lib/merb/{merb_mail_controller.rb → mail_controller.rb} +102 -49
- data/lib/merb/{merb_mailer.rb → mailer.rb} +31 -27
- data/lib/merb/mixins/{basic_authentication_mixin.rb → basic_authentication.rb} +3 -3
- data/lib/merb/mixins/{controller_mixin.rb → controller.rb} +131 -112
- data/lib/merb/mixins/{erubis_capture_mixin.rb → erubis_capture.rb} +12 -21
- data/lib/merb/mixins/{form_control_mixin.rb → form_control.rb} +6 -12
- data/lib/merb/mixins/render.rb +401 -0
- data/lib/merb/mixins/responder.rb +378 -0
- data/lib/merb/mixins/{view_context_mixin.rb → view_context.rb} +65 -10
- data/lib/merb/mixins/web_controller.rb +29 -0
- data/lib/merb/{merb_handler.rb → mongrel_handler.rb} +59 -38
- data/lib/merb/part_controller.rb +19 -0
- data/lib/merb/plugins.rb +16 -0
- data/lib/merb/rack_adapter.rb +37 -0
- data/lib/merb/request.rb +421 -0
- data/lib/merb/router.rb +576 -0
- data/lib/merb/{merb_server.rb → server.rb} +275 -71
- data/lib/merb/session.rb +10 -10
- data/lib/merb/session/cookie_store.rb +125 -0
- data/lib/merb/session/{merb_mem_cache_session.rb → mem_cache_session.rb} +22 -9
- data/lib/merb/session/{merb_memory_session.rb → memory_session.rb} +15 -11
- data/lib/merb/template.rb +35 -8
- data/lib/merb/template/erubis.rb +16 -10
- data/lib/merb/template/haml.rb +33 -20
- data/lib/merb/template/markaby.rb +16 -14
- data/lib/merb/template/xml_builder.rb +8 -4
- data/lib/merb/test/{merb_fake_request.rb → fake_request.rb} +11 -5
- data/lib/merb/test/helper.rb +31 -0
- data/lib/merb/test/hpricot.rb +136 -0
- data/lib/merb/test/{merb_multipart.rb → multipart.rb} +1 -1
- data/lib/merb/test/rspec.rb +93 -0
- data/lib/merb/{merb_upload_handler.rb → upload_handler.rb} +5 -6
- data/lib/merb/{merb_upload_progress.rb → upload_progress.rb} +1 -1
- data/lib/merb/{merb_view_context.rb → view_context.rb} +27 -42
- data/lib/{merb_tasks.rb → tasks.rb} +0 -0
- data/lib/tasks/merb.rake +21 -11
- data/merb_default_generators/model/USAGE +0 -0
- data/merb_default_generators/model/model_generator.rb +16 -0
- data/merb_default_generators/model/templates/new_model_template.erb +5 -0
- data/merb_default_generators/resource_controller/USAGE +0 -0
- data/merb_default_generators/resource_controller/resource_controller_generator.rb +26 -0
- data/merb_default_generators/resource_controller/templates/controller.rb +30 -0
- data/merb_default_generators/resource_controller/templates/edit.html.erb +1 -0
- data/merb_default_generators/resource_controller/templates/helper.rb +5 -0
- data/merb_default_generators/resource_controller/templates/index.html.erb +1 -0
- data/merb_default_generators/resource_controller/templates/new.html.erb +1 -0
- data/merb_default_generators/resource_controller/templates/show.html.erb +1 -0
- data/merb_generators/controller/USAGE +5 -0
- data/merb_generators/controller/controller_generator.rb +16 -0
- data/merb_generators/controller/templates/controller.rb +8 -0
- data/merb_generators/controller/templates/helper.rb +5 -0
- data/merb_generators/controller/templates/index.html.erb +3 -0
- data/merb_generators/resource/USAGE +0 -0
- data/merb_generators/resource/resource_generator.rb +60 -0
- data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +67 -0
- data/rspec_generators/merb_controller_test/templates/controller_spec.rb +8 -0
- data/rspec_generators/merb_controller_test/templates/edit_spec.rb +12 -0
- data/rspec_generators/merb_controller_test/templates/helper_spec.rb +5 -0
- data/rspec_generators/merb_controller_test/templates/index_spec.rb +12 -0
- data/rspec_generators/merb_controller_test/templates/new_spec.rb +12 -0
- data/rspec_generators/merb_controller_test/templates/show_spec.rb +5 -0
- data/rspec_generators/merb_model_test/merb_model_test_generator.rb +26 -0
- data/rspec_generators/merb_model_test/templates/model_spec_template.erb +7 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +53 -0
- data/test_unit_generators/merb_controller_test/templates/functional_test.rb +17 -0
- data/test_unit_generators/merb_controller_test/templates/helper_test.rb +9 -0
- data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +29 -0
- data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +9 -0
- metadata +172 -94
- data/examples/README_EXAMPLES +0 -10
- data/examples/skeleton/Rakefile +0 -68
- data/examples/skeleton/dist/app/views/layout/application.herb +0 -12
- data/examples/skeleton/dist/conf/database.yml +0 -23
- data/examples/skeleton/dist/conf/merb.yml +0 -57
- data/examples/skeleton/dist/conf/merb_init.rb +0 -24
- data/examples/skeleton/dist/conf/router.rb +0 -22
- data/examples/skeleton/dist/conf/upload.conf +0 -5
- data/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb +0 -14
- data/examples/skeleton/script/new_migration +0 -21
- data/lib/merb/core_ext/merb_string.rb +0 -18
- data/lib/merb/merb_controller.rb +0 -206
- data/lib/merb/merb_dispatcher.rb +0 -87
- data/lib/merb/merb_exceptions.rb +0 -319
- data/lib/merb/merb_part_controller.rb +0 -42
- data/lib/merb/merb_plugins.rb +0 -293
- data/lib/merb/merb_request.rb +0 -165
- data/lib/merb/merb_router.rb +0 -309
- data/lib/merb/merb_yaml_store.rb +0 -31
- data/lib/merb/mixins/render_mixin.rb +0 -283
- data/lib/merb/mixins/responder_mixin.rb +0 -159
- data/lib/merb/session/merb_ar_session.rb +0 -131
- data/lib/merb/vendor/paginator/README.txt +0 -84
- data/lib/merb/vendor/paginator/paginator.rb +0 -124
- data/lib/tasks/db.rake +0 -55
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
require File.dirname(__FILE__)+'/mixins/view_context_mixin'
|
3
|
-
require File.dirname(__FILE__)+'/mixins/form_control_mixin'
|
1
|
+
|
4
2
|
|
5
3
|
module Merb
|
6
4
|
PROTECTED_IVARS = %w[@_new_cookie
|
7
5
|
@method
|
8
6
|
@env
|
9
|
-
@
|
7
|
+
@web_controller
|
10
8
|
@_body
|
11
9
|
@_fingerprint_before
|
12
10
|
@_session
|
@@ -16,7 +14,18 @@ module Merb
|
|
16
14
|
@_status
|
17
15
|
@_view_context_cache
|
18
16
|
@_response
|
19
|
-
@_params
|
17
|
+
@_params
|
18
|
+
@thrown_content
|
19
|
+
@_route
|
20
|
+
@_benchmarks
|
21
|
+
@_provided_formats
|
22
|
+
@_format_value
|
23
|
+
@_content_type
|
24
|
+
@_merb_unmatched
|
25
|
+
@_template_format
|
26
|
+
@_provided_formats
|
27
|
+
@template]
|
28
|
+
|
20
29
|
|
21
30
|
module GlobalHelper
|
22
31
|
end
|
@@ -26,18 +35,18 @@ module Merb
|
|
26
35
|
class ViewContext
|
27
36
|
include Merb::ViewContextMixin
|
28
37
|
include Merb::FormControls
|
29
|
-
include Merb::
|
38
|
+
include Merb::WebControllerMixin
|
30
39
|
|
31
40
|
def initialize(controller)
|
41
|
+
@web_controller = controller
|
32
42
|
@_merb_partial_locals = {}
|
33
|
-
@
|
34
|
-
|
35
|
-
self.instance_variable_set(ivar, @controller.instance_variable_get(ivar))
|
43
|
+
(@web_controller.instance_variables - PROTECTED_IVARS).each do |ivar|
|
44
|
+
self.instance_variable_set(ivar, @web_controller.instance_variable_get(ivar))
|
36
45
|
end
|
37
46
|
begin
|
38
|
-
self.class.class_eval("include Merb::#{@
|
47
|
+
self.class.class_eval(" include Merb::GlobalHelper; include Merb::#{@web_controller.class.name}Helper")
|
39
48
|
rescue NameError
|
40
|
-
MERB_LOGGER.
|
49
|
+
MERB_LOGGER.debug("Missing Helper: Merb::#{@web_controller.class.name}Helper")
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
@@ -46,46 +55,22 @@ module Merb
|
|
46
55
|
self
|
47
56
|
end
|
48
57
|
|
49
|
-
# accessor for the view. refers to the current @
|
58
|
+
# accessor for the view. refers to the current @web_controller object
|
50
59
|
def controller
|
51
|
-
@
|
52
|
-
end
|
53
|
-
|
54
|
-
def request
|
55
|
-
@controller.request
|
56
|
-
end
|
57
|
-
|
58
|
-
def params
|
59
|
-
@controller.params
|
60
|
-
end
|
61
|
-
|
62
|
-
def cookies
|
63
|
-
@controller.cookies
|
64
|
-
end
|
65
|
-
|
66
|
-
def headers
|
67
|
-
@controller.headers
|
60
|
+
@web_controller
|
68
61
|
end
|
69
|
-
|
70
|
-
def session
|
71
|
-
@controller.session
|
72
|
-
end
|
73
|
-
|
74
|
-
def response
|
75
|
-
@controller.response
|
76
|
-
end
|
77
|
-
|
62
|
+
|
78
63
|
alias_method :old_respond_to?, :respond_to?
|
79
64
|
|
80
65
|
def respond_to?(sym, include_private=false)
|
81
|
-
old_respond_to?(sym, include_private) || @
|
66
|
+
old_respond_to?(sym, include_private) || @web_controller.respond_to?(sym, include_private) || @_merb_partial_locals.key?(sym)
|
82
67
|
end
|
83
68
|
|
84
69
|
# catch any method calls that the controller responds to
|
85
70
|
# and delegate them back to the controller.
|
86
71
|
def method_missing(sym, *args, &blk)
|
87
|
-
if @
|
88
|
-
@
|
72
|
+
if @web_controller.respond_to? sym
|
73
|
+
@web_controller.send(sym, *args, &blk)
|
89
74
|
elsif @_merb_partial_locals.key? sym
|
90
75
|
@_merb_partial_locals[sym]
|
91
76
|
else
|
@@ -95,4 +80,4 @@ module Merb
|
|
95
80
|
|
96
81
|
end
|
97
82
|
|
98
|
-
end
|
83
|
+
end
|
File without changes
|
data/lib/tasks/merb.rake
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
def install_merb_script
|
2
2
|
script_filepath = MERB_ROOT / 'script/merb'
|
3
3
|
FileUtils.rm script_filepath if File.exist? script_filepath
|
4
|
-
tmpl = "#!/usr/bin/env ruby\nrequire File.expand_path(File.dirname(__FILE__)+'/../
|
4
|
+
tmpl = "#!/usr/bin/env ruby\nrequire File.expand_path(File.dirname(__FILE__)+'/../framework/merb/server')\nMerb::Server.run\n"
|
5
5
|
File.open(script_filepath, 'wb') {|f|
|
6
6
|
f.write tmpl
|
7
7
|
f.chmod(0744)
|
@@ -9,36 +9,46 @@ def install_merb_script
|
|
9
9
|
end
|
10
10
|
|
11
11
|
namespace :merb do
|
12
|
-
desc "freeze the merb framework into
|
12
|
+
desc "freeze the merb framework into merb for portability"
|
13
13
|
task :freeze do
|
14
|
-
FileUtils.rm_rf MERB_ROOT / '
|
15
|
-
FileUtils.cp_r MERB_FRAMEWORK_ROOT, (MERB_ROOT / '
|
14
|
+
FileUtils.rm_rf MERB_ROOT / 'framework'
|
15
|
+
FileUtils.cp_r MERB_FRAMEWORK_ROOT, (MERB_ROOT / 'framework')
|
16
16
|
install_merb_script
|
17
17
|
|
18
|
-
puts " Freezing Merb Framework into
|
18
|
+
puts " Freezing Merb Framework into framework"
|
19
19
|
puts " Use script/merb to start instead of plain merb"
|
20
20
|
end
|
21
21
|
desc "unfreeze this app from the framework and use system gem."
|
22
22
|
task :unfreeze do
|
23
|
-
FileUtils.rm_rf MERB_ROOT / '
|
23
|
+
FileUtils.rm_rf MERB_ROOT / 'framework'
|
24
24
|
FileUtils.rm MERB_ROOT / 'script/merb'
|
25
25
|
|
26
26
|
puts " Removed: "
|
27
|
-
puts " - #{MERB_ROOT / '
|
27
|
+
puts " - #{MERB_ROOT / 'framework'} (recursive) "
|
28
28
|
puts " - #{MERB_ROOT / 'script/merb'}"
|
29
29
|
end
|
30
30
|
|
31
|
-
desc "freeze the merb framework from svn"
|
31
|
+
desc "freeze the merb framework from svn, use REVISION=# to freeze a specific revision"
|
32
32
|
task :freeze_from_svn do
|
33
|
-
install_path = MERB_ROOT / '
|
33
|
+
install_path = MERB_ROOT / 'framework'
|
34
|
+
revision = ENV['REVISION'] || 'HEAD'
|
34
35
|
puts " Removing old framework" if File.exist? install_path
|
35
36
|
FileUtils.rm_rf install_path
|
36
37
|
|
37
|
-
puts " Freezing Merb Framework from svn"
|
38
|
-
system "svn co http://svn.devjavu.com/merb/trunk/lib #{install_path}"
|
38
|
+
puts " Freezing Merb Framework from svn, revision #{revision}"
|
39
|
+
system "svn co -r #{revision} http://svn.devjavu.com/merb/trunk/lib #{install_path}"
|
39
40
|
install_merb_script
|
40
41
|
|
41
42
|
puts " Use script/merb to start instead of plain merb"
|
42
43
|
end
|
43
44
|
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Setup the Merb Environment by requiring merb and loading your merb_init.rb"
|
48
|
+
task :merb_env do
|
49
|
+
require 'rubygems'
|
50
|
+
require 'merb'
|
51
|
+
Merb::Server.config[:environment] = ENV['MERB_ENV'] if ENV['MERB_ENV']
|
52
|
+
MERB_ENV = Merb::Server.config[:environment].nil? ? 'development' : Merb::Server.config[:environment]
|
53
|
+
load MERB_ROOT+'/config/merb_init.rb'
|
44
54
|
end
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'merb/generators/merb_generator_helpers'
|
2
|
+
|
3
|
+
class ModelGenerator < Merb::GeneratorHelpers::ModelGeneratorBase
|
4
|
+
|
5
|
+
def initialize( *args )
|
6
|
+
super( *args )
|
7
|
+
options[:skip_migration] = true
|
8
|
+
@model_template_name = "new_model_template.erb"
|
9
|
+
@model_test_generator_name = "merb_model_test"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.superclass
|
13
|
+
RubiGen::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'merb/generators/merb_generator_helpers'
|
2
|
+
|
3
|
+
class ResourceControllerGenerator < Merb::GeneratorHelpers::ControllerGeneratorBase
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
runtime_options = args.last.is_a?(Hash) ? args.pop : {}
|
7
|
+
name, *actions = args.flatten
|
8
|
+
runtime_options[:actions] = %w[index show new edit]
|
9
|
+
runtime_options[:test_stub_generator] = "merb_controller_test"
|
10
|
+
super( [name], runtime_options )
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.superclass
|
14
|
+
RubiGen::Base
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def banner
|
19
|
+
<<-EOS
|
20
|
+
Creates a Merb controller, views and specs using Active Record Models
|
21
|
+
|
22
|
+
USAGE: #{$0} #{spec.name} resource_name"
|
23
|
+
EOS
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<% klass = class_name.singularize -%>
|
2
|
+
<% ivar = class_name.snake_case.singularize -%>
|
3
|
+
class <%= class_name %> < Application
|
4
|
+
provides :xml, :js, :yaml
|
5
|
+
|
6
|
+
def index
|
7
|
+
render
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
render
|
12
|
+
end
|
13
|
+
|
14
|
+
def new
|
15
|
+
render
|
16
|
+
end
|
17
|
+
|
18
|
+
def edit
|
19
|
+
render
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
end
|
27
|
+
|
28
|
+
def destroy
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Edit Action for <%= class_name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Index Action for <%= class_name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
New Action for <%= class_name %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Show Action for <%= class_name %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'merb/generators/merb_generator_helpers'
|
2
|
+
|
3
|
+
class ControllerGenerator < Merb::GeneratorHelpers::ControllerGeneratorBase
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
runtime_options = args.last.is_a?(Hash) ? args.pop : {}
|
7
|
+
name, *actions = args.flatten
|
8
|
+
runtime_options[:actions] = actions.empty? ? %w[index] : actions
|
9
|
+
super( [name], runtime_options )
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.superclass
|
13
|
+
RubiGen::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'merb'
|
2
|
+
class ResourceGenerator < RubiGen::Base
|
3
|
+
|
4
|
+
default_options :author => nil
|
5
|
+
|
6
|
+
attr_reader :name, :class_name, :file_name, :provided_args
|
7
|
+
|
8
|
+
def initialize(runtime_args, runtime_options = {})
|
9
|
+
super
|
10
|
+
usage if args.empty?
|
11
|
+
# @name = args.shift
|
12
|
+
@provided_args = runtime_args
|
13
|
+
# @class_name = args.first.camel_case
|
14
|
+
extract_options
|
15
|
+
end
|
16
|
+
|
17
|
+
def manifest
|
18
|
+
record do |m|
|
19
|
+
m.dependency "model", provided_args.dup, options.dup
|
20
|
+
m.dependency "resource_controller", provided_args.dup, options.dup
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def banner
|
26
|
+
<<-EOS
|
27
|
+
Creates a full resource. This includes:
|
28
|
+
|
29
|
+
Model: A model class
|
30
|
+
Migration: if required
|
31
|
+
Model Test or Spec stub
|
32
|
+
Resource Controller and views
|
33
|
+
Controller Test of Spec stubs
|
34
|
+
|
35
|
+
Example
|
36
|
+
|
37
|
+
ruby script/generate resource post title:string content:text created_at:datetime
|
38
|
+
|
39
|
+
USAGE: #{$0} #{spec.name} name"
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_options!(opts)
|
44
|
+
# opts.separator ''
|
45
|
+
# opts.separator 'Options:'
|
46
|
+
# For each option below, place the default
|
47
|
+
# at the top of the file next to "default_options"
|
48
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
49
|
+
# "Some comment about this option",
|
50
|
+
# "Default: none") { |options[:author]| }
|
51
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_options
|
55
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
56
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
57
|
+
# raw instance variable value.
|
58
|
+
# @author = options[:author]
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'merb'
|
2
|
+
class MerbControllerTestGenerator < RubiGen::Base
|
3
|
+
|
4
|
+
default_options :author => nil
|
5
|
+
|
6
|
+
attr_reader :name, :class_name, :file_name, :template_actions
|
7
|
+
|
8
|
+
def initialize(runtime_args, runtime_options = {})
|
9
|
+
super
|
10
|
+
usage if args.empty?
|
11
|
+
@name = args.shift
|
12
|
+
@class_name = @name.camel_case
|
13
|
+
@file_name = @name.snake_case #.pluralize
|
14
|
+
@template_actions = runtime_options[:template_actions] || []
|
15
|
+
@engine = runtime_options[:engine] || "erb" # set by subclasses only
|
16
|
+
extract_options
|
17
|
+
end
|
18
|
+
|
19
|
+
def manifest
|
20
|
+
record do |m|
|
21
|
+
m.directory 'spec/controllers'
|
22
|
+
m.template "controller_spec.rb", "spec/controllers/#{file_name}_spec.rb"
|
23
|
+
|
24
|
+
m.directory "spec/views/#{file_name}"
|
25
|
+
|
26
|
+
|
27
|
+
# Setup the view stubs for each view
|
28
|
+
@template_actions.each do |the_action|
|
29
|
+
template_name = "#{the_action}.html.#{@engine}"
|
30
|
+
if File.exists?(File.join(MERB_ROOT, "app", "views", file_name, template_name))
|
31
|
+
m.template "#{the_action}_spec.rb", "spec/views/#{file_name}/#{the_action}_html_spec.rb"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
m.directory 'spec/helpers'
|
37
|
+
m.template "helper_spec.rb", "spec/helpers/#{file_name}_helper_spec.rb"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
def banner
|
43
|
+
<<-EOS
|
44
|
+
Creates a ...
|
45
|
+
|
46
|
+
USAGE: #{$0} #{spec.name} name"
|
47
|
+
EOS
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_options!(opts)
|
51
|
+
# opts.separator ''
|
52
|
+
# opts.separator 'Options:'
|
53
|
+
# For each option below, place the default
|
54
|
+
# at the top of the file next to "default_options"
|
55
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
56
|
+
# "Some comment about this option",
|
57
|
+
# "Default: none") { |options[:author]| }
|
58
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_options
|
62
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
63
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
64
|
+
# raw instance variable value.
|
65
|
+
# @author = options[:author]
|
66
|
+
end
|
67
|
+
end
|