Module: RailsPulse::ApplicationHelper

Includes:
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, #render_tag_badge

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, #duration_threshold_filter_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

#page_url(page_number) ⇒ Object



69
70
71
# File 'app/helpers/rails_pulse/application_helper.rb', line 69

def page_url(page_number)
  url_for(request.query_parameters.merge(page: page_number))
end

#rails_pulseObject

Make Rails Pulse routes available as rails_pulse in views



74
75
76
# File 'app/helpers/rails_pulse/application_helper.rb', line 74

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

#rails_pulse_csp_nonceObject

CSP nonce helper for Rails Pulse



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
156
157
158
159
160
# File 'app/helpers/rails_pulse/application_helper.rb', line 120

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



13
14
15
16
17
18
19
20
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
47
48
49
# File 'app/helpers/rails_pulse/application_helper.rb', line 13

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

  # Normalize numeric width/height values into px for layout stability
  width_css = normalize_dimension(width)
  height_css = normalize_dimension(height)

  default_style = [
    "display:inline-flex",
    "align-items:center",
    "justify-content:center",
    "width:#{width_css}",
    "height:#{height_css}",
    "flex-shrink:0"
  ].join(";")

  style_attribute = [ default_style, custom_style ].compact.join(";")

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

  ("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,
    style: style_attribute,
    **attrs
  )
end