Module: SolidStackWeb::ApplicationHelper

Defined in:
app/helpers/solid_stack_web/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#format_duration(seconds) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/helpers/solid_stack_web/application_helper.rb', line 3

def format_duration(seconds)
  return "—" if seconds.nil?
  return "#{(seconds * 1000).round}ms" if seconds < 1
  s = seconds.to_i
  return "#{sprintf("%g", seconds.round(1))}s" if s < 60
  return "#{s / 60}m #{s % 60}s"      if s < 3600

  "#{s / 3600}h #{(s % 3600) / 60}m"
end

#inline_stylesObject



67
68
69
70
71
# File 'app/helpers/solid_stack_web/application_helper.rb', line 67

def inline_styles
  dir = SolidStackWeb::Engine.root.join("app/assets/stylesheets/solid_stack_web")
  css = dir.glob("_*.css").sort.map(&:read).join("\n")
  (:style, css.html_safe)
end

#queue_depth_sparkline_svg(sparkline) ⇒ Object



24
25
26
27
28
29
30
31
# File 'app/helpers/solid_stack_web/application_helper.rb', line 24

def queue_depth_sparkline_svg(sparkline)
  build_sparkline_svg(sparkline, css_class: "sqw-sparkline sqw-sparkline--sm",
                                 aria_label: "Queue depth over the last 12 hours") do |count, i|
    hours_ago = SolidStackWeb::QueueDepthSparkline::HOURS - 1 - i
    jobs_word = count == 1 ? "job" : "jobs"
    hours_ago.zero? ? "#{count} ready #{jobs_word} now" : "#{count} ready #{jobs_word} #{hours_ago}h ago"
  end
end

#throughput_sparkline_svg(sparkline) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/solid_stack_web/application_helper.rb', line 13

def throughput_sparkline_svg(sparkline)
  build_sparkline_svg(sparkline, aria_label: "Throughput over the last 12 hours") do |count, i|
    hours_ago = SolidStackWeb::ThroughputSparkline::HOURS - i
    if hours_ago == 1
      "#{count} #{count == 1 ? "job" : "jobs"} in the last hour"
    else
      "#{count} #{count == 1 ? "job" : "jobs"} (#{hours_ago}h–#{hours_ago - 1}h ago)"
    end
  end
end