Class: Rack::IframeTransport
- Inherits:
-
Object
- Object
- Rack::IframeTransport
show all
- Defined in:
- lib/rack_iframe_transport.rb
Instance Method Summary
collapse
Constructor Details
#initialize(app, tag = 'textarea', meta = {}) ⇒ IframeTransport
Returns a new instance of IframeTransport.
3
4
5
6
7
|
# File 'lib/rack_iframe_transport.rb', line 3
def initialize(app, tag = 'textarea', meta = {})
@app = app
@tag = tag
@meta = meta
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
54
55
56
|
# File 'lib/rack_iframe_transport.rb', line 54
def method_missing(method, *args)
@response.send(method.intern, *args)
end
|
Instance Method Details
#_call(env) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rack_iframe_transport.rb', line 13
def _call(env)
@status, @headers, @response = @app.call(env)
@request = Rack::Request.new(env)
if iframe_transport?
@enclosed_content_type = @headers['Content-Type'] || 'text/html'
@headers['Content-Type'] = 'text/html'
[@status, @headers, self]
else
[@status, @headers, @response]
end
end
|
#call(env) ⇒ Object
9
10
11
|
# File 'lib/rack_iframe_transport.rb', line 9
def call(env)
dup._call(env)
end
|
#each(&block) ⇒ Object
26
27
28
29
30
|
# File 'lib/rack_iframe_transport.rb', line 26
def each(&block)
block.call(html_document_left) if iframe_transport?
@response.each(&block)
block.call(html_document_right) if iframe_transport?
end
|
#html_document_left ⇒ Object
36
37
38
|
# File 'lib/rack_iframe_transport.rb', line 36
def html_document_left
"<!DOCTYPE html><html><body><#{@tag} #{metadata}>"
end
|
#html_document_right ⇒ Object
40
41
42
|
# File 'lib/rack_iframe_transport.rb', line 40
def html_document_right
"</#{@tag}></body></html>"
end
|
#iframe_transport? ⇒ Boolean
32
33
34
|
# File 'lib/rack_iframe_transport.rb', line 32
def iframe_transport?
@request.params['X-Requested-With'] == 'IFrame'
end
|
44
45
46
47
48
49
50
|
# File 'lib/rack_iframe_transport.rb', line 44
def metadata
meta = @meta.dup
meta['data-status'] = @response.status if @response.respond_to? :status
meta['data-statusText'] = @response.status_message if @response.respond_to? :status_message
meta['data-type'] = @enclosed_content_type
meta.map {|key,value| "#{key}='#{value}'" }.join(' ')
end
|