Module: Playbook::PbDocHelper
- Defined in:
- lib/playbook/pb_doc_helper.rb
Instance Method Summary collapse
-
#get_kits ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #get_kits_pb_website ⇒ Object
- #nav_hash_array(link) ⇒ Object
- #pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false, dark_mode: false) ⇒ Object
- #pb_kit_title(title) ⇒ Object
-
#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.
-
#render_pb_doc_kit(kit, type, limit_examples, code = true, dark_mode = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
Instance Method Details
#get_kits ⇒ Object
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 = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml")) all_kits = [] ["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_website ⇒ Object
63 64 65 66 |
# File 'lib/playbook/pb_doc_helper.rb', line 63 def get_kits_pb_website = YAML.load_file(Rails.root.join("config/menu.yml")) ["kits"] end |
#nav_hash_array(link) ⇒ Object
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 |