# frozen_string_literal: truemodulePlaybookmodulePbDocHelperdefpb_kit_title(title)title.remove("pb_").titleize.tr("_"," ")enddefpb_kit(kit: "",type: "rails",show_code: true,limit_examples: false,dark_mode: false)examples=pb_doc_kit_examples(kit,type)examples=examples.first(1)iflimit_examplesexamples.mapdo|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))enddefnav_hash_array(link)link.first.lastend# Deal with lists of kits, used in Playbook doc and Externallydefpb_kits(type: "rails",limit_examples: false,dark_mode: false)kits=get_kits(type)# Initialize an empty string to store the rendered HTMLrendered_html=""# Iterate through the filtered kits and render their child componentskits.eachdo|kit|kit["components"].eachdo|component|# Check if the component is compatible with the specified typerendered_html+=render_pb_doc_kit(component["name"],type,limit_examples,true,dark_mode)ifcomponent["platforms"].include?(type)endend# Return the rendered HTML as safe HTMLrendered_html.html_safeenddefget_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 typekits["kits"].selectdo|kit|kit["components"].any?{|component|component["platforms"].include?(type)}endenddefaggregate_kitsall_kits=[]YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))["kits"].eachdo|kit|kit_name=kit["name"]components=kit["components"].map{|c|c["name"]}all_kits<<ifcomponents.size==1components.firstelse{kit_name=>components}endendall_kitsend# rubocop:disable Style/OptionalBooleanParameterdefrender_pb_doc_kit(kit_name,type,limit_examples,code=true,dark_mode=false)title=pb_doc_render_clickable_title(kit_name,type)ui=raw("<div class='pb--docItem-ui'>
#{pb_kit(kit: kit_name,type: type,show_code: code,limit_examples: limit_examples,dark_mode: dark_mode)}</div>")title+uiend# rubocop:enable Style/OptionalBooleanParameterprivatedefpb_doc_kit_path(kit,*args)Playbook.kit_path(kit,"docs",*args)enddefpb_doc_kit_examples(kit,type)example_file=pb_doc_kit_path(kit,"example.yml")ifFile.exist?(example_file)examples_list=YAML.load_file(example_file).inject({}){|item,(k,v)|item[k.to_sym]=v;item}examples_list.dig(:examples,type)||[]else[]endend# Modify the method to accept kit_namedefpb_doc_render_clickable_title(kit_name,type)url="#"beginurl=casetypewhen"react"kit_show_reacts_path(kit_name)# Use kit_name instead of kitwhen"swift"kit_show_swift_path(kit_name)# Use kit_name instead of kitelsekit_show_path(kit_name)# Use kit_name instead of kitend# FIXME: this is here because this helper generates a link for playbook website,# but shouldn't do anything when used elsewhererescueputs"Kit Path Not Available"endrenderinline: "<a href='#{url}'>#{pb_rails(:title,props: {text: pb_kit_title(kit_name),tag: 'h3',size: 2})}</a>"endendend