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
-
#pagy_items(pagy) ⇒ Object
Get items per page from Pagy instance (compatible with Pagy 8.x and 43+).
-
#pagy_next(pagy) ⇒ Object
Get next page number (compatible with Pagy 8.x and 43+).
-
#pagy_page_url(pagy, page_number) ⇒ Object
Get page URL from Pagy instance (compatible with Pagy 8.x and 43+).
-
#pagy_previous(pagy) ⇒ Object
Get previous page number (compatible with Pagy 8.x and 43+).
-
#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 TagsHelper
#display_tag_badges, #render_tag_badge
Methods included from FormHelper
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
Instance Method Details
#pagy_items(pagy) ⇒ Object
Get items per page from Pagy instance (compatible with Pagy 8.x and 43+)
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 73 def pagy_items(pagy) # Pagy 43+ uses options[:items] or has a limit method if pagy.respond_to?(:options) && pagy..is_a?(Hash) pagy.[: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+)
111 112 113 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 111 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+)
87 88 89 90 91 92 93 94 95 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 87 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+)
98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 98 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_pulse ⇒ Object
Make Rails Pulse routes available as rails_pulse in views
116 117 118 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 116 def rails_pulse @rails_pulse_helper ||= RailsPulseHelper.new(self) end |
#rails_pulse_csp_nonce ⇒ Object
CSP nonce helper for Rails Pulse
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 146 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/rails_pulse/application_helper.rb', line 17 def rails_pulse_icon(name, = {}) width = [:width] || ["width"] || 24 height = [:height] || ["height"] || 24 css_class = [:class] || ["class"] || "" custom_style = [:style] || ["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 = .except(:width, :height, :class, :style, "width", "height", "class", "style") 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, style: style_attribute, **attrs ) end |