Module: Playbook::PbDocHelper

Defined in:
lib/playbook/pb_doc_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_kitsObject

rubocop:disable Naming/AccessorMethodName



45
46
47
48
# File 'lib/playbook/pb_doc_helper.rb', line 45

def get_kits
  menu = YAML.load_file(Playbook::Engine.root.join("app/pb_kits/playbook/data/menu.yml"))
  menu["kits"]
end


24
25
26
# File 'lib/playbook/pb_doc_helper.rb', line 24

def nav_hash_array(link)
  link.first.last
end

#pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false, dark_mode: false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/playbook/pb_doc_helper.rb', line 9

def pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false, dark_mode: false)
  examples = pb_doc_kit_examples(kit, type)
  examples = examples.first(1) if limit_examples
  examples.map do |example|
    pb_rails "docs/kit_example", props: {
      kit: kit,
      example_title: example.values.first,
      example_key: example.keys.first,
      show_code: show_code,
      type: type,
      dark: dark_mode,
    }
  end.join.yield_self(&method(:raw))
end

#pb_kit_title(title) ⇒ Object



5
6
7
# File 'lib/playbook/pb_doc_helper.rb', line 5

def pb_kit_title(title)
  title.remove("pb_").titleize.tr("_", " ")
end

#pb_kits(type: "rails", limit_examples: false, dark_mode: false) ⇒ Object

Deal with lists of kits, used in Playbook doc and Externally



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/playbook/pb_doc_helper.rb', line 29

def pb_kits(type: "rails", limit_examples: false, dark_mode: false)
  display_kits = []
  kits = get_kits
  kits.each do |kit|
    if kit.is_a?(Hash)
      nav_hash_array(kit).each do |sub_kit|
        display_kits << render_pb_doc_kit(sub_kit, type, limit_examples, false, dark_mode)
      end
    else
      display_kits << render_pb_doc_kit(kit, type, limit_examples, false, dark_mode)
    end
  end
  raw("<div class='pb--docItem'>" + display_kits.join("</div><div class='pb--docItem'>") + "</div>")
end

#render_pb_doc_kit(kit, type, limit_examples, code = true, dark_mode = false) ⇒ Object

rubocop:enable Naming/AccessorMethodName



51
52
53
54
55
56
# File 'lib/playbook/pb_doc_helper.rb', line 51

def render_pb_doc_kit(kit, type, limit_examples, code = true, dark_mode = false)
  title = pb_doc_render_clickable_title(kit, type)
  ui = raw("<div class='pb--docItem-ui'>
      #{pb_kit(kit: kit, type: type, show_code: code, limit_examples: limit_examples, dark_mode: dark_mode)}</div>")
  title + ui
end