Module: WIP::Runner::Renderer

Included in:
Context
Defined in:
lib/wip/runner/renderer.rb,
lib/wip/runner/renderer/helper.rb,
lib/wip/runner/renderer/context.rb,
lib/wip/runner/renderer/handlers.rb,
lib/wip/runner/renderer/handlers/erb.rb

Defined Under Namespace

Modules: Handlers Classes: Context, Helper

Instance Method Summary collapse

Instance Method Details

#asset(path) ⇒ Object



4
5
6
# File 'lib/wip/runner/renderer.rb', line 4

def asset(path)
  File.read(asset_path(path))
end

#asset_path(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wip/runner/renderer.rb', line 8

def asset_path(path)
  return File.expand_path(path) if File.exist?(path)

  paths = WIP::Runner::CLI.assets
  paths.each do |base|
    file = File.join("#{base}/#{path}")
    return file if File.exist?(file)
  end

  raise WIP::Runner::InvalidArgument,
    "#{path} not found in:\n#{paths.map { |base| "    - #{base}" }.join("\n")}"
end

#render(content, context = {}) ⇒ Object

TODO: allow handler configuration/option



22
23
24
25
# File 'lib/wip/runner/renderer.rb', line 22

def render(content, context = {})
  content = path?(content) ? asset(content) : content
  handler(:ERB, content).render(Context.for(context))
end