Class: Dope::ResourceContext

Inherits:
Derailleur::Context
  • Object
show all
Defined in:
lib/dope/core/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resourceObject (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

#contentObject

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_typeObject



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_typeObject



22
23
24
# File 'lib/dope/core/context.rb', line 22

def default_content_type
  'text/plain'
end

#default_extObject



18
19
20
# File 'lib/dope/core/context.rb', line 18

def default_ext
  '.html'
end

#extObject



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

#headersObject



55
56
57
# File 'lib/dope/core/context.rb', line 55

def headers
  {'Content-Type' => content_type}
end

#mime_typesObject



42
43
44
# File 'lib/dope/core/context.rb', line 42

def mime_types
  MIME::Types.of(ext)
end

#perspectiveObject



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