Module: Karafka::Web::Ui::Helpers::PathsHelper

Included in:
Base
Defined in:
lib/karafka/web/ui/helpers/paths_helper.rb

Overview

Helper for web ui paths builders

Instance Method Summary collapse

Instance Method Details

#asset_path(local_path) ⇒ String

Generates a full path to any asset with our web-ui version. We ship all assets with the version in the url to prevent those assets from being used after update. After each web-ui update, assets are going to be re-fetched as the url will change

Parameters:

  • local_path (String)

    local path to the asset

Returns:

  • (String)

    full path to the asst including correct root path



27
28
29
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 27

def asset_path(local_path)
  root_path("assets/#{Karafka::Web::VERSION}/#{local_path}")
end

#explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil) ⇒ String

Helps build explorer paths. We often link offsets to proper messages, etc so this allows us to short-track this

Parameters:

  • topic_name (String, nil) (defaults to: nil)

    name of the topic where we want to go within the explorer or nil if we want to just go to the explorer root

  • partition_id (Integer, nil) (defaults to: nil)

    partition we want to display in the explorer or nil if we want to go to the topic root

  • offset (Integer, nil) (defaults to: nil)

    offset of particular message or nil of we want to just go to the partition root

  • action (String, nil) (defaults to: nil)

    specific routed action or nil

Returns:

  • (String)

    path to the expected location



41
42
43
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 41

def explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil)
  root_path(*['explorer', topic_name, partition_id, offset, action].compact)
end

#root_path(*args) ⇒ String

Note:

This needs to be done that way with the #root_path because the web UI can be mounted in a sub-path and we need to make sure our all paths are relative to “our” root, not the root of the app in which it was mounted.

Generates a full path with the root path out of the provided arguments

Parameters:

  • args (Array<String, Numeric>)

    arguments that will make the path

Returns:

  • (String)

    path from the root



17
18
19
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 17

def root_path(*args)
  "#{env.fetch('SCRIPT_NAME')}/#{args.join('/')}"
end