Module: PrestoView::Utils

Included in:
API, Config
Defined in:
lib/presto/view/utils.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) engine_supported?(engine)

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/presto/view/utils.rb', line 30

def engine_supported? engine

  if e = ENGINES[engine]
    return e
  end

  msg = []
  msg << "#{ engine } engine not supported. Please use one of:"
  ENGINES.keys.map { |e| msg << ":#{e}" }
  raise msg.join("\n")
end

- (Object) guess_extension(engine)



23
24
25
26
27
28
# File 'lib/presto/view/utils.rb', line 23

def guess_extension engine
  ::Tilt.mappings.each_pair do |ext, engines|
    return ext if engines.include?(engine)
  end
  nil
end

- (Object) guess_layout(opts = {})



4
5
6
7
8
9
# File 'lib/presto/view/utils.rb', line 4

def guess_layout opts = {}
  if layout_name = opts[:layout] || layout[opts[:action]] || layout[:*]
    '%s.%s' % [::File.join(root, layouts_path || path, layout_name),
               (opts[:ext] || ext || guess_extension(engine))]
  end
end

- (Object) guess_path(path_or_action, ext = nil)



11
12
13
14
# File 'lib/presto/view/utils.rb', line 11

def guess_path path_or_action, ext = nil
  path = (@controller && @controller.ctrl.action_map[path_or_action]) || path_or_action.to_s
  ::File.join(root(), path(), path) << '.' << (ext || ext())
end

- (Object) guess_scope_and_context(*scope_and_or_context)



16
17
18
19
20
21
# File 'lib/presto/view/utils.rb', line 16

def guess_scope_and_context *scope_and_or_context
  scope, context = (scope() || @controller_instance || @controller), Hash.new
  scope = @controller_instance.instance_exec(&scope) if @controller_instance && scope.is_a?(Proc)
  scope_and_or_context.each { |a| a.is_a?(Hash) ? context.update(a) : scope = a }
  [scope, context]
end