roda 2.29.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +52 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +51 -109
  5. data/Rakefile +7 -14
  6. data/doc/conventions.rdoc +4 -4
  7. data/doc/release_notes/1.2.0.txt +1 -1
  8. data/doc/release_notes/3.0.0.txt +84 -0
  9. data/lib/roda.rb +25 -79
  10. data/lib/roda/plugins/assets.rb +25 -58
  11. data/lib/roda/plugins/assets_preloading.rb +0 -5
  12. data/lib/roda/plugins/backtracking_array.rb +0 -5
  13. data/lib/roda/plugins/branch_locals.rb +3 -3
  14. data/lib/roda/plugins/caching.rb +5 -38
  15. data/lib/roda/plugins/chunked.rb +7 -25
  16. data/lib/roda/plugins/class_level_routing.rb +2 -2
  17. data/lib/roda/plugins/content_for.rb +7 -10
  18. data/lib/roda/plugins/cookies.rb +3 -3
  19. data/lib/roda/plugins/csrf.rb +2 -2
  20. data/lib/roda/plugins/delegate.rb +3 -3
  21. data/lib/roda/plugins/drop_body.rb +0 -7
  22. data/lib/roda/plugins/empty_root.rb +0 -3
  23. data/lib/roda/plugins/error_email.rb +4 -6
  24. data/lib/roda/plugins/error_handler.rb +1 -2
  25. data/lib/roda/plugins/error_mail.rb +3 -6
  26. data/lib/roda/plugins/flash.rb +0 -4
  27. data/lib/roda/plugins/h.rb +5 -0
  28. data/lib/roda/plugins/hash_matcher.rb +4 -2
  29. data/lib/roda/plugins/head.rb +5 -7
  30. data/lib/roda/plugins/header_matchers.rb +12 -33
  31. data/lib/roda/plugins/heartbeat.rb +2 -7
  32. data/lib/roda/plugins/indifferent_params.rb +2 -2
  33. data/lib/roda/plugins/json.rb +6 -14
  34. data/lib/roda/plugins/json_parser.rb +2 -13
  35. data/lib/roda/plugins/mailer.rb +29 -39
  36. data/lib/roda/plugins/match_affix.rb +0 -5
  37. data/lib/roda/plugins/middleware.rb +10 -15
  38. data/lib/roda/plugins/multi_route.rb +8 -5
  39. data/lib/roda/plugins/multi_run.rb +1 -0
  40. data/lib/roda/plugins/named_templates.rb +2 -2
  41. data/lib/roda/plugins/optimized_string_matchers.rb +0 -3
  42. data/lib/roda/plugins/padrino_render.rb +6 -9
  43. data/lib/roda/plugins/param_matchers.rb +6 -6
  44. data/lib/roda/plugins/params_capturing.rb +15 -35
  45. data/lib/roda/plugins/partials.rb +3 -8
  46. data/lib/roda/plugins/path.rb +5 -5
  47. data/lib/roda/plugins/path_matchers.rb +3 -3
  48. data/lib/roda/plugins/path_rewriter.rb +4 -9
  49. data/lib/roda/plugins/placeholder_string_matchers.rb +1 -1
  50. data/lib/roda/plugins/precompile_templates.rb +10 -20
  51. data/lib/roda/plugins/public.rb +6 -9
  52. data/lib/roda/plugins/render.rb +50 -171
  53. data/lib/roda/plugins/render_each.rb +4 -7
  54. data/lib/roda/plugins/render_locals.rb +6 -20
  55. data/lib/roda/plugins/request_headers.rb +2 -4
  56. data/lib/roda/plugins/run_append_slash.rb +1 -4
  57. data/lib/roda/plugins/run_handler.rb +4 -7
  58. data/lib/roda/plugins/shared_vars.rb +3 -6
  59. data/lib/roda/plugins/sinatra_helpers.rb +11 -40
  60. data/lib/roda/plugins/slash_path_empty.rb +0 -3
  61. data/lib/roda/plugins/static.rb +2 -2
  62. data/lib/roda/plugins/static_routing.rb +2 -3
  63. data/lib/roda/plugins/streaming.rb +15 -108
  64. data/lib/roda/plugins/strip_path_prefix.rb +1 -1
  65. data/lib/roda/plugins/symbol_matchers.rb +7 -23
  66. data/lib/roda/plugins/type_routing.rb +4 -9
  67. data/lib/roda/plugins/view_options.rb +10 -66
  68. data/lib/roda/version.rb +2 -2
  69. data/spec/all.rb +0 -2
  70. data/spec/composition_spec.rb +1 -1
  71. data/spec/env_spec.rb +1 -1
  72. data/spec/freeze_spec.rb +1 -1
  73. data/spec/integration_spec.rb +1 -1
  74. data/spec/matchers_spec.rb +26 -70
  75. data/spec/opts_spec.rb +1 -1
  76. data/spec/plugin/all_verbs_spec.rb +1 -1
  77. data/spec/plugin/assets_preloading_spec.rb +1 -1
  78. data/spec/plugin/assets_spec.rb +43 -27
  79. data/spec/plugin/backtracking_array_spec.rb +1 -1
  80. data/spec/plugin/branch_locals_spec.rb +1 -1
  81. data/spec/plugin/caching_spec.rb +1 -1
  82. data/spec/plugin/chunked_spec.rb +1 -1
  83. data/spec/plugin/class_level_routing_spec.rb +1 -1
  84. data/spec/plugin/class_matchers_spec.rb +1 -1
  85. data/spec/plugin/content_for_spec.rb +2 -7
  86. data/spec/plugin/cookies_spec.rb +1 -1
  87. data/spec/plugin/csrf_spec.rb +1 -1
  88. data/spec/plugin/default_headers_spec.rb +1 -1
  89. data/spec/plugin/default_status_spec.rb +1 -1
  90. data/spec/plugin/delay_build_spec.rb +1 -1
  91. data/spec/plugin/delegate_spec.rb +1 -1
  92. data/spec/plugin/delete_empty_headers_spec.rb +1 -1
  93. data/spec/plugin/disallow_file_uploads_spec.rb +2 -2
  94. data/spec/plugin/drop_body_spec.rb +1 -1
  95. data/spec/plugin/empty_root_spec.rb +1 -1
  96. data/spec/plugin/environments_spec.rb +1 -1
  97. data/spec/plugin/error_email_spec.rb +1 -1
  98. data/spec/plugin/error_handler_spec.rb +1 -1
  99. data/spec/plugin/error_mail_spec.rb +2 -2
  100. data/spec/plugin/flash_spec.rb +1 -1
  101. data/spec/plugin/h_spec.rb +1 -1
  102. data/spec/plugin/halt_spec.rb +2 -2
  103. data/spec/plugin/hash_matcher_spec.rb +1 -1
  104. data/spec/plugin/head_spec.rb +1 -1
  105. data/spec/plugin/header_matchers_spec.rb +4 -47
  106. data/spec/plugin/heartbeat_spec.rb +1 -1
  107. data/spec/plugin/hooks_spec.rb +1 -1
  108. data/spec/plugin/indifferent_params_spec.rb +1 -1
  109. data/spec/plugin/json_parser_spec.rb +12 -1
  110. data/spec/plugin/json_spec.rb +8 -1
  111. data/spec/plugin/mailer_spec.rb +1 -1
  112. data/spec/plugin/match_affix_spec.rb +1 -1
  113. data/spec/plugin/middleware_spec.rb +15 -1
  114. data/spec/plugin/module_include_spec.rb +1 -1
  115. data/spec/plugin/multi_route_spec.rb +5 -3
  116. data/spec/plugin/multi_run_spec.rb +1 -1
  117. data/spec/plugin/multi_view_spec.rb +1 -1
  118. data/spec/plugin/named_templates_spec.rb +1 -1
  119. data/spec/plugin/not_allowed_spec.rb +1 -1
  120. data/spec/plugin/not_found_spec.rb +1 -1
  121. data/spec/plugin/optimized_string_matchers_spec.rb +1 -1
  122. data/spec/plugin/padrino_render_spec.rb +1 -1
  123. data/spec/plugin/param_matchers_spec.rb +1 -1
  124. data/spec/plugin/params_capturing_spec.rb +6 -22
  125. data/spec/plugin/partials_spec.rb +1 -1
  126. data/spec/plugin/pass_spec.rb +1 -1
  127. data/spec/plugin/path_matchers_spec.rb +1 -1
  128. data/spec/plugin/path_rewriter_spec.rb +1 -1
  129. data/spec/plugin/path_spec.rb +1 -1
  130. data/spec/plugin/placeholder_string_matchers_spec.rb +3 -36
  131. data/spec/plugin/precompile_templates_spec.rb +1 -17
  132. data/spec/plugin/public_spec.rb +3 -4
  133. data/spec/plugin/render_each_spec.rb +1 -1
  134. data/spec/plugin/render_locals_spec.rb +1 -1
  135. data/spec/plugin/render_spec.rb +28 -114
  136. data/spec/plugin/request_headers_spec.rb +1 -1
  137. data/spec/plugin/response_request_spec.rb +1 -1
  138. data/spec/plugin/run_append_slash_spec.rb +1 -1
  139. data/spec/plugin/run_handler_spec.rb +1 -1
  140. data/spec/plugin/shared_vars_spec.rb +1 -1
  141. data/spec/plugin/sinatra_helpers_spec.rb +1 -1
  142. data/spec/plugin/slash_path_empty_spec.rb +1 -1
  143. data/spec/plugin/static_routing_spec.rb +1 -1
  144. data/spec/plugin/static_spec.rb +1 -1
  145. data/spec/plugin/status_303_spec.rb +1 -1
  146. data/spec/plugin/status_handler_spec.rb +1 -1
  147. data/spec/plugin/streaming_spec.rb +1 -106
  148. data/spec/plugin/strip_path_prefix_spec.rb +1 -1
  149. data/spec/plugin/symbol_matchers_spec.rb +1 -77
  150. data/spec/plugin/symbol_status_spec.rb +1 -1
  151. data/spec/plugin/symbol_views_spec.rb +1 -1
  152. data/spec/plugin/type_routing_spec.rb +1 -1
  153. data/spec/plugin/unescape_path_spec.rb +1 -1
  154. data/spec/plugin/view_options_spec.rb +16 -110
  155. data/spec/plugin_spec.rb +1 -1
  156. data/spec/redirect_spec.rb +1 -1
  157. data/spec/request_spec.rb +1 -1
  158. data/spec/response_spec.rb +1 -1
  159. data/spec/session_spec.rb +1 -1
  160. data/spec/spec_helper.rb +1 -3
  161. data/spec/version_spec.rb +1 -1
  162. metadata +6 -26
  163. data/lib/roda/plugins/_erubis_escaping.rb +0 -59
  164. data/lib/roda/plugins/per_thread_caching.rb +0 -71
  165. data/lib/roda/plugins/static_path_info.rb +0 -12
  166. data/lib/roda/plugins/view_subdirs.rb +0 -7
  167. data/lib/roda/plugins/websockets.rb +0 -107
  168. data/spec/plugin/_erubis_escaping_spec.rb +0 -97
  169. data/spec/plugin/per_thread_caching_spec.rb +0 -28
  170. data/spec/plugin/websockets_spec.rb +0 -84
@@ -17,7 +17,7 @@ class Roda
17
17
  # end
18
18
  #
19
19
  # It is not recommended to use this in new applications, and it is encouraged
20
- # to use separate symbol or string class matchers instead:
20
+ # to use separate string class or symbol matchers instead:
21
21
  #
22
22
  # r.is "foo", String
23
23
  # r.is "foo", :bar
@@ -25,16 +25,10 @@ class Roda
25
25
  # If the templates use local variables, you need to specify which local
26
26
  # variables to precompile, which should be an array of symbols:
27
27
  #
28
- # precompile_templates 'views/users/_*.erb', :locals=>[:user]
28
+ # precompile_templates 'views/users/_*.erb', locals: [:user]
29
29
  #
30
- # Note that if you have multiple local variables and are not using a Tilt
31
- # version greater than 2.0.1, you should specify the :locals option in the
32
- # same order as the keys in the :locals hash you pass to render/view. Since
33
- # hashes are not ordered in ruby 1.8, you should not attempt to precompile
34
- # templates that use :locals on ruby 1.8 unless you are using a Tilt version
35
- # greater than 2.0.1. If you are running the Tilt master branch, you can
36
- # force sorting of locals using the +:sort_locals+ option when loading the
37
- # plugin.
30
+ # Note that you should use Tilt 2.0.1+ if you are using this plugin, so
31
+ # that locals are handled in the same order.
38
32
  #
39
33
  # You can specify other render options when calling +precompile_templates+,
40
34
  # including +:cache_key+, +:template_class+, and +:template_opts+. If you
@@ -44,29 +38,25 @@ class Roda
44
38
  # To compile inline templates, just pass a single hash containing an :inline
45
39
  # to +precompile_templates+:
46
40
  #
47
- # precompile_templates :inline=>some_template_string
41
+ # precompile_templates inline: some_template_string
48
42
  module PrecompileTemplates
49
- OPTS = {}.freeze
50
- RodaPlugins.deprecate_constant(self, :OPTS)
51
-
52
43
  # Load the render plugin as precompile_templates depends on it.
53
- # Default to sorting the locals if the Tilt version is greater than 2.0.1.
54
- def self.load_dependencies(app, opts=RodaPlugins::OPTS)
44
+ def self.load_dependencies(app, opts=OPTS)
55
45
  app.plugin :render
56
- app.opts[:precompile_templates_sort] = opts.fetch(:sort_locals, Tilt::VERSION > '2.0.1')
57
46
  end
58
47
 
59
48
  module ClassMethods
60
49
  # Precompile the templates using the given options. See PrecompileTemplates
61
50
  # for details.
62
- def precompile_templates(pattern, opts=RodaPlugins::OPTS)
51
+ def precompile_templates(pattern, opts=OPTS)
63
52
  if pattern.is_a?(Hash)
64
53
  opts = pattern.merge(opts)
65
54
  end
66
55
 
67
- locals = opts[:locals] || []
68
- if locals && self.opts[:precompile_templates_sort]
69
- locals = locals.sort{|x,y| x.to_s <=> y.to_s}
56
+ if locals = opts[:locals]
57
+ locals.sort!
58
+ else
59
+ locals = EMPTY_ARRAY
70
60
  end
71
61
 
72
62
  compile_opts = if pattern.is_a?(Hash)
@@ -10,7 +10,7 @@ class Roda
10
10
  #
11
11
  # The public plugin recognizes the application's :root option, and defaults to
12
12
  # using the +public+ subfolder of the application's +:root+ option. If the application's
13
- # :root option is not set, it defaults to the the +public+ folder in the working
13
+ # :root option is not set, it defaults to the +public+ folder in the working
14
14
  # directory. Additionally, if a relative path is provided as the :root
15
15
  # option to the plugin, it will be considered relative to the application's
16
16
  # +:root+ option.
@@ -19,13 +19,10 @@ class Roda
19
19
  #
20
20
  # opts[:root] = '/path/to/app'
21
21
  # plugin :public
22
- # plugin :public, :root=>'static'
22
+ # plugin :public, root: 'static'
23
23
  module Public
24
24
  SPLIT = Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact)
25
- PARSER = RUBY_VERSION >= '1.9' ? URI::DEFAULT_PARSER : URI
26
-
27
- NULL_BYTE = "\0".freeze
28
- RodaPlugins.deprecate_constant(self, :NULL_BYTE)
25
+ PARSER = URI::DEFAULT_PARSER
29
26
 
30
27
  # Use options given to setup a Rack::File instance for serving files. Options:
31
28
  # :default_mime :: The default mime type to use if the mime type is not recognized.
@@ -97,18 +94,18 @@ class Roda
97
94
  end
98
95
 
99
96
  if ::Rack.release > '2'
100
- # :nocov:
97
+ # Serve the given path using the given Rack::File server.
101
98
  def public_serve(server, path)
102
99
  server.serving(self, path)
103
100
  end
104
- # :nocov:
105
101
  else
106
- # Serve the given path using the given Rack::File server.
102
+ # :nocov:
107
103
  def public_serve(server, path)
108
104
  server = server.dup
109
105
  server.path = path
110
106
  server.serving(env)
111
107
  end
108
+ # :nocov:
112
109
  end
113
110
  end
114
111
  end
@@ -24,7 +24,7 @@ class Roda
24
24
  # side effects (unless the templates themselves have side effects).
25
25
  # As Roda uses the routing block return value as the body of the response,
26
26
  # in most cases you will call these methods as the last expression in a
27
- # routing block # to have the response body be the result of the template
27
+ # routing block to have the response body be the result of the template
28
28
  # rendering.
29
29
  #
30
30
  # Because +render+ and +view+ just return strings, you can call them inside
@@ -33,40 +33,34 @@ class Roda
33
33
  #
34
34
  # route do |r|
35
35
  # r.is 'foo-bars' do
36
- # @bars = Bar.where(:foo).map{|b| render(:bar, :locals=>{:bar=>b})}.join
36
+ # @bars = Bar.where(:foo).map{|b| render(:bar, locals: {bar: b})}.join
37
37
  # view('foo')
38
38
  # end
39
39
  # end
40
40
  #
41
41
  # You can provide options to the plugin method:
42
42
  #
43
- # plugin :render, :engine=>'haml', :views=>'admin_views'
43
+ # plugin :render, engine: 'haml', views: 'admin_views'
44
44
  #
45
45
  # = Plugin Options
46
46
  #
47
47
  # The following plugin options are supported:
48
48
  #
49
- # :allowed_paths :: Set the template paths to allow if +:check_paths+ is true.
50
- # Defaults to the +:views+ directory.
51
- # :cache :: nil/false to disallow template caching completely.
49
+ # :allowed_paths :: Set the template paths to allow. Attempts to render paths outside
50
+ # of this directory will raise an error. Defaults to the +:views+ directory.
51
+ # :cache :: nil/false to disable template caching by default. By default, caching
52
+ # is disabled by default if RACK_ENV is development.
52
53
  # :cache_class :: A class to use as the template cache instead of the default.
53
- # :check_paths :: Check template paths start with one of the entries in +:allowed_paths+,
54
- # and raise a RodaError if the path doesn't.
54
+ # :check_paths :: Can be set to false to turn off template path checking.
55
55
  # :engine :: The tilt engine to use for rendering, also the default file extension for
56
56
  # templates, defaults to 'erb'.
57
- # :escape :: Use Roda's Erubis escaping support, which makes <tt><%= %></tt> escape output,
58
- # <tt><%== %></tt> not escape output, and handles postfix conditions inside
59
- # <tt><%= %></tt> tags. Can have a value of :erubi to use Erubi escaping support.
60
- # :explicit_cache :: Only use the template cache if the :cache option is provided when rendering
61
- # (useful for development). Defaults to true if RACK_ENV is development, allowing explicit
62
- # caching of specific templates, but not caching by default.
63
- # :inherit_cache :: Whether to create a dup of the cache in subclasses. The default is false, which
64
- # starts subclasses with an empty cache.
57
+ # :escape :: Use Erubi as the ERB template engine, and enable escaping by default,
58
+ # which makes <tt><%= %></tt> escape output and <tt><%== %></tt> not escape output.
65
59
  # :layout :: The base name of the layout file, defaults to 'layout'. This can be provided as a hash
66
60
  # with the :template or :inline options.
67
61
  # :layout_opts :: The options to use when rendering the layout, if different from the default options.
68
62
  # :template_opts :: The tilt options used when rendering all templates. defaults to:
69
- # <tt>{:outvar=>'@_out_buf', :default_encoding=>Encoding.default_external}</tt>.
63
+ # <tt>{outvar: '@_out_buf', default_encoding: Encoding.default_external}</tt>.
70
64
  # :engine_opts :: The tilt options to use per template engine. Keys are
71
65
  # engine strings, values are hashes of template options.
72
66
  # :views :: The directory holding the view files, defaults to the 'views' subdirectory of the
@@ -77,8 +71,8 @@ class Roda
77
71
  # Most of these options can be overridden at runtime by passing options
78
72
  # to the +view+ or +render+ methods:
79
73
  #
80
- # view('foo', :engine=>'html.erb')
81
- # render('foo', :views=>'admin_views')
74
+ # view('foo', engine: 'html.erb')
75
+ # render('foo', views: 'admin_views')
82
76
  #
83
77
  # There are additional options to +view+ and +render+ that are
84
78
  # available at runtime:
@@ -108,10 +102,10 @@ class Roda
108
102
  # :template_class :: Provides the template class to use, inside of using
109
103
  # Tilt or <tt>Tilt[:engine]</tt>.
110
104
  #
111
- # Here's how those options are used:
105
+ # Here's an example of using these options:
112
106
  #
113
- # view(:inline=>'<%= @foo %>')
114
- # render(:path=>'/path/to/template.erb')
107
+ # view(inline: '<%= @foo %>')
108
+ # render(path: '/path/to/template.erb')
115
109
  #
116
110
  # If you pass a hash as the first argument to +view+ or +render+, it should
117
111
  # have either +:template+, +:inline+, +:path+, or +:content+ (for +view+) as
@@ -128,7 +122,7 @@ class Roda
128
122
  # path never uses more than one template, you can use the +view_options+ plugin
129
123
  # and do:
130
124
  #
131
- # set_view_options :cache_key=>r.path_info
125
+ # set_view_options cache_key: r.path_info
132
126
  #
133
127
  # at the top of your route block. You can even do this if you do have paths
134
128
  # that use more than one template, as long as you specify +:cache_key+
@@ -138,18 +132,8 @@ class Roda
138
132
  # rendering faster by specifying +:cache_key+ inside the +:layout_opts+
139
133
  # plugin option.
140
134
  module Render
141
- OPTS={}.freeze
142
- RodaPlugins.deprecate_constant(self, :OPTS)
143
-
144
- # RODA3: Remove
145
- def self.load_dependencies(app, opts=RodaPlugins::OPTS)
146
- if opts[:escape] && opts[:escape] != :erubi
147
- app.plugin :_erubis_escaping
148
- end
149
- end
150
-
151
135
  # Setup default rendering options. See Render for details.
152
- def self.configure(app, opts=RodaPlugins::OPTS)
136
+ def self.configure(app, opts=OPTS)
153
137
  if app.opts[:render]
154
138
  orig_cache = app.opts[:render][:cache]
155
139
  opts = app.opts[:render][:orig_opts].merge(opts)
@@ -158,49 +142,27 @@ class Roda
158
142
  app.opts[:render][:orig_opts] = opts
159
143
 
160
144
  opts = app.opts[:render]
161
- if opts[:ext] && !opts[:engine]
162
- RodaPlugins.warn "The :ext render plugin option is deprecated and will be removed in Roda 3. Switch to using the :engine option."
163
- end
164
- opts[:engine] = (opts[:engine] || opts[:ext] || "erb").dup.freeze
145
+ opts[:engine] = (opts[:engine] || "erb").dup.freeze
165
146
  opts[:views] = app.expand_path(opts[:views]||"views").freeze
166
147
  opts[:allowed_paths] ||= [opts[:views]].freeze
167
148
  opts[:allowed_paths] = opts[:allowed_paths].map{|f| app.expand_path(f, nil)}.uniq.freeze
149
+ opts[:check_paths] = true unless opts.has_key?(:check_paths)
168
150
 
169
- if opts.fetch(:cache, true)
170
- if orig_cache
171
- opts[:cache] = orig_cache
172
- elsif cache_class = opts[:cache_class]
173
- opts[:cache] = cache_class.new
151
+ unless opts.has_key?(:explicit_cache)
152
+ opts[:explicit_cache] = if opts.fetch(:cache, true)
153
+ ENV['RACK_ENV'] == 'development'
174
154
  else
175
- opts[:cache] = app.thread_safe_cache
155
+ true
176
156
  end
177
157
  end
178
158
 
179
- opts[:explicit_cache] = ENV['RACK_ENV'] == 'development' unless opts.has_key?(:explicit_cache)
159
+ opts[:cache] = orig_cache || (opts[:cache_class] || RodaCache).new
180
160
 
181
161
  opts[:layout_opts] = (opts[:layout_opts] || {}).dup
162
+ opts[:layout_opts][:_is_layout] = true
182
163
  if opts[:layout_opts][:views]
183
164
  opts[:layout_opts][:views] = app.expand_path(opts[:layout_opts][:views]).freeze
184
165
  end
185
- # RODA3: Remove
186
- opts[:layout_opts][:_is_layout] = true
187
-
188
- if opts[:locals]
189
- RodaPlugins.warn "The :locals render plugin option is deprecated and will be removed in Roda 3. Locals should now be specified on a per-call basis, or you can use the render_locals plugin."
190
- end
191
-
192
- if opts[:layout_opts][:locals]
193
- RodaPlugins.warn "The :layout_opts=>:locals render plugin option is deprecated and will be removed in Roda 3. Locals should now be specified on a per-call basis, or you can use the render_locals plugin."
194
- end
195
-
196
- if opts[:layout_opts][:merge_locals]
197
- RodaPlugins.warn "The :layout_opts=>:merge_locals render plugin option is deprecated and will be removed in Roda 3. You can use the render_locals plugin for merging locals."
198
- end
199
-
200
- # RODA3: Remove
201
- if opts[:layout_opts][:merge_locals] && opts[:locals]
202
- opts[:layout_opts][:locals] = opts[:locals].merge(opts[:layout_opts][:locals] || {})
203
- end
204
166
 
205
167
  if layout = opts.fetch(:layout, true)
206
168
  opts[:layout] = true unless opts.has_key?(:layout)
@@ -218,21 +180,13 @@ class Roda
218
180
 
219
181
  template_opts = opts[:template_opts] = (opts[:template_opts] || {}).dup
220
182
  template_opts[:outvar] ||= '@_out_buf'
221
- if RUBY_VERSION >= "1.9" && !template_opts.has_key?(:default_encoding)
183
+ unless template_opts.has_key?(:default_encoding)
222
184
  template_opts[:default_encoding] = Encoding.default_external
223
185
  end
224
- # RODA3: Make :escape assume erubi, remove erubis support
225
- if opts[:escape] == :erubi
186
+
187
+ if opts[:escape]
226
188
  require 'tilt/erubi'
227
189
  template_opts[:escape] = true
228
- elsif opts[:escape]
229
- template_opts[:engine_class] = ErubisEscaping::Eruby
230
-
231
- opts[:escaper] ||= if opts[:escape_safe_classes]
232
- ErubisEscaping::UnsafeClassEscaper.new(opts[:escape_safe_classes])
233
- else
234
- ::Erubis::XmlHelper
235
- end
236
190
  end
237
191
  template_opts.freeze
238
192
 
@@ -252,17 +206,7 @@ class Roda
252
206
  def inherited(subclass)
253
207
  super
254
208
  opts = subclass.opts[:render] = subclass.opts[:render].dup
255
-
256
- if opts[:cache]
257
- opts[:cache] = if opts[:inherit_cache]
258
- opts[:cache] = opts[:cache].dup
259
- elsif cache_class = opts[:cache_class]
260
- opts[:cache] = cache_class.new
261
- else
262
- opts[:cache] = thread_safe_cache
263
- end
264
- end
265
-
209
+ opts[:cache] = opts[:cache].dup
266
210
  opts.freeze
267
211
  end
268
212
 
@@ -274,14 +218,12 @@ class Roda
274
218
 
275
219
  module InstanceMethods
276
220
  # Render the given template. See Render for details.
277
- def render(template, opts = RodaPlugins::OPTS, &block)
221
+ def render(template, opts = OPTS, &block)
278
222
  opts = render_template_opts(template, opts)
279
- retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||RodaPlugins::OPTS), &block)
223
+ retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
280
224
  end
281
225
 
282
- # Return the render options for the instance's class. While this
283
- # is not currently frozen, it may be frozen in a future version,
284
- # so you should not attempt to modify it.
226
+ # Return the render options for the instance's class.
285
227
  def render_opts
286
228
  self.class.render_opts
287
229
  end
@@ -289,7 +231,7 @@ class Roda
289
231
  # Render the given template. If there is a default layout
290
232
  # for the class, take the result of the template rendering
291
233
  # and render it inside the layout. See Render for details.
292
- def view(template, opts=RodaPlugins::OPTS)
234
+ def view(template, opts=OPTS)
293
235
  opts = parse_template_opts(template, opts)
294
236
  content = opts[:content] || render_template(opts)
295
237
 
@@ -304,12 +246,7 @@ class Roda
304
246
 
305
247
  # Convert template options to single hash when rendering templates using render.
306
248
  def render_template_opts(template, opts)
307
- opts = parse_template_opts(template, opts)
308
-
309
- # RODA3: Remove
310
- merge_render_locals(opts) if render_plugin_handle_locals?
311
-
312
- opts
249
+ parse_template_opts(template, opts)
313
250
  end
314
251
 
315
252
  # Private alias for render. Should be used by other plugins when they want to render a template
@@ -319,7 +256,8 @@ class Roda
319
256
  # If caching templates, attempt to retrieve the template from the cache. Otherwise, just yield
320
257
  # to get the template.
321
258
  def cached_template(opts, &block)
322
- if (!render_opts[:explicit_cache] || opts[:cache]) && (cache = render_opts[:cache]) && (key = opts[:cache_key])
259
+ if (!render_opts[:explicit_cache] || opts[:cache]) && (key = opts[:cache_key])
260
+ cache = render_opts[:cache]
323
261
  unless template = cache[key]
324
262
  template = cache[key] = yield
325
263
  end
@@ -333,10 +271,7 @@ class Roda
333
271
  # template block, and locals to use for the render in the passed options.
334
272
  def find_template(opts)
335
273
  render_opts = render_opts()
336
- if opts[:ext] && !opts[:engine]
337
- RodaPlugins.warn "The :ext render plugin option is deprecated and will be removed in Roda 3. Switch to using the :engine option."
338
- end
339
- engine_override = opts[:engine] ||= opts[:ext]
274
+ engine_override = opts[:engine]
340
275
  engine = opts[:engine] ||= render_opts[:engine]
341
276
  if content = opts[:inline]
342
277
  path = opts[:path] = content
@@ -349,41 +284,26 @@ class Roda
349
284
  opts[:template_class] ||= ::Tilt
350
285
  end
351
286
 
352
- if render_opts[:cache]
353
- if (cache = opts[:cache]).nil?
354
- cache = content || !opts[:template_block]
355
- end
287
+ if (cache = opts[:cache]).nil?
288
+ cache = content || !opts[:template_block]
289
+ end
356
290
 
357
- if cache
358
- template_block = opts[:template_block] unless content
359
- template_opts = opts[:template_opts]
291
+ if cache
292
+ template_block = opts[:template_block] unless content
293
+ template_opts = opts[:template_opts]
360
294
 
361
- opts[:cache_key] ||= if template_class || engine_override || template_opts || template_block
362
- [path, template_class, engine_override, template_opts, template_block]
363
- else
364
- path
365
- end
295
+ opts[:cache_key] ||= if template_class || engine_override || template_opts || template_block
296
+ [path, template_class, engine_override, template_opts, template_block]
366
297
  else
367
- opts.delete(:cache_key)
298
+ path
368
299
  end
369
- elsif opts[:cache]
370
- RodaPlugins.warn ":cache render/view method option used when caching explicitly disabled via :cache=>nil/false plugin option. Caching this template will be skipped for backwards compatibility. Starting in Roda 3, the :cache render/view method option will force caching even if the plugin defaults to not caching."
300
+ else
301
+ opts.delete(:cache_key)
371
302
  end
372
303
 
373
304
  opts
374
305
  end
375
306
 
376
- # RODA3: Remove
377
- def merge_render_locals(opts)
378
- if !opts[:_is_layout] && (r_locals = render_opts[:locals])
379
- opts[:locals] = if locals = opts[:locals]
380
- Hash[r_locals].merge!(locals)
381
- else
382
- r_locals
383
- end
384
- end
385
- end
386
-
387
307
  # Return a single hash combining the template and opts arguments.
388
308
  def parse_template_opts(template, opts)
389
309
  opts = Hash[opts]
@@ -427,24 +347,15 @@ class Roda
427
347
  # The template path for the given options.
428
348
  def template_path(opts)
429
349
  path = "#{opts[:views]}/#{template_name(opts)}.#{opts[:engine]}"
430
- full_path = self.class.expand_path(path)
431
350
  if opts.fetch(:check_paths){render_opts[:check_paths]}
351
+ full_path = self.class.expand_path(path)
432
352
  unless render_opts[:allowed_paths].any?{|f| full_path.start_with?(f)}
433
353
  raise RodaError, "attempt to render path not in allowed_paths: #{full_path} (allowed: #{render_opts[:allowed_paths].join(', ')})"
434
354
  end
435
- elsif !opts.has_key?(:check_paths) && !render_opts.has_key?(:check_paths)
436
- unless render_opts[:allowed_paths].any?{|f| full_path.start_with?(f)}
437
- RodaPlugins.warn "The :check_paths render/view method option and :check_paths render plugin option were not specified, and the path used for the template (#{full_path.inspect}) is not in the allowed paths (#{render_opts[:allowed_paths].inspect}). Allowing the template render anyway for backwards compatibility, but an error will be raised starting in Roda 3. Specify the :allowed_paths render plugin option to include the path, or use the :check_paths=>false render plugin option to explicitly disable path checking."
438
- end
439
355
  end
440
356
  path
441
357
  end
442
358
 
443
- # RODA3: Remove
444
- def render_plugin_handle_locals?
445
- true
446
- end
447
-
448
359
  # If a layout should be used, return a hash of options for
449
360
  # rendering the layout template. If a layout should not be
450
361
  # used, return nil.
@@ -452,41 +363,9 @@ class Roda
452
363
  if layout = opts.fetch(:layout, render_opts[:layout])
453
364
  layout_opts = render_layout_opts
454
365
 
455
- # RODA3: Remove
456
- merge_locals = layout_opts[:merge_locals]
457
-
458
366
  method_layout_opts = opts[:layout_opts]
459
-
460
- # RODA3: Remove
461
- if render_plugin_handle_locals?
462
- if method_layout_opts
463
- method_layout_locals = method_layout_opts[:locals]
464
- if method_layout_opts.has_key?(:merge_locals)
465
- RodaPlugins.warn "The :layout_opts=>:merge_locals view option is deprecated and will be removed in Roda 3. You can use the render_locals plugin for merging locals."
466
- merge_locals = method_layout_opts[:merge_locals]
467
- end
468
- end
469
-
470
- locals = {}
471
- if merge_locals && (plugin_locals = render_opts[:locals])
472
- locals.merge!(plugin_locals)
473
- end
474
- if layout_locals = layout_opts[:locals]
475
- locals.merge!(layout_locals)
476
- end
477
- if merge_locals && (method_locals = opts[:locals])
478
- locals.merge!(method_locals)
479
- end
480
- if method_layout_locals
481
- locals.merge!(method_layout_locals)
482
- end
483
- end
484
-
485
367
  layout_opts.merge!(method_layout_opts) if method_layout_opts
486
368
 
487
- # RODA3: Remove
488
- layout_opts[:locals] = locals if render_plugin_handle_locals? && !locals.empty?
489
-
490
369
  case layout
491
370
  when Hash
492
371
  layout_opts.merge!(layout)