Module: RailsPulse::ApplicationHelper

Includes:
Pagy::Frontend, BreadcrumbsHelper, ChartHelper, FormHelper, FormattingHelper, StatusHelper, TableHelper, TagsHelper
Defined in:
app/helpers/rails_pulse/application_helper.rb

Defined Under Namespace

Classes: RailsPulseHelper

Instance Method Summary collapse

Methods included from TagsHelper

#display_tag_badges

Methods included from FormHelper

#time_range_selector

Methods included from TableHelper

#cell_highlight_class, #render_cell_content

Methods included from StatusHelper

#categorize_operation, #duration_options, #event_color, #operation_category_label, #operation_status_indicator, #operations_performance_breakdown, #performance_badge_class, #query_status_indicator, #request_status_indicator, #rescue_template_missing, #route_status_indicator, #truncate_sql

Methods included from FormattingHelper

#human_readable_occurred_at, #human_readable_summary_period, #time_ago_in_words

Methods included from ChartHelper

#area_chart_options, #bar_chart_options, #base_chart_options, #line_chart_options, #render_stimulus_chart, #sparkline_chart_options

Methods included from BreadcrumbsHelper

#breadcrumbs

Instance Method Details

#pagy_items(pagy) ⇒ Object

Get items per page from Pagy instance (compatible with Pagy 8.x and 43+)



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/rails_pulse/application_helper.rb', line 42

def pagy_items(pagy)
  # Pagy 43+ uses options[:items] or has a limit method
  if pagy.respond_to?(:options) && pagy.options.is_a?(Hash)
    pagy.options[:items]
  # Pagy 8.x uses vars[:items]
  elsif pagy.respond_to?(:vars)
    pagy.vars[:items]
  # Fallback
  else
    pagy.limit || 10
  end
end

#pagy_next(pagy) ⇒ Object

Get next page number (compatible with Pagy 8.x and 43+)



80
81
82
# File 'app/helpers/rails_pulse/application_helper.rb', line 80

def pagy_next(pagy)
  pagy.respond_to?(:next) ? pagy.next : nil
end

#pagy_page_url(pagy, page_number) ⇒ Object

Get page URL from Pagy instance (compatible with Pagy 8.x and 43+)



56
57
58
59
60
61
62
63
64
# File 'app/helpers/rails_pulse/application_helper.rb', line 56

def pagy_page_url(pagy, page_number)
  # Pagy 43+ has page_url method
  if pagy.respond_to?(:page_url)
    pagy.page_url(page_number)
  # Pagy 8.x requires using pagy_url_for helper
  else
    pagy_url_for(pagy, page_number)
  end
end

#pagy_previous(pagy) ⇒ Object

Get previous page number (compatible with Pagy 8.x and 43+)



67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/rails_pulse/application_helper.rb', line 67

def pagy_previous(pagy)
  # Pagy 43+ uses 'previous'
  if pagy.respond_to?(:previous)
    pagy.previous
  # Pagy 8.x uses 'prev'
  elsif pagy.respond_to?(:prev)
    pagy.prev
  else
    nil
  end
end

#rails_pulseObject

Make Rails Pulse routes available as rails_pulse in views



85
86
87
# File 'app/helpers/rails_pulse/application_helper.rb', line 85

def rails_pulse
  @rails_pulse_helper ||= RailsPulseHelper.new(self)
end

#rails_pulse_csp_nonceObject

CSP nonce helper for Rails Pulse



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/helpers/rails_pulse/application_helper.rb', line 115

def rails_pulse_csp_nonce
  # Try various methods to get the CSP nonce from the host application
  nonce = nil

  # Method 1: Check for Rails 6+ CSP nonce helper
  if respond_to?(:content_security_policy_nonce)
    nonce = content_security_policy_nonce
  end

  # Method 2: Check for custom csp_nonce helper (common in many apps)
  if nonce.blank? && respond_to?(:csp_nonce)
    nonce = csp_nonce
  end

  # Method 3: Try to extract from request environment (where CSP gems often store it)
  if nonce.blank? && defined?(request) && request
    nonce = request.env["action_dispatch.content_security_policy_nonce"] ||
            request.env["secure_headers.content_security_policy_nonce"] ||
            request.env["csp_nonce"]
  end

  # Method 4: Check content_for CSP nonce (some apps set it this way)
  if nonce.blank? && respond_to?(:content_for) && content_for?(:csp_nonce)
    nonce = content_for(:csp_nonce)
  end

  # Method 5: Extract from meta tag if present (less efficient but works)
  if nonce.blank? && defined?(content_security_policy_nonce_tag)
    begin
      tag_content = content_security_policy_nonce_tag
      if tag_content && tag_content.include?("nonce-")
        nonce = tag_content.match(/nonce-([^"']+)/)[1] if tag_content.match(/nonce-([^"']+)/)
      end
    rescue
      # Ignore parsing errors
    end
  end

  # Return the nonce or nil (Rails will handle CSP properly with nil)
  nonce.presence
end

#rails_pulse_icon(name, options = {}) ⇒ Object Also known as: lucide_icon

Replacement for lucide_icon helper that works with pre-compiled assets Outputs a custom element that will be hydrated by Stimulus



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/rails_pulse/application_helper.rb', line 17

def rails_pulse_icon(name, options = {})
  width = options[:width] || options["width"] || 24
  height = options[:height] || options["height"] || 24
  css_class = options[:class] || options["class"] || ""

  # Additional HTML attributes
  attrs = options.except(:width, :height, :class, "width", "height", "class")

  ("rails-pulse-icon",
    "",
    data: {
      controller: "rails-pulse--icon",
      'rails-pulse--icon-name-value': name,
      'rails-pulse--icon-width-value': width,
      'rails-pulse--icon-height-value': height
    },
    class: css_class,
    **attrs
  )
end