Class: RailsWayback::BarRenderer

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

Overview

Builds the HTML/CSS/JS payload that the middleware injects into every HTML response so the developer can travel from any page of their app without visiting a dedicated route.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BarRenderer.



11
12
13
14
15
16
17
18
19
# File 'lib/rails_wayback/bar_renderer.rb', line 11

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

Instance Method Details

#renderObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rails_wayback/bar_renderer.rb', line 21

def render
  <<~HTML
    <style data-rails-wayback>#{styles}</style>
    <div id="rails-wayback-bar" data-mount="#{escape(@engine_mount)}"
         data-branch="#{escape(@current_branch)}"
         data-commit="#{escape(@current_commit)}"
         data-active-ref="#{escape(@active_ref.to_s)}"
         data-active-branch="#{escape(@active_branch.to_s)}">
      <div class="rw-bar-inner">
        <div class="rw-field">
          <label>#{escape(branch_label)}</label>
          <select data-rw-branch></select>
        </div>
        <div class="rw-field rw-flex">
          <label>#{escape(commit_label)}</label>
          <select data-rw-commit></select>
        </div>
        <div class="rw-state" data-rw-state></div>
        <button type="button" data-rw-travel class="rw-btn rw-btn-primary">Travel</button>
        <button type="button" data-rw-reset  class="rw-btn rw-btn-ghost" hidden>Return to HEAD</button>
      </div>
      #{diff_summary_html}
    </div>
    <script data-rails-wayback>#{script}</script>
  HTML
end