Class: EmbedCodeDropdown::Component

Inherits:
Lookbook::BaseComponent
  • Object
show all
Defined in:
app/components/lookbook/embed_code_dropdown/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(preview:, target:, pages:, params:, policy:, **html_attrs) ⇒ Component

Returns a new instance of Component.



5
6
7
8
9
10
11
12
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 5

def initialize(preview:, target:, pages:, params:, policy:, **html_attrs)
  @preview = preview
  @target = target
  @pages = pages
  @policy = policy
  @params = params.deep_symbolize_keys
  super(**html_attrs)
end

Instance Attribute Details

#pagesObject (readonly)

Returns the value of attribute pages.



3
4
5
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 3

def pages
  @pages
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 3

def params
  @params
end

#policyObject (readonly)

Returns the value of attribute policy.



3
4
5
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 3

def policy
  @policy
end

#previewObject (readonly)

Returns the value of attribute preview.



3
4
5
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 3

def preview
  @preview
end

#targetObject (readonly)

Returns the value of attribute target.



3
4
5
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 3

def target
  @target
end

Instance Method Details

#app_pathObject



14
15
16
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 14

def app_path
  helpers.lookbook_home_url
end

#embed_codeObject



27
28
29
30
31
32
33
34
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 27

def embed_code
  embed_tag = ("lookbook-embed",
    app: app_path,
    preview: preview_name,
    scenario: target.name,
    **external_embed_params) { "" }
  escape_once embed_tag
end

#embed_urlObject



36
37
38
39
40
41
42
43
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 36

def embed_url
  props = {
    preview: preview_name,
    scenario: target.name,
    **external_embed_params.transform_keys { |k| k.tr("-", "_") }
  }.to_json
  "#{app_path}embed?props=#{CGI.escape(props)}"
end

#external_embed_paramsObject



22
23
24
25
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 22

def external_embed_params
  permitted = params.select { |key, val| key.to_s != "_display" }
  permitted.transform_keys! { |key| "param-#{key}" }
end

#preview_nameObject



18
19
20
# File 'app/components/lookbook/embed_code_dropdown/component.rb', line 18

def preview_name
  preview.preview_class_name
end