merb 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +21 -14
- data/Rakefile +157 -108
- data/SVN_REVISION +1 -0
- data/app_generators/merb/templates/Rakefile +20 -4
- data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +1 -1
- data/app_generators/merb/templates/config/boot.rb +1 -1
- data/app_generators/merb/templates/config/dependencies.rb +3 -3
- data/app_generators/merb/templates/config/merb.yml +5 -0
- data/app_generators/merb/templates/config/merb_init.rb +3 -3
- data/app_generators/merb/templates/script/destroy +3 -0
- data/app_generators/merb/templates/script/generate +1 -1
- data/app_generators/merb/templates/spec/spec_helper.rb +2 -2
- data/app_generators/merb/templates/test/test_helper.rb +1 -1
- data/app_generators/merb_plugin/merb_plugin_generator.rb +4 -0
- data/bin/merb +1 -3
- data/lib/merb.rb +144 -76
- data/lib/merb/abstract_controller.rb +6 -5
- data/lib/merb/assets.rb +119 -0
- data/lib/merb/boot_loader.rb +217 -0
- data/lib/merb/caching.rb +1 -1
- data/lib/merb/caching/action_cache.rb +1 -1
- data/lib/merb/caching/fragment_cache.rb +1 -1
- data/lib/merb/caching/store/file_cache.rb +1 -1
- data/lib/merb/config.rb +290 -0
- data/lib/merb/controller.rb +5 -5
- data/lib/merb/core_ext/get_args.rb +1 -0
- data/lib/merb/core_ext/hash.rb +182 -169
- data/lib/merb/core_ext/kernel.rb +57 -26
- data/lib/merb/dispatcher.rb +6 -6
- data/lib/merb/drb_server.rb +1 -1
- data/lib/merb/generators/merb_generator_helpers.rb +7 -6
- data/lib/merb/logger.rb +1 -1
- data/lib/merb/mail_controller.rb +3 -4
- data/lib/merb/mailer.rb +2 -2
- data/lib/merb/mixins/basic_authentication.rb +2 -2
- data/lib/merb/mixins/controller.rb +1 -1
- data/lib/merb/mixins/general_controller.rb +13 -20
- data/lib/merb/mixins/inline_partial.rb +32 -0
- data/lib/merb/mixins/render.rb +3 -3
- data/lib/merb/mixins/responder.rb +1 -1
- data/lib/merb/mixins/view_context.rb +159 -33
- data/lib/merb/mongrel_handler.rb +9 -9
- data/lib/merb/plugins.rb +1 -1
- data/lib/merb/request.rb +25 -1
- data/lib/merb/router.rb +264 -226
- data/lib/merb/server.rb +66 -560
- data/lib/merb/session/cookie_store.rb +14 -13
- data/lib/merb/session/mem_cache_session.rb +20 -10
- data/lib/merb/session/memory_session.rb +21 -11
- data/lib/merb/template.rb +2 -2
- data/lib/merb/template/erubis.rb +3 -33
- data/lib/merb/template/haml.rb +8 -3
- data/lib/merb/test/fake_request.rb +8 -3
- data/lib/merb/test/helper.rb +66 -22
- data/lib/merb/test/rspec.rb +9 -155
- data/lib/merb/test/rspec_matchers/controller_matchers.rb +117 -0
- data/lib/merb/test/rspec_matchers/markup_matchers.rb +98 -0
- data/lib/merb/upload_handler.rb +2 -1
- data/lib/merb/version.rb +38 -3
- data/lib/merb/view_context.rb +1 -2
- data/lib/tasks/merb.rake +11 -11
- data/merb_generators/part_controller/USAGE +5 -0
- data/merb_generators/part_controller/part_controller_generator.rb +27 -0
- data/merb_generators/part_controller/templates/controller.rb +8 -0
- data/merb_generators/part_controller/templates/helper.rb +5 -0
- data/merb_generators/part_controller/templates/index.html.erb +3 -0
- data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +1 -1
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/fixtures/controllers/dispatch_spec_controllers.rb +9 -1
- data/spec/fixtures/controllers/render_spec_controllers.rb +5 -5
- data/spec/fixtures/models/router_spec_models.rb +10 -0
- data/spec/merb/abstract_controller_spec.rb +2 -2
- data/spec/merb/assets_spec.rb +207 -0
- data/spec/merb/caching_spec.rb +2 -2
- data/spec/merb/controller_spec.rb +7 -2
- data/spec/merb/cookie_store_spec.rb +1 -1
- data/spec/merb/core_ext/class_spec.rb +97 -0
- data/spec/merb/core_ext/enumerable_spec.rb +27 -0
- data/spec/merb/core_ext/hash_spec.rb +251 -0
- data/spec/merb/core_ext/inflector_spec.rb +34 -0
- data/spec/merb/core_ext/kernel_spec.rb +25 -0
- data/spec/merb/core_ext/numeric_spec.rb +26 -0
- data/spec/merb/core_ext/object_spec.rb +47 -0
- data/spec/merb/core_ext/string_spec.rb +22 -0
- data/spec/merb/core_ext/symbol_spec.rb +7 -0
- data/spec/merb/dependency_spec.rb +22 -0
- data/spec/merb/dispatch_spec.rb +23 -12
- data/spec/merb/fake_request_spec.rb +8 -0
- data/spec/merb/generator_spec.rb +140 -21
- data/spec/merb/handler_spec.rb +5 -5
- data/spec/merb/mail_controller_spec.rb +3 -3
- data/spec/merb/render_spec.rb +1 -1
- data/spec/merb/responder_spec.rb +3 -3
- data/spec/merb/router_spec.rb +260 -191
- data/spec/merb/server_spec.rb +5 -5
- data/spec/merb/upload_handler_spec.rb +7 -0
- data/spec/merb/version_spec.rb +33 -0
- data/spec/merb/view_context_spec.rb +217 -59
- data/spec/spec_generator_helper.rb +15 -0
- data/spec/spec_helper.rb +5 -3
- data/spec/spec_helpers/url_shared_behaviour.rb +5 -7
- metadata +32 -7
- data/lib/merb/caching/store/memcache.rb +0 -20
- data/lib/merb/mixins/form_control.rb +0 -332
- data/lib/patch +0 -69
- data/spec/merb/core_ext_spec.rb +0 -464
- data/spec/merb/form_control_mixin_spec.rb +0 -431
data/lib/merb/core_ext/kernel.rb
CHANGED
@@ -1,4 +1,41 @@
|
|
1
1
|
module Kernel
|
2
|
+
# Loads the given string as a gem.
|
3
|
+
# An optional second parameter of a version string can be specified and is passed to rubygems.
|
4
|
+
# If rubygems cannot find the gem it requires the string as a library.
|
5
|
+
|
6
|
+
# Note that this new version tries to load the file via ROOT/gems first before moving off to
|
7
|
+
# the system gems (so if you have a lower version of a gem in ROOT/gems, it'll still get loaded)
|
8
|
+
|
9
|
+
def dependency(name, *ver)
|
10
|
+
begin
|
11
|
+
# If it's not in ROOT/gems, skip to the next attempt
|
12
|
+
raise LoadError unless File.directory?(Merb.root / "gems")
|
13
|
+
|
14
|
+
# cache the gem path
|
15
|
+
begin
|
16
|
+
# Clear out the paths and reset them to Merb
|
17
|
+
Gem.use_paths(Merb.root / "gems", [Merb.root / "gems"])
|
18
|
+
|
19
|
+
# Try activating the gem (Failure will raise a LoadError)
|
20
|
+
Gem.activate(name, true, *ver)
|
21
|
+
Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")
|
22
|
+
ensure
|
23
|
+
# Either way, set the gem path back to normal
|
24
|
+
Gem.clear_paths
|
25
|
+
end
|
26
|
+
|
27
|
+
# If we couldn't load the gem or there was no ROOT/gems, try again, now with the full gem path
|
28
|
+
rescue LoadError
|
29
|
+
begin
|
30
|
+
# Try activating again
|
31
|
+
Gem.activate(name, true, *ver)
|
32
|
+
Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")
|
33
|
+
rescue LoadError
|
34
|
+
# Failed requiring as a gem, let's try loading with a normal require.
|
35
|
+
require name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
2
39
|
|
3
40
|
# Loads both gem and library dependencies that are passed in as arguments.
|
4
41
|
# Each argument can be:
|
@@ -15,23 +52,7 @@ module Kernel
|
|
15
52
|
end
|
16
53
|
end
|
17
54
|
end
|
18
|
-
|
19
|
-
# Loads the given string as a gem.
|
20
|
-
# An optional second parameter of a version string can be specified and is passed to rubygems.
|
21
|
-
# If rubygems cannot find the gem it requires the string as a library.
|
22
|
-
|
23
|
-
def dependency(name, *ver)
|
24
|
-
begin
|
25
|
-
Gem.activate(name, true, *ver)
|
26
|
-
message = "#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ..."
|
27
|
-
puts(message)
|
28
|
-
MERB_LOGGER.info(message)
|
29
|
-
rescue LoadError
|
30
|
-
# Failed requiring as a gem, let's try loading with a normal require.
|
31
|
-
requires(name)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
55
|
+
|
35
56
|
# Requires the library string passed in.
|
36
57
|
# If the library fails to load then it will display a helpful message.
|
37
58
|
|
@@ -41,19 +62,19 @@ module Kernel
|
|
41
62
|
require(library)
|
42
63
|
message = "#{Time.now.httpdate}: loading library '#{library}' from #{__app_file_trace__.first} ..."
|
43
64
|
puts(message)
|
44
|
-
|
65
|
+
Merb.logger.info(message)
|
45
66
|
rescue LoadError
|
46
67
|
# TODO: adjust the two messages below to use merb's logger.error/info once logging refactor is complete.
|
47
68
|
message = "#{Time.now.httpdate}: <e> Could not find '#{library}' as either a library or gem, loaded from #{__app_file_trace__.first}.\n"
|
48
69
|
puts(message)
|
49
|
-
|
70
|
+
Merb.logger.error(message)
|
50
71
|
|
51
72
|
# Print a helpful message
|
52
73
|
message = "#{Time.now.httpdate}: <i> Please be sure that if '#{library}': \n"
|
53
74
|
message << "#{Time.now.httpdate}: <i> * is a normal ruby library (file), be sure that the path of the library it is present in the $LOAD_PATH via $LOAD_PATH.unshift(\"/path/to/#{library}\") \n"
|
54
75
|
message << "#{Time.now.httpdate}: <i> * is included within a gem, be sure that you are specifying the gem as a dependency \n"
|
55
76
|
puts(message)
|
56
|
-
|
77
|
+
Merb.logger.error(message)
|
57
78
|
exit() # Missing library/gem must be addressed.
|
58
79
|
end
|
59
80
|
|
@@ -66,7 +87,7 @@ module Kernel
|
|
66
87
|
puts message if message
|
67
88
|
end
|
68
89
|
|
69
|
-
# Used in
|
90
|
+
# Used in Merb.root/dependencies.yml
|
70
91
|
# Tells merb which ORM (Object Relational Mapper) you wish to use.
|
71
92
|
# Currently merb has plugins to support ActiveRecord, DataMapper, and Sequel.
|
72
93
|
#
|
@@ -85,7 +106,7 @@ module Kernel
|
|
85
106
|
Kernel.dependency(orm_plugin)
|
86
107
|
end
|
87
108
|
|
88
|
-
# Used in
|
109
|
+
# Used in Merb.root/dependencies.yml
|
89
110
|
# Tells merb which testing framework to use.
|
90
111
|
# Currently merb supports rspec and test_unit for testing
|
91
112
|
#
|
@@ -107,9 +128,9 @@ module Kernel
|
|
107
128
|
|
108
129
|
def __app_file_trace__
|
109
130
|
caller.select do |call|
|
110
|
-
call.include?(
|
131
|
+
call.include?(Merb.root) && !call.include?(Merb.root + "/framework")
|
111
132
|
end.map do |call|
|
112
|
-
file, line = call.scan(Regexp.new("#{
|
133
|
+
file, line = call.scan(Regexp.new("#{Merb.root}/(.*):(.*)")).first
|
113
134
|
"#{file}:#{line}"
|
114
135
|
end
|
115
136
|
end
|
@@ -171,7 +192,7 @@ module Kernel
|
|
171
192
|
|
172
193
|
# Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>)
|
173
194
|
# Takes a block and profiles the results of running the block 100 times.
|
174
|
-
# The resulting profile is written out to
|
195
|
+
# The resulting profile is written out to Merb.root/log/#{name}.html.
|
175
196
|
# <tt>min</tt> specifies the minimum percentage of the total time a method must take for it to be included in the result.
|
176
197
|
#
|
177
198
|
# Example
|
@@ -189,7 +210,7 @@ module Kernel
|
|
189
210
|
100.times{return_result = yield}
|
190
211
|
end
|
191
212
|
printer = RubyProf::GraphHtmlPrinter.new(result)
|
192
|
-
path = File.join(
|
213
|
+
path = File.join(Merb.root, 'log', "#{name}.html")
|
193
214
|
File.open(path, 'w') do |file|
|
194
215
|
printer.print(file, {:min_percent => min,
|
195
216
|
:print_file => true})
|
@@ -208,4 +229,14 @@ module Kernel
|
|
208
229
|
args.pop if Hash === args.last
|
209
230
|
end
|
210
231
|
|
232
|
+
unless Kernel.respond_to?(:debugger)
|
233
|
+
# define debugger method so that code even works if debugger was not
|
234
|
+
# requested
|
235
|
+
# Drops a not to the logs that Debugger was not available
|
236
|
+
def debugger
|
237
|
+
Merb.logger.info "\n***** Debugger requested, but was not " +
|
238
|
+
"available: Start server with --debugger " +
|
239
|
+
"to enable *****\n"
|
240
|
+
end
|
241
|
+
end
|
211
242
|
end
|
data/lib/merb/dispatcher.rb
CHANGED
@@ -2,7 +2,7 @@ module Merb
|
|
2
2
|
class Dispatcher
|
3
3
|
|
4
4
|
DEFAULT_ERROR_TEMPLATE = Erubis::MEruby.new((File.read(
|
5
|
-
File.join(
|
5
|
+
File.join(Merb.root, 'app/views/exceptions/internal_server_error.html.erb')) rescue "Internal Server Error!"))
|
6
6
|
|
7
7
|
class << self
|
8
8
|
|
@@ -11,7 +11,7 @@ module Merb
|
|
11
11
|
end
|
12
12
|
|
13
13
|
@@mutex = Mutex.new
|
14
|
-
@@use_mutex = ::Merb::
|
14
|
+
@@use_mutex = ::Merb::Config[:use_mutex]
|
15
15
|
# This is where we grab the incoming request REQUEST_URI and use that in
|
16
16
|
# the merb RouteMatcher to determine which controller and method to run.
|
17
17
|
# Returns a 2 element tuple of: [controller, action]
|
@@ -21,20 +21,20 @@ module Merb
|
|
21
21
|
def handle(http_request, response)
|
22
22
|
start = Time.now
|
23
23
|
request = Merb::Request.new(http_request)
|
24
|
-
|
25
|
-
|
24
|
+
Merb.logger.info("Params: #{request.params.inspect}")
|
25
|
+
Merb.logger.info("Cookies: #{request.cookies.inspect}")
|
26
26
|
# user friendly error messages
|
27
27
|
if request.route_params.empty?
|
28
28
|
raise ControllerExceptions::BadRequest, "No routes match the request"
|
29
29
|
elsif request.controller_name.nil?
|
30
30
|
raise ControllerExceptions::BadRequest, "Route matched, but route did not specify a controller"
|
31
31
|
end
|
32
|
-
|
32
|
+
Merb.logger.debug("Routed to: #{request.route_params.inspect}")
|
33
33
|
# set controller class and the action to call
|
34
34
|
klass = request.controller_class
|
35
35
|
dispatch_action(klass, request.action, request, response)
|
36
36
|
rescue => exception
|
37
|
-
|
37
|
+
Merb.logger.error(Merb.exception(exception))
|
38
38
|
exception = controller_exception(exception)
|
39
39
|
dispatch_exception(request, response, exception)
|
40
40
|
end
|
data/lib/merb/drb_server.rb
CHANGED
@@ -255,6 +255,7 @@ EOS
|
|
255
255
|
@engine = runtime_options[:engine] || "erb" # set by subclasses only
|
256
256
|
@template_actions = runtime_options[:actions] || %w[index] # Used by subclasses only
|
257
257
|
@test_generator = runtime_options[:test_stub_generator] || "merb_controller_test"
|
258
|
+
@base_dest_folder = runtime_options[:base_dest_folder] || "app"
|
258
259
|
extract_options
|
259
260
|
end
|
260
261
|
|
@@ -264,10 +265,10 @@ EOS
|
|
264
265
|
# ensure there are no other definitions of this model already defined.
|
265
266
|
m.class_collisions(@class_name)
|
266
267
|
|
267
|
-
m.directory "
|
268
|
-
m.template "controller.rb", "
|
268
|
+
m.directory "#{@base_dest_folder}/controllers"
|
269
|
+
m.template "controller.rb", "#{@base_dest_folder}/controllers/#{file_name}.rb", :assigns => {:actions => @template_actions}
|
269
270
|
|
270
|
-
m.directory "
|
271
|
+
m.directory "#{@base_dest_folder}/views/#{file_name}"
|
271
272
|
|
272
273
|
# Include templates if they exist
|
273
274
|
@template_actions.each do |the_action|
|
@@ -275,12 +276,12 @@ EOS
|
|
275
276
|
template_path = "/" + source_path(spec.name).split("/")[0..-2].join("/")
|
276
277
|
|
277
278
|
if File.exists?(File.join(template_path,template_name))
|
278
|
-
m.template template_name, "
|
279
|
+
m.template template_name, "#{@base_dest_folder}/views/#{file_name}/#{template_name}"
|
279
280
|
end
|
280
281
|
end
|
281
282
|
|
282
|
-
m.directory "
|
283
|
-
m.template "helper.rb", "
|
283
|
+
m.directory "#{@base_dest_folder}/helpers/"
|
284
|
+
m.template "helper.rb", "#{@base_dest_folder}/helpers/#{file_name}_helper.rb"
|
284
285
|
m.dependency @test_generator, [name], :destination => destination_root, :template_actions => @template_actions
|
285
286
|
end
|
286
287
|
end
|
data/lib/merb/logger.rb
CHANGED
@@ -28,7 +28,7 @@ module Merb
|
|
28
28
|
@log.sync = true
|
29
29
|
@log.write("# Logfile created on %s\n" % [Time.now.to_s])
|
30
30
|
end
|
31
|
-
if !
|
31
|
+
if !Merb.environment.match(/development|test/) &&
|
32
32
|
!RUBY_PLATFORM.match(/java|mswin/) &&
|
33
33
|
!(@log == STDOUT) &&
|
34
34
|
@log.respond_to?(:write_nonblock)
|
data/lib/merb/mail_controller.rb
CHANGED
@@ -183,7 +183,7 @@ module Merb
|
|
183
183
|
rescue => e
|
184
184
|
# An error should be logged if no template is found instead of an error raised
|
185
185
|
if @_missing_templates
|
186
|
-
|
186
|
+
Merb.logger.error(e)
|
187
187
|
else
|
188
188
|
@_missing_templates = true
|
189
189
|
end
|
@@ -237,9 +237,9 @@ module Merb
|
|
237
237
|
body = dispatch method
|
238
238
|
if !@mail.html.blank? || !@mail.text.blank?
|
239
239
|
@mailer.deliver!
|
240
|
-
|
240
|
+
Merb.logger.info "#{method} sent to #{@mail.to} about #{@mail.subject}"
|
241
241
|
else
|
242
|
-
|
242
|
+
Merb.logger.info "#{method} was not sent because nothing was rendered for it"
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
@@ -258,7 +258,6 @@ module Merb
|
|
258
258
|
# This method is here to overwrite the one in the general_controller mixin
|
259
259
|
# The method ensures that when a url is generated with a hash, it contains a controller
|
260
260
|
def get_controller_for_url_generation(opts)
|
261
|
-
puts @base_controller.params[:controller] if @base_controller
|
262
261
|
controller = opts[:controller] || ( @base_controller.params[:controller] if @base_controller)
|
263
262
|
raise "No Controller Specified for url()" unless controller
|
264
263
|
controller
|
data/lib/merb/mailer.rb
CHANGED
@@ -3,7 +3,7 @@ begin
|
|
3
3
|
require 'net/smtp'
|
4
4
|
rescue LoadError
|
5
5
|
puts "You need to install the mailfactory gem to use Merb::Mailer"
|
6
|
-
|
6
|
+
Merb.logger.warn "You need to install the mailfactory gem to use Merb::Mailer"
|
7
7
|
end
|
8
8
|
|
9
9
|
class MailFactory
|
@@ -25,7 +25,7 @@ module Merb
|
|
25
25
|
#
|
26
26
|
# or
|
27
27
|
#
|
28
|
-
# Merb::Mailer.config = {:sendmail_path => '/somewhere/odd'
|
28
|
+
# Merb::Mailer.config = {:sendmail_path => '/somewhere/odd'}
|
29
29
|
# Merb::Mailer.delivery_method = :sendmail
|
30
30
|
#
|
31
31
|
# You could send mail manually like this (but it's better to use
|
@@ -13,7 +13,7 @@ module Merb
|
|
13
13
|
|
14
14
|
def authenticated?
|
15
15
|
username, password = *credentials
|
16
|
-
username == Merb::
|
16
|
+
username == Merb::Config[:basic_auth][:username] and password == Merb::Config[:basic_auth][:password]
|
17
17
|
end
|
18
18
|
|
19
19
|
def basic_authentication
|
@@ -26,7 +26,7 @@ module Merb
|
|
26
26
|
set_status(401)
|
27
27
|
headers['Content-type'] = 'text/plain'
|
28
28
|
headers['Status'] = 'Unauthorized'
|
29
|
-
headers['WWW-Authenticate'] = "Basic realm=\"#{Merb::
|
29
|
+
headers['WWW-Authenticate'] = "Basic realm=\"#{Merb::Config[:basic_auth][:domain]}\""
|
30
30
|
return 'Unauthorized'
|
31
31
|
end
|
32
32
|
|
@@ -66,7 +66,7 @@ module Merb
|
|
66
66
|
# fully-qualified URL.
|
67
67
|
#
|
68
68
|
def redirect(url)
|
69
|
-
|
69
|
+
Merb.logger.info("Redirecting to: #{url}")
|
70
70
|
set_status(302)
|
71
71
|
headers['Location'] = url
|
72
72
|
"<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
|
@@ -52,11 +52,11 @@ module Merb
|
|
52
52
|
# url(:edit_blogpost, @post) # => /blogposts/1/edit
|
53
53
|
# url(:custom_new_blogpost, :action => 'alternate') # => /blogposts/new/alternate
|
54
54
|
#
|
55
|
-
# url(:comments, :
|
56
|
-
# url(:new_comment, :
|
55
|
+
# url(:comments, :blogpost_id => @post) # => /blogposts/1/comments
|
56
|
+
# url(:new_comment, :blogpost_id => @post) # => /blogposts/1/comments/new
|
57
57
|
# url(:comment, @comment) # => /blogposts/1/comments/1
|
58
58
|
# url(:edit_comment, @comment) # => /blogposts/1/comments/1/edit
|
59
|
-
# url(:custom_new_comment, :
|
59
|
+
# url(:custom_new_comment, :blogpost_id => @post)
|
60
60
|
#
|
61
61
|
# url(:page => 2) # => /posts/show/1?page=2
|
62
62
|
# url(:new_post, :page => 3) # => /posts/new?page=3
|
@@ -86,7 +86,7 @@ module Merb
|
|
86
86
|
else
|
87
87
|
raise "URL not generated: #{route_name.inspect}, #{new_params.inspect}"
|
88
88
|
end
|
89
|
-
url = Merb::
|
89
|
+
url = Merb::Config[:path_prefix] + url if Merb::Config[:path_prefix]
|
90
90
|
url
|
91
91
|
end
|
92
92
|
|
@@ -97,10 +97,12 @@ module Merb
|
|
97
97
|
end
|
98
98
|
route = symbol.is_a?(Symbol) ? Merb::Router.named_routes[symbol] : symbol
|
99
99
|
unless route
|
100
|
-
raise
|
100
|
+
raise "URL could not be constructed. Route symbol not found: #{symbol.inspect}"
|
101
101
|
end
|
102
|
+
|
102
103
|
path = route.generate(new_params, params)
|
103
104
|
keys = route.symbol_segments
|
105
|
+
|
104
106
|
if new_params.is_a? Hash
|
105
107
|
if ext = format_extension(new_params)
|
106
108
|
new_params.delete(:format)
|
@@ -190,7 +192,7 @@ module Merb
|
|
190
192
|
# # => /products/3
|
191
193
|
#
|
192
194
|
def format_extension(new_params={})
|
193
|
-
use_format = Merb::
|
195
|
+
use_format = Merb::Config[:use_format_in_urls]
|
194
196
|
if use_format.nil?
|
195
197
|
prms = params.merge(new_params)
|
196
198
|
use_format = prms[:format] != 'html' && prms[:format]
|
@@ -223,18 +225,10 @@ module Merb
|
|
223
225
|
alias h escape_xml
|
224
226
|
alias html_escape escape_xml
|
225
227
|
|
226
|
-
# Escapes +s+ for use in a URL.
|
227
|
-
#
|
228
|
-
# ==== Parameter
|
229
|
-
#
|
230
|
-
# +s+ - String to URL escape.
|
231
|
-
#
|
232
228
|
def escape(s)
|
233
|
-
|
234
|
-
'%'+$1.unpack('H2'*$1.size).join('%').upcase
|
235
|
-
}.tr(' ', '+')
|
229
|
+
::Merb::Request.escape(s)
|
236
230
|
end
|
237
|
-
|
231
|
+
|
238
232
|
# Unescapes a string (i.e., reverse URL escaping).
|
239
233
|
#
|
240
234
|
# ==== Parameter
|
@@ -242,11 +236,10 @@ module Merb
|
|
242
236
|
# +s+ - String to unescape.
|
243
237
|
#
|
244
238
|
def unescape(s)
|
245
|
-
|
246
|
-
[$1.delete('%')].pack('H*')
|
247
|
-
}
|
239
|
+
::Merb::Request.unescape(s)
|
248
240
|
end
|
249
241
|
|
242
|
+
|
250
243
|
private
|
251
244
|
# Used for sepccing
|
252
245
|
def get_controller_for_url_generation(options)
|
@@ -255,4 +248,4 @@ module Merb
|
|
255
248
|
end
|
256
249
|
|
257
250
|
end
|
258
|
-
end
|
251
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Merb::InlinePartialMixin
|
2
|
+
def partial(template, opts={})
|
3
|
+
|
4
|
+
unless @_template_format
|
5
|
+
@web_controller.choose_template_format(Merb.available_mime_types, {})
|
6
|
+
end
|
7
|
+
|
8
|
+
found_template = @web_controller._cached_partials["#{template}.#{@_template_format}"] ||=
|
9
|
+
@web_controller.send(:find_partial, template, opts)
|
10
|
+
|
11
|
+
template_method = found_template.gsub(/[^\.a-zA-Z0-9]/, "__").gsub(/\./, "_")
|
12
|
+
|
13
|
+
unless self.respond_to?(template_method)
|
14
|
+
return super
|
15
|
+
end
|
16
|
+
|
17
|
+
if with = opts.delete(:with)
|
18
|
+
as = opts.delete(:as) || found_template.match(/(.*\/_)([^\.]*)/)[2]
|
19
|
+
@_merb_partial_locals = opts
|
20
|
+
sent_template = [with].flatten.map do |temp|
|
21
|
+
@_merb_partial_locals[as.to_sym] = temp
|
22
|
+
send(template_method)
|
23
|
+
end.join
|
24
|
+
else
|
25
|
+
@_merb_partial_locals = opts
|
26
|
+
sent_template = send(template_method)
|
27
|
+
end
|
28
|
+
|
29
|
+
return sent_template if sent_template
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/merb/mixins/render.rb
CHANGED
@@ -12,7 +12,7 @@ module Merb
|
|
12
12
|
:_cached_partials
|
13
13
|
|
14
14
|
self._layout = :application
|
15
|
-
self._template_root = File.expand_path(
|
15
|
+
self._template_root = File.expand_path(Merb.view_path)
|
16
16
|
self._templates = {}
|
17
17
|
self._cached_partials = {}
|
18
18
|
|
@@ -226,7 +226,7 @@ module Merb
|
|
226
226
|
# set any additinal headers that may be associated with the current mime type
|
227
227
|
Merb.response_headers[tmpl_fmt].each do |key,value|
|
228
228
|
headers[key.to_s] = value
|
229
|
-
end
|
229
|
+
end
|
230
230
|
|
231
231
|
end
|
232
232
|
end
|
@@ -421,7 +421,7 @@ module Merb
|
|
421
421
|
# This method will return a matching template at the specified path, using the
|
422
422
|
# template_name.format.engine convention
|
423
423
|
def glob_template(path, opts = {})
|
424
|
-
the_template = "#{path}.#{@_template_format}"
|
424
|
+
the_template = "#{path}.#{opts[:format] || @_template_format}"
|
425
425
|
Merb::AbstractController._template_path_cache[the_template] || (@_merb_unmatched = (the_template + ".*"); nil)
|
426
426
|
end
|
427
427
|
|