Module: RailsPulse::ApplicationHelper
- Includes:
- Pagy::Frontend, BreadcrumbsHelper, CachedComponentHelper, ChartHelper, FormattingHelper, StatusHelper, TableHelper
- Defined in:
- app/helpers/rails_pulse/application_helper.rb
Defined Under Namespace
Classes: RailsPulseHelper
Instance Method Summary collapse
-
#rails_pulse ⇒ Object
Make Rails Pulse routes available as rails_pulse in views.
-
#rails_pulse_csp_nonce ⇒ Object
CSP nonce helper for Rails Pulse.
-
#rails_pulse_icon(name, options = {}) ⇒ Object
(also: #lucide_icon)
Replacement for lucide_icon helper that works with pre-compiled assets Outputs a custom element that will be hydrated by Stimulus.
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, #time_ago_in_words
Methods included from ChartHelper
#area_chart_options, #bar_chart_options, #base_chart_options, #line_chart_options, #sparkline_chart_options
Methods included from CachedComponentHelper
Methods included from BreadcrumbsHelper
Instance Method Details
#rails_pulse ⇒ Object
Make Rails Pulse routes available as rails_pulse in views
39 40 41 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 39 def rails_pulse @rails_pulse_helper ||= RailsPulseHelper.new(self) end |
#rails_pulse_csp_nonce ⇒ Object
CSP nonce helper for Rails Pulse
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 69 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
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 14 def rails_pulse_icon(name, = {}) width = [:width] || ["width"] || 24 height = [:height] || ["height"] || 24 css_class = [:class] || ["class"] || "" # Additional HTML attributes attrs = .except(:width, :height, :class, "width", "height", "class") content_tag("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 |