2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-07-19 09:12:15 -04:00
|
|
|
module ActionView
|
2010-06-16 14:17:49 -04:00
|
|
|
# = Action View Context
|
|
|
|
#
|
2012-05-15 22:46:40 -04:00
|
|
|
# Action View contexts are supplied to Action Controller to render a template.
|
2010-06-16 14:17:49 -04:00
|
|
|
# The default Action View context is ActionView::Base.
|
2009-07-19 09:12:15 -04:00
|
|
|
#
|
2018-04-17 06:14:10 -04:00
|
|
|
# In order to work with Action Controller, a Context must just include this
|
|
|
|
# module. The initialization of the variables used by the context
|
|
|
|
# (@output_buffer, @view_flow, and @virtual_path) is responsibility of the
|
|
|
|
# object that includes this module (although you can call _prepare_context
|
|
|
|
# defined below).
|
2009-07-19 09:12:15 -04:00
|
|
|
module Context
|
2011-05-01 06:16:31 -04:00
|
|
|
attr_accessor :output_buffer, :view_flow
|
|
|
|
|
2011-05-01 13:39:57 -04:00
|
|
|
# Prepares the context by setting the appropriate instance variables.
|
|
|
|
def _prepare_context
|
|
|
|
@view_flow = OutputFlow.new
|
|
|
|
@output_buffer = nil
|
2020-12-30 07:24:58 -05:00
|
|
|
@virtual_path = nil
|
2011-05-01 13:39:57 -04:00
|
|
|
end
|
2011-05-01 06:16:31 -04:00
|
|
|
|
2011-05-01 13:39:57 -04:00
|
|
|
# Encapsulates the interaction with the view flow so it
|
2012-05-15 22:46:40 -04:00
|
|
|
# returns the correct buffer on +yield+. This is usually
|
2012-07-12 12:21:09 -04:00
|
|
|
# overwritten by helpers to add more behavior.
|
2016-10-28 23:05:58 -04:00
|
|
|
def _layout_for(name = nil)
|
2011-05-01 13:39:57 -04:00
|
|
|
name ||= :layout
|
|
|
|
view_flow.get(name).html_safe
|
2011-05-01 06:16:31 -04:00
|
|
|
end
|
2009-07-19 09:12:15 -04:00
|
|
|
end
|
2012-07-12 12:21:09 -04:00
|
|
|
end
|