Module: SolidWebUi::Cable::ApplicationHelper

Defined in:
app/helpers/solid_web_ui/cable/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#cable_nav(active) ⇒ Object



5
6
7
8
9
10
# File 'app/helpers/solid_web_ui/cable/application_helper.rb', line 5

def cable_nav(active)
  [
    { label: "Dashboard", href: root_path, active: active == :dashboard },
    { label: "Channels", href: channels_path, active: active == :channels }
  ]
end

#readable_channel(channel, length: 80) ⇒ Object



12
13
14
# File 'app/helpers/solid_web_ui/cable/application_helper.rb', line 12

def readable_channel(channel, length: 80)
  truncate(channel.to_s.dup.force_encoding("UTF-8").scrub("?"), length: length)
end

#readable_payload(payload, length: 120) ⇒ Object

Cable payloads are binary; present a scrubbed, truncated preview.



17
18
19
# File 'app/helpers/solid_web_ui/cable/application_helper.rb', line 17

def readable_payload(payload, length: 120)
  truncate(payload.to_s.dup.force_encoding("UTF-8").scrub("?"), length: length)
end

#short_time(time) ⇒ Object



21
22
23
24
25
# File 'app/helpers/solid_web_ui/cable/application_helper.rb', line 21

def short_time(time)
  return "" if time.nil?

  time.in_time_zone(SolidWebUi::Cable.config.time_zone).strftime("%Y-%m-%d %H:%M:%S")
end