Module: RailsApiKeys::UI::ApiKeysHelper

Defined in:
app/helpers/rails_api_keys/ui/api_keys_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.stylesheet_contentsObject



38
39
40
# File 'app/helpers/rails_api_keys/ui/api_keys_helper.rb', line 38

def self.stylesheet_contents
  @stylesheet_contents ||= File.read(stylesheet_path).html_safe
end

.stylesheet_pathObject



34
35
36
# File 'app/helpers/rails_api_keys/ui/api_keys_helper.rb', line 34

def self.stylesheet_path
  Engine.root.join("app/assets/stylesheets/rails_api_keys/ui.css")
end

Instance Method Details

#rails_api_keys_ui_panel(api_keys:, create_path:, destroy_path:, raw_token: nil) ⇒ Object

Renders the embeddable API keys panel (list + create/reveal modals).

Reads the reveal-once raw token from flash when raw_token is omitted.

Parameters:

  • api_keys (Enumerable)
  • create_path (String)
  • destroy_path (Proc, #call)

    receives an api_key, returns path

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


14
15
16
17
18
19
20
21
22
# File 'app/helpers/rails_api_keys/ui/api_keys_helper.rb', line 14

def rails_api_keys_ui_panel(api_keys:, create_path:, destroy_path:, raw_token: nil)
  render partial: "rails_api_keys/ui/api_keys/panel",
         locals: {
           api_keys: api_keys,
           create_path: create_path,
           destroy_path: destroy_path,
           raw_token: raw_token.nil? ? flash[RailsApiKeys::UI.configuration.raw_token_flash_key] : raw_token
         }
end

#rails_api_keys_ui_stylesheetObject

Inlines the gem stylesheet once per render (no asset pipeline required). Disable with config.include_stylesheet = false when the host supplies styles.



26
27
28
29
30
31
32
# File 'app/helpers/rails_api_keys/ui/api_keys_helper.rb', line 26

def rails_api_keys_ui_stylesheet
  return "".html_safe unless RailsApiKeys::UI.configuration.include_stylesheet
  return "".html_safe if @_rails_api_keys_ui_stylesheet_rendered

  @_rails_api_keys_ui_stylesheet_rendered = true
  (:style, ApiKeysHelper.stylesheet_contents, type: "text/css")
end