Module: Karafka::Web::Ui::Helpers::ApplicationHelper
- Included in:
- Base
- Defined in:
- lib/karafka/web/ui/helpers/application_helper.rb
Overview
Application-wide helpers: navigation, layout, icons, empty states and generic hash utilities. More specific concerns live in dedicated helpers ([[SortingHelper]], [[FormattingHelper]], [[BadgesHelper]], [[PartitionsHelper]]).
Instance Method Summary collapse
-
#deep_merge(hash1, hash2) ⇒ Hash
Merges two hashes deeply, combining nested hashes recursively.
-
#empty_state(message, icon: "inbox", description: nil, action: nil, action_path: nil, card: nil, &block) ⇒ String
Renders the standardized "nothing here" empty state (icon + message, optionally with a description and a call-to-action button).
-
#icon(name, size: nil) ⇒ String
Renders the svg icon out of our icon set.
-
#nav_class(location) ⇒ Object
Adds active class to the current location in the nav if needed.
-
#view_title(title) ⇒ String
Sets the particular page title.
Instance Method Details
#deep_merge(hash1, hash2) ⇒ Hash
Merges two hashes deeply, combining nested hashes recursively.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/karafka/web/ui/helpers/application_helper.rb', line 78 def deep_merge(hash1, hash2) merged_hash = hash1.dup hash2.each_pair do |k, v| tv = merged_hash[k] merged_hash[k] = if tv.is_a?(Hash) && v.is_a?(Hash) deep_merge(tv, v) else v end end merged_hash end |
#empty_state(message, icon: "inbox", description: nil, action: nil, action_path: nil, card: nil, &block) ⇒ String
Renders the standardized "nothing here" empty state (icon + message, optionally with a description and a call-to-action button). The description can also be given as a block, in which case it may contain arbitrary markup (e.g. a checklist).
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/karafka/web/ui/helpers/application_helper.rb', line 49 def empty_state( , icon: "inbox", description: nil, action: nil, action_path: nil, card: nil, &block ) description = capture_erb(&block) if block inject_erb partial( "shared/empty_state", locals: { message: , icon_name: icon, description: description, action: action, action_path: action_path, card: card } ) end |
#icon(name, size: nil) ⇒ String
Renders the svg icon out of our icon set
33 34 35 |
# File 'lib/karafka/web/ui/helpers/application_helper.rb', line 33 def icon(name, size: nil) render "shared/icons/_#{name}", locals: { size: size } end |
#nav_class(location) ⇒ Object
Adds active class to the current location in the nav if needed
14 15 16 17 18 19 |
# File 'lib/karafka/web/ui/helpers/application_helper.rb', line 14 def nav_class(location) comparator, value = location.to_a.first local_location = request.path.gsub(env.fetch("SCRIPT_NAME"), "") local_location.public_send(:"#{comparator}?", value) ? "active" : "" end |
#view_title(title) ⇒ String
Sets the particular page title
25 26 27 |
# File 'lib/karafka/web/ui/helpers/application_helper.rb', line 25 def view_title(title) content_for(:title) { title } end |