Class: RailsWayback::BarRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_wayback/bar_renderer.rb

Overview

Builds the HTML payload that the middleware injects into every HTML response and references the toolbar's same-origin CSS and JavaScript.

Constant Summary collapse

TEMPLATE =
ERB.new(File.read(File.expand_path("bar_renderer.html.erb", __dir__))).freeze
STYLES =
File.read(File.expand_path("bar_renderer.css", __dir__)).freeze
SEARCH_SCRIPT =
File.read(File.expand_path("bar_search.js", __dir__)).freeze
SCRIPT =
[SEARCH_SCRIPT, File.read(File.expand_path("bar_renderer.js", __dir__))].join("\n").freeze

Instance Method Summary collapse

Constructor Details

#initialize(current_branch:, current_commit:, active_ref: nil, active_branch: nil, engine_mount: "/rails-wayback", diff_info: nil, csp_nonce: nil, ref_error: nil) ⇒ BarRenderer

Returns a new instance of BarRenderer.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_wayback/bar_renderer.rb', line 16

def initialize(current_branch:, current_commit:, active_ref: nil, active_branch: nil,
               engine_mount: "/rails-wayback", diff_info: nil, csp_nonce: nil, ref_error: nil)
  @current_branch = current_branch
  @current_commit = current_commit
  @active_ref = active_ref
  @active_branch = active_branch
  @engine_mount = normalize_mount(engine_mount)
  @diff_info = diff_info
  @csp_nonce = csp_nonce.to_s
  @ref_error = ref_error.to_s
end

Instance Method Details

#render ⇒ Object



28
29
30
# File 'lib/rails_wayback/bar_renderer.rb', line 28

def render
  TEMPLATE.result(binding)
end