Class: Dope::ResourceContext
- Inherits:
-
Derailleur::Context
- Object
- Derailleur::Context
- Dope::ResourceContext
- Defined in:
- lib/dope/core/context.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#content ⇒ Object
XXX bitchy: all the if ext == ‘.html’ may go to the code in the view.
- #content_type ⇒ Object
- #default_content_type ⇒ Object
- #default_ext ⇒ Object
- #ext ⇒ Object
- #headers ⇒ Object
-
#initialize(env, ctx, resource, &blk) ⇒ ResourceContext
constructor
A new instance of ResourceContext.
- #mime_types ⇒ Object
- #perspective ⇒ Object
Constructor Details
#initialize(env, ctx, resource, &blk) ⇒ ResourceContext
Returns a new instance of ResourceContext.
9 10 11 12 |
# File 'lib/dope/core/context.rb', line 9 def initialize(env, ctx, resource, &blk) super(env, ctx, &blk) @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
8 9 10 |
# File 'lib/dope/core/context.rb', line 8 def resource @resource end |
Instance Method Details
#content ⇒ Object
XXX bitchy: all the if ext == ‘.html’ may go to the code in the view
33 34 35 36 37 38 39 40 |
# File 'lib/dope/core/context.rb', line 33 def content e = ext if e == '.html' resource.view.render(self) else resource.to_ext(e, self) end end |
#content_type ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/dope/core/context.rb', line 46 def content_type m = mime_types if m m.first.to_s else default_content_type end end |
#default_content_type ⇒ Object
22 23 24 |
# File 'lib/dope/core/context.rb', line 22 def default_content_type 'text/plain' end |
#default_ext ⇒ Object
18 19 20 |
# File 'lib/dope/core/context.rb', line 18 def default_ext '.html' end |
#ext ⇒ Object
26 27 28 29 30 |
# File 'lib/dope/core/context.rb', line 26 def ext ret = extname return default_ext if ret.empty? ret end |
#headers ⇒ Object
55 56 57 |
# File 'lib/dope/core/context.rb', line 55 def headers {'Content-Type' => content_type} end |
#mime_types ⇒ Object
42 43 44 |
# File 'lib/dope/core/context.rb', line 42 def mime_types MIME::Types.of(ext) end |
#perspective ⇒ Object
14 15 16 |
# File 'lib/dope/core/context.rb', line 14 def perspective (Rack::Utils.parse_query(env['QUERY_STRING'])['perspective'] || 'default').to_sym end |