Module: Playbook::PbDocHelper

Defined in:
lib/playbook/pb_doc_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_kitsObject

rubocop:disable Naming/AccessorMethodName



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/playbook/pb_doc_helper.rb', line 47

def get_kits
  menu = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))
  all_kits = []
  menu["kits"].each do |kit|
    kit_name = kit["name"]
    components = kit["components"].map { |c| c["name"] }

    all_kits << if components.size == 1
                  components.first
                else
                  { kit_name => components }
                end
  end
  all_kits
end

#get_kits_pb_websiteObject



63
64
65
66
# File 'lib/playbook/pb_doc_helper.rb', line 63

def get_kits_pb_website
  menu = YAML.load_file(Rails.root.join("config/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, method: get_kits) ⇒ Object

Deal with lists of kits, used in Playbook doc and Externally rubocop:disable Style/StringConcatenation



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

def pb_kits(type: "rails", limit_examples: false, dark_mode: false, method: get_kits)
  display_kits = []
  kits = method
  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:disable Style/OptionalBooleanParameter



70
71
72
73
74
75
# File 'lib/playbook/pb_doc_helper.rb', line 70

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