Guest User

Untitled

a guest
May 5th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 KB | None | 0 0
  1. diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
  2. index d12cc41..8736178 100644
  3. --- a/actionpack/lib/action_controller/base.rb
  4. +++ b/actionpack/lib/action_controller/base.rb
  5. @@ -859,7 +859,7 @@ module ActionController #:nodoc:
  6. raise DoubleRenderError, "Can only render or redirect once per action" if performed?
  7.  
  8. if options.nil?
  9. - return render_for_file(default_template_name)
  10. + return render(:file => default_template_name, :layout => true)
  11. elsif !extra_options.is_a?(Hash)
  12. raise RenderError, "You called render with invalid options : #{options.inspect}, #{extra_options.inspect}"
  13. else
  14. @@ -870,6 +870,8 @@ module ActionController #:nodoc:
  15. end
  16. end
  17.  
  18. + response.layout = layout = pick_layout(options)
  19. +
  20. if content_type = options[:content_type]
  21. response.content_type = content_type.to_s
  22. end
  23. @@ -879,20 +881,21 @@ module ActionController #:nodoc:
  24. end
  25.  
  26. if options.has_key?(:text)
  27. - render_for_text(options[:text], options[:status])
  28. + text = layout ? @template.render(options.merge(:text => options[:text], :layout => layout)) : options[:text]
  29. + render_for_text(text, options[:status])
  30.  
  31. else
  32. if file = options[:file]
  33. - render_for_file(file, options[:status], options[:locals] || {})
  34. + render_for_file(file, options[:status], layout, options[:locals] || {})
  35.  
  36. elsif template = options[:template]
  37. - render_for_file(template, options[:status], options[:locals] || {})
  38. + render_for_file(template, options[:status], layout, options[:locals] || {})
  39.  
  40. elsif inline = options[:inline]
  41. - render_for_text(@template.render(options), options[:status])
  42. + render_for_text(@template.render(options.merge(:layout => layout)), options[:status])
  43.  
  44. elsif action_name = options[:action]
  45. - render_for_file(default_template_name(action_name.to_s), options[:status])
  46. + render_for_file(default_template_name(action_name.to_s), options[:status], layout)
  47.  
  48. elsif xml = options[:xml]
  49. response.content_type ||= Mime::XML
  50. @@ -906,7 +909,11 @@ module ActionController #:nodoc:
  51.  
  52. elsif options[:partial]
  53. options[:partial] = default_template_name if options[:partial] == true
  54. - render_for_text(@template.render(options), options[:status])
  55. + if layout
  56. + render_for_text(@template.render(:text => @template.render(options), :layout => layout), options[:status])
  57. + else
  58. + render_for_text(@template.render(options), options[:status])
  59. + end
  60.  
  61. elsif options[:update]
  62. @template.send! :evaluate_assigns_and_ivars
  63. @@ -919,7 +926,7 @@ module ActionController #:nodoc:
  64. render_for_text(nil, options[:status])
  65.  
  66. else
  67. - render_for_file(default_template_name, options[:status])
  68. + render_for_file(default_template_name, options[:status], layout)
  69. end
  70. end
  71. end
  72. @@ -1114,9 +1121,9 @@ module ActionController #:nodoc:
  73.  
  74.  
  75. private
  76. - def render_for_file(template_path, status = nil, locals = {}) #:nodoc:
  77. + def render_for_file(template_path, status = nil, layout = nil, locals = {}) #:nodoc:
  78. logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
  79. - render_for_text(@template.render(:file => template_path, :locals => locals), status)
  80. + render_for_text @template.render(:file => template_path, :locals => locals, :layout => layout), status
  81. end
  82.  
  83. def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
  84. diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb
  85. index f3535f8..3d32519 100644
  86. --- a/actionpack/lib/action_controller/caching/actions.rb
  87. +++ b/actionpack/lib/action_controller/caching/actions.rb
  88. @@ -121,7 +121,7 @@ module ActionController #:nodoc:
  89. end
  90.  
  91. def content_for_layout(controller)
  92. - controller.response.layout && controller.response.template.instance_variable_get('@content_for_layout')
  93. + controller.response.layout && controller.response.template.instance_variable_get('@cached_content_for_layout')
  94. end
  95. end
  96.  
  97. diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
  98. index 585bd03..ef59c7d 100644
  99. --- a/actionpack/lib/action_controller/layout.rb
  100. +++ b/actionpack/lib/action_controller/layout.rb
  101. @@ -3,11 +3,6 @@ module ActionController #:nodoc:
  102. def self.included(base)
  103. base.extend(ClassMethods)
  104. base.class_eval do
  105. - # NOTE: Can't use alias_method_chain here because +render_without_layout+ is already
  106. - # defined as a publicly exposed method
  107. - alias_method :render_with_no_layout, :render
  108. - alias_method :render, :render_with_a_layout
  109. -
  110. class << self
  111. alias_method_chain :inherited, :layout
  112. end
  113. @@ -240,50 +235,24 @@ module ActionController #:nodoc:
  114. end
  115. end
  116.  
  117. - protected
  118. - def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc:
  119. - template_with_options = options.is_a?(Hash)
  120. -
  121. - if (layout = pick_layout(template_with_options, options)) && apply_layout?(template_with_options, options)
  122. - options.delete(:layout) if template_with_options
  123. - logger.info("Rendering template within #{layout}") if logger
  124. -
  125. - content_for_layout = render_with_no_layout(options, extra_options, &block)
  126. - erase_render_results
  127. - @template.instance_variable_set("@content_for_layout", content_for_layout)
  128. - response.layout = layout
  129. - status = template_with_options ? options[:status] : nil
  130. - render_for_text(@template.render(layout), status)
  131. - else
  132. - render_with_no_layout(options, extra_options, &block)
  133. - end
  134. - end
  135. -
  136. -
  137. private
  138. - def apply_layout?(template_with_options, options)
  139. - return false if options == :update
  140. - template_with_options ? candidate_for_layout?(options) : !template_exempt_from_layout?
  141. - end
  142. -
  143. def candidate_for_layout?(options)
  144. - (options.has_key?(:layout) && options[:layout] != false) ||
  145. - options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? &&
  146. + options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? &&
  147. !template_exempt_from_layout?(options[:template] || default_template_name(options[:action]))
  148. end
  149.  
  150. - def pick_layout(template_with_options, options)
  151. - if template_with_options
  152. - case layout = options[:layout]
  153. - when FalseClass
  154. - nil
  155. - when NilClass, TrueClass
  156. - active_layout if action_has_layout?
  157. - else
  158. - active_layout(layout)
  159. + def pick_layout(options)
  160. + if options.has_key?(:layout)
  161. + case layout = options.delete(:layout)
  162. + when FalseClass
  163. + nil
  164. + when NilClass, TrueClass
  165. + active_layout if action_has_layout? && !template_exempt_from_layout?(default_template_name)
  166. + else
  167. + active_layout(layout)
  168. end
  169. else
  170. - active_layout if action_has_layout?
  171. + active_layout if action_has_layout? && candidate_for_layout?(options)
  172. end
  173. end
  174.  
  175. diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
  176. index ce629d3..f1c6f4a 100644
  177. --- a/actionpack/lib/action_view/base.rb
  178. +++ b/actionpack/lib/action_view/base.rb
  179. @@ -246,23 +246,8 @@ module ActionView #:nodoc:
  180. update_page(&block)
  181. elsif options.is_a?(Hash)
  182. options = options.reverse_merge(:locals => {})
  183. -
  184. - if partial_layout = options.delete(:layout)
  185. - if block_given?
  186. - begin
  187. - @_proc_for_layout = block
  188. - concat(render(options.merge(:partial => partial_layout)))
  189. - ensure
  190. - @_proc_for_layout = nil
  191. - end
  192. - else
  193. - begin
  194. - original_content_for_layout, @content_for_layout = @content_for_layout, render(options)
  195. - render(options.merge(:partial => partial_layout))
  196. - ensure
  197. - @content_for_layout = original_content_for_layout
  198. - end
  199. - end
  200. + if options[:layout]
  201. + render_with_layout(options, local_assigns, &block)
  202. elsif options[:file]
  203. if options[:use_full_path]
  204. ActiveSupport::Deprecation.warn("use_full_path option has been deprecated and has no affect.", caller)
  205. @@ -273,6 +258,8 @@ module ActionView #:nodoc:
  206. render_partial(options)
  207. elsif options[:inline]
  208. InlineTemplate.new(options[:inline], options[:type]).render(self, options[:locals])
  209. + elsif options[:text]
  210. + options[:text]
  211. end
  212. end
  213. end
  214. @@ -362,5 +349,29 @@ module ActionView #:nodoc:
  215. controller.response.content_type ||= content_type
  216. end
  217. end
  218. +
  219. + def render_with_layout(options, local_assigns, &block)
  220. + partial_layout = options.delete(:layout)
  221. + if block_given?
  222. + begin
  223. + @_proc_for_layout = block
  224. + concat(render(options.merge(:partial => partial_layout)))
  225. + ensure
  226. + @_proc_for_layout = nil
  227. + end
  228. + else
  229. + begin
  230. + original_content_for_layout, @content_for_layout = @content_for_layout, render(options)
  231. + if (options[:inline] || options[:file] || options[:text])
  232. + @cached_content_for_layout = @content_for_layout
  233. + render(:file => partial_layout, :locals => local_assigns)
  234. + else
  235. + render(options.merge(:partial => partial_layout))
  236. + end
  237. + ensure
  238. + @content_for_layout = original_content_for_layout
  239. + end
  240. + end
  241. + end
  242. end
  243. end
Add Comment
Please, Sign In to add comment