# 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 Externally# rubocop:disable Style/StringConcatenationdefpb_kits(type: "rails",limit_examples: false,dark_mode: false,method: get_kits)display_kits=[]kits=methodkits.eachdo|kit|ifkit.is_a?(Hash)nav_hash_array(kit).eachdo|sub_kit|display_kits<<render_pb_doc_kit(sub_kit,type,limit_examples,false,dark_mode)endelsedisplay_kits<<render_pb_doc_kit(kit,type,limit_examples,false,dark_mode)endendraw("<div class='pb--docItem'>"+display_kits.join("</div><div class='pb--docItem'>")+"</div>")end# rubocop:enable Style/StringConcatenation# rubocop:disable Naming/AccessorMethodNamedefget_kitsmenu=ActiveSupport::ConfigurationFile.parse(Playbook::Engine.root.join("dist/menu.yml"))all_kits=[]menu["kits"].eachdo|kit|kit_name=kit["name"]components=kit["components"].map{|c|c["name"]}all_kits<<ifcomponents.size==1components.firstelse{kit_name=>components}endendall_kitsenddefget_kits_pb_websitemenu=ActiveSupport::ConfigurationFile.parse(Rails.root.join("config/menu.yml"))menu["kits"]end# rubocop:enable Naming/AccessorMethodName# rubocop:disable Style/OptionalBooleanParameterdefrender_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+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)ActiveSupport::ConfigurationFile.parse(example_file).transform_keys(&:to_sym).dig(:examples,type)||[]else[]endenddefpb_doc_render_clickable_title(kit,type)url="#"beginurl=casetypewhen"react"kit_show_reacts_path(kit)when"swift"kit_show_swift_path(kit)elsekit_show_path(kit)end# FIXME: this is here because this helper generates a link for playbook website,# but shouldn't do anything when used elsewhererescueputs"Kit Path Not Avaliable"endrenderinline: "<a href='#{url}'>#{pb_rails(:title,props: {text: pb_kit_title(kit),tag: 'h3',size: 2})}</a>"endendend