Class: Terminus::Proxy::DriverBody
- Inherits:
-
Object
- Object
- Terminus::Proxy::DriverBody
- Defined in:
- lib/terminus/proxy/driver_body.rb
Constant Summary collapse
- TEMPLATE =
ERB.new(<<-DRIVER) <script id="terminus-data" type="text/javascript"> TERMINUS_STATUS = <%= @response.first %>; TERMINUS_HEADERS = {}; <% @response[1].each do |key, value| %> TERMINUS_HEADERS[<%= key.inspect %>] = <%= value.inspect %>; <% end %> TERMINUS_SOURCE = <%= page_source %>; </script> <script type="text/javascript"> (function() { var terminusScript = document.getElementById('terminus-data'); terminusScript.parentNode.removeChild(terminusScript); })(); </script> <%= driver_script %> DRIVER
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(env, response) ⇒ DriverBody
constructor
A new instance of DriverBody.
Constructor Details
#initialize(env, response) ⇒ DriverBody
Returns a new instance of DriverBody.
23 24 25 26 27 |
# File 'lib/terminus/proxy/driver_body.rb', line 23 def initialize(env, response) @env = env @response = response @body = response[2] end |
Instance Method Details
#each(&block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/terminus/proxy/driver_body.rb', line 29 def each(&block) script_injected = false @source = '' @body.each do |fragment| @source << fragment output = inject_script(fragment) script_injected ||= (output != fragment) block.call(output) end unless script_injected block.call(TEMPLATE.result(binding)) end end |