Module: Playbook::PbDocHelper

Defined in:
app/helpers/playbook/pb_doc_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_kit_description(kit) ⇒ Object



26
27
28
29
# File 'app/helpers/playbook/pb_doc_helper.rb', line 26

def get_kit_description(kit)
  filename = "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{@kit}/docs/_description.md"
  read_file(filename)
end


36
37
38
39
# File 'app/helpers/playbook/pb_doc_helper.rb', line 36

def get_kit_footer(kit)
  filename = "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}/docs/_footer.md"
  read_file(filename)
end

#get_kitsObject



63
64
65
66
# File 'app/helpers/playbook/pb_doc_helper.rb', line 63

def get_kits
  menu = YAML.load_file("#{Playbook::Engine.root}/app/pb_kits/playbook/data/menu.yml")
  return menu['kits']
end

#get_per_sample_descriptions(kit, key) ⇒ Object



31
32
33
34
# File 'app/helpers/playbook/pb_doc_helper.rb', line 31

def get_per_sample_descriptions(kit, key)
  filename = "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}/docs/_#{key}.md"
  read_file(filename)
end

#has_kit_type?(kit, type) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'app/helpers/playbook/pb_doc_helper.rb', line 9

def has_kit_type?(kit, type)
  type ||= "rails"
  if type == "rails"
    Dir["playbook/pb_#{kit}/*.html.erb"].empty?
  elsif type == "react"
    Dir["playbook/pb_#{kit}/*.jsx"].empty?
  end
end


97
98
99
# File 'app/helpers/playbook/pb_doc_helper.rb', line 97

def nav_hash_array(link)
  link.first.last
end


93
94
95
# File 'app/helpers/playbook/pb_doc_helper.rb', line 93

def nav_hash_category(link)
  link.keys.first
end

#pb_category_kits(category_kits: [], type: "rails") ⇒ Object



68
69
70
71
72
73
74
# File 'app/helpers/playbook/pb_doc_helper.rb', line 68

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) ⇒ Object



41
42
43
44
45
46
# File 'app/helpers/playbook/pb_doc_helper.rb', line 41

def pb_kit(kit: "", type: "rails", show_code: true)
  @type = type
  @kit_examples = get_kit_examples(kit, type)
  @show_code = show_code
  render partial: "config/kit_example"
end

#pb_kit_api(kit) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'app/helpers/playbook/pb_doc_helper.rb', line 83

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") ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/playbook/pb_doc_helper.rb', line 48

def pb_kits(type: "rails")
  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)
      end
    else
      display_kits << render_pb_doc_kit(kit, type, false)
    end
  end
  raw("<div class='pb--docItem'>" + display_kits.join("</div><div class='pb--docItem'>") + "</div>")
end

#read_file(filename) ⇒ Object



18
19
20
21
22
23
24
# File 'app/helpers/playbook/pb_doc_helper.rb', line 18

def read_file(filename)
  if File.file?(filename)
    File.read(filename)
  else
    ""
  end
end

#render_pb_doc_kit(kit, type, code = true) ⇒ Object



76
77
78
79
80
81
# File 'app/helpers/playbook/pb_doc_helper.rb', line 76

def render_pb_doc_kit(kit, type, code = true)
  title = render_clickable_title(kit)
  ui = raw("<div class='pb--docItem-ui'>
      #{pb_kit(kit: kit, type: type, show_code: code)}</div>")
  title + ui
end