Module: Playbook::PbDocHelper
- Defined in:
- app/helpers/playbook/pb_doc_helper.rb
Instance Method Summary collapse
- #all_active(controller_name, action_name) ⇒ Object
- #all_link(type) ⇒ Object
- #category_active(category, link) ⇒ Object
- #category_link(type, link) ⇒ Object
- #get_kit_description(kit) ⇒ Object
- #get_kit_footer(kit) ⇒ Object
- #get_kits ⇒ Object
- #get_per_sample_descriptions(kit, key) ⇒ Object
- #get_samples(kit) ⇒ Object
- #has_kit_type?(kit, type) ⇒ Boolean
- #kit_active(kit, link) ⇒ Object
- #kit_link(type, link) ⇒ Object
- #kit_path(kit) ⇒ Object
- #nav_hash_array(link) ⇒ Object
- #nav_hash_category(link) ⇒ Object
- #pb_category_kits(category_kits: [], type: "rails") ⇒ Object
- #pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false) ⇒ Object
- #pb_kit_api(kit) ⇒ Object
- #pb_kit_title(title) ⇒ Object
- #pb_kits(type: "rails", limit_examples: false) ⇒ Object
- #read_file(filename) ⇒ Object
- #render_pb_doc_kit(kit, type, code = true, limit_examples) ⇒ Object
- #sub_category_active(kit, link) ⇒ Object
- #sub_category_link(type, link) ⇒ Object
Instance Method Details
#all_active(controller_name, action_name) ⇒ Object
154 155 156 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 154 def all_active(controller_name, action_name) (controller_name == "pages" && action_name == "kits") end |
#all_link(type) ⇒ Object
126 127 128 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 126 def all_link(type) type == "react" ? kits_path("", type: "react") : kits_path end |
#category_active(category, link) ⇒ Object
158 159 160 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 158 def category_active(category, link) (!category.nil? && category == nav_hash_category(link)) end |
#category_link(type, link) ⇒ Object
130 131 132 133 134 135 136 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 130 def category_link(type, link) if type == "react" kit_category_show_path(nav_hash_category(link), type: "react") else kit_category_show_path(nav_hash_category(link), type: "rails") end end |
#get_kit_description(kit) ⇒ Object
50 51 52 53 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 50 def get_kit_description(kit) filename = "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}/docs/_description.md" read_file(filename) end |
#get_kit_footer(kit) ⇒ Object
60 61 62 63 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 60 def (kit) filename = "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}/docs/_footer.md" read_file(filename) end |
#get_kits ⇒ Object
88 89 90 91 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 88 def get_kits = YAML.load_file("#{Playbook::Engine.root}/app/pb_kits/playbook/data/menu.yml") ["kits"] end |
#get_per_sample_descriptions(kit, key) ⇒ Object
55 56 57 58 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 55 def get_per_sample_descriptions(kit, key) filename = "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}/docs/_#{key}.md" read_file(filename) end |
#get_samples(kit) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 28 def get_samples(kit) sample_yaml = YAML.load_file("#{Playbook::Engine.root}/app/pb_kits/playbook/data/samples.yml") all_samples = [] sample_yaml.each do |_category, sample| all_samples.push(sample) end output = "" samples_using_kit = [] all_samples[0].each do |sample| filepath = "#{Playbook::Engine.root}/app/views/playbook/samples/#{sample}/index.html.erb" output = `grep -l 'pb_rails(\"#{kit}' #{filepath}` samples_using_kit.push(sample) if output.chomp == filepath end samples_using_kit end |
#has_kit_type?(kit, type) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 9 def has_kit_type?(kit, type) type ||= "rails" if type == "rails" erbfiles = File.join("**", "*.erb") Dir.glob(erbfiles, base: "#{kit_path(kit)}/docs").present? elsif type == "react" jsxfiles = File.join("**", "*.jsx") Dir.glob(jsxfiles, base: "#{kit_path(kit)}/docs").present? end end |
#kit_active(kit, link) ⇒ Object
162 163 164 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 162 def kit_active(kit, link) (!kit.nil? && kit == link) end |
#kit_link(type, link) ⇒ Object
146 147 148 149 150 151 152 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 146 def kit_link(type, link) if type == "react" kit_show_reacts_path(link) else kit_show_path(link) end end |
#kit_path(kit) ⇒ Object
46 47 48 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 46 def kit_path(kit) "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}" end |
#nav_hash_array(link) ⇒ Object
122 123 124 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 122 def nav_hash_array(link) link.first.last end |
#nav_hash_category(link) ⇒ Object
118 119 120 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 118 def nav_hash_category(link) link.keys.first end |
#pb_category_kits(category_kits: [], type: "rails") ⇒ Object
93 94 95 96 97 98 99 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 93 def pb_category_kits(category_kits: [], type: "rails") display_kits = [] category_kits.each do |kit| display_kits << render_pb_doc_kit(kit, type, false) end raw("<div class='pb--docItem'>" + display_kits.join("</div><div class='pb--docItem'>") + "</div>") end |
#pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false) ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 65 def pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false) @type = type @kit_examples = get_kit_examples(kit, type) @limit_examples = limit_examples @show_code = show_code render partial: "config/kit_example" end |
#pb_kit_api(kit) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 108 def pb_kit_api(kit) kit_class_obj = get_class_name(kit.to_s) @kit_api = if kit_class_obj < Playbook::PbKit::Base kit_class_obj.instance_method(:initialize).parameters.map(&:last) else kit_class_obj.props.keys end render partial: "playbook/config/pb_kit_api" end |
#pb_kit_title(title) ⇒ Object
5 6 7 |
# File 'app/helpers/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) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 73 def pb_kits(type: "rails", limit_examples: false) display_kits = [] kits = get_kits 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, false, limit_examples) end else display_kits << render_pb_doc_kit(kit, type, false, limit_examples) end end raw("<div class='pb--docItem'>" + display_kits.join("</div><div class='pb--docItem'>") + "</div>") end |
#read_file(filename) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 20 def read_file(filename) if File.file?(filename) File.read(filename) else "" end end |
#render_pb_doc_kit(kit, type, code = true, limit_examples) ⇒ Object
101 102 103 104 105 106 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 101 def render_pb_doc_kit(kit, type, code = true, limit_examples) title = 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)}</div>") title + ui end |
#sub_category_active(kit, link) ⇒ Object
166 167 168 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 166 def sub_category_active(kit, link) (!kit.nil? && @kit == link) end |
#sub_category_link(type, link) ⇒ Object
138 139 140 141 142 143 144 |
# File 'app/helpers/playbook/pb_doc_helper.rb', line 138 def sub_category_link(type, link) if type == "react" kit_show_reacts_path(link) else kit_show_path(link) end end |