Module: Playbook::PbDocHelper
- Defined in:
- lib/playbook/pb_doc_helper.rb
Instance Method Summary collapse
- #aggregate_kits ⇒ Object
- #get_kits(type = "rails") ⇒ 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) ⇒ Object
Deal with lists of kits, used in Playbook doc and Externally.
- #render_markdown(text) ⇒ Object
-
#render_pb_doc_kit(kit_name, type, limit_examples, code = true, dark_mode = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
Instance Method Details
#aggregate_kits ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/playbook/pb_doc_helper.rb', line 51 def aggregate_kits all_kits = [] YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))["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(type = "rails") ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/playbook/pb_doc_helper.rb', line 42 def get_kits(type = "rails") kits = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml")) || [] # Filter kits that have at least one component compatible with the type kits["kits"].select do |kit| kit["components"].any? { |component| component["platforms"].include?(type) } end end |
#nav_hash_array(link) ⇒ Object
28 29 30 |
# File 'lib/playbook/pb_doc_helper.rb', line 28 def nav_hash_array(link) link.first.last end |
#pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false, dark_mode: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/playbook/pb_doc_helper.rb', line 13 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
9 10 11 |
# File 'lib/playbook/pb_doc_helper.rb', line 9 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
33 34 35 36 37 38 39 40 |
# File 'lib/playbook/pb_doc_helper.rb', line 33 def pb_kits(type: "rails", limit_examples: false, dark_mode: false) kits = get_kits(type) # Iterate through the filtered kits and render them kits.map do |kit| render_pb_doc_kit(kit["name"], type, limit_examples, true, dark_mode) end.join.html_safe end |
#render_markdown(text) ⇒ Object
5 6 7 |
# File 'lib/playbook/pb_doc_helper.rb', line 5 def render_markdown(text) PlaybookWebsite::Markdown::Helper.markdown(text) end |
#render_pb_doc_kit(kit_name, type, limit_examples, code = true, dark_mode = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/playbook/pb_doc_helper.rb', line 69 def render_pb_doc_kit(kit_name, type, limit_examples, code = true, dark_mode = false) parent_kit = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))["kits"].find { |kit| kit["name"] == kit_name } # Initialize component_content as an empty string component_content = "" # Check if parent_kit is not nil # Filter components based on the specified type components = parent_kit["components"].select { |component| component["platforms"].include?(type) } # If it's a parent with components, accumulate the UI content for child components if components.any? component_content = components.map do |component| component_name = component["name"] title = pb_doc_render_clickable_title(component_name, type) # Use component_name for the title # Render the component UI content with the same styles/tags as the parent component_ui = raw("<div class='pb--docItem-ui'> #{pb_kit(kit: component_name, type: type, show_code: code, limit_examples: limit_examples, dark_mode: dark_mode)} </div>") # Combine the component name and component UI content "#{title}#{component_ui}" end.join.to_s end # Return the component_content component_content.to_s end |