File: template.rb

package info (click to toggle)
ruby-web-console 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 632 kB
  • sloc: ruby: 1,496; javascript: 497; sh: 19; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module WebConsole
  # A facade that handles template rendering and composition.
  #
  # It introduces template helpers to ease the inclusion of scripts only on
  # Rails error pages.
  class Template
    # Lets you customize the default templates folder location.
    cattr_accessor :template_paths, default: [ File.expand_path("../templates", __FILE__) ]

    def initialize(env, session)
      @env = env
      @session = session
      @mount_point = Middleware.mount_point
    end

    # Render a template (inferred from +template_paths+) as a plain string.
    def render(template)
      view = View.with_empty_template_cache.with_view_paths(template_paths, instance_values)
      view.render(template: template, layout: false)
    end
  end
end