Module: Docks::Themes::API::Helpers

Defined in:
lib/docks_theme_api/helpers/ui_helper.rb

Instance Method Summary collapse

Instance Method Details

#docks_component(name, opts = {}, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/docks_theme_api/helpers/ui_helper.rb', line 57

def docks_component(name, opts = {}, &block)
  locals = {}
  locals[name.to_s.split(":").last.to_sym] = locals[:component] = Components.component_for(name).new(self, opts, &block)

  if block.nil?
    render(Components.template_path(name), locals)
  else
    concat render(Components.template_path(name), locals)
  end
end

#docks_demo(demo, locals = {}) ⇒ Object



30
31
32
33
34
# File 'lib/docks_theme_api/helpers/ui_helper.rb', line 30

def docks_demo(demo, locals = {})
  locals[:id] ||= unique_iframe_id
  locals[:demo] = demo
  render(Docks::Templates.demo.path, layout: Docks::Templates.demo.layout, locals: locals)
end

#docks_icon(name, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/docks_theme_api/helpers/ui_helper.rb', line 18

def docks_icon(name, options = {})
  klass = "icon"

  size = options.delete(:size)
  klass << " icon--#{size}" unless size.nil?

  color = options.delete(:color)
  klass << " icon--#{color.to_s.gsub("_", "-")}" unless color.nil?

  "<svg class='#{klass}'><use xlink:href='#icon--#{name}'></use></svg>"
end

#docks_iconsObject



13
14
15
16
# File 'lib/docks_theme_api/helpers/ui_helper.rb', line 13

def docks_icons
  # html safe
  File.read(API.instance.assets.path_for("images/icons.svg"))
end

#unique_iframe_idObject



7
8
9
10
11
# File 'lib/docks_theme_api/helpers/ui_helper.rb', line 7

def unique_iframe_id
  @iframe_id ||= 0
  @iframe_id += 1
  "iframe--#{@iframe_id}"
end