Module: Playbook::PbDocHelper

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

Instance Method Summary collapse

Instance Method Details

#all_active(controller_name, action_name) ⇒ Object



135
136
137
# File 'app/helpers/playbook/pb_doc_helper.rb', line 135

def all_active(controller_name, action_name)
  (controller_name == "pages" && action_name == "kits")
end


107
108
109
# File 'app/helpers/playbook/pb_doc_helper.rb', line 107

def all_link(type)
  type == "react" ? kits_path("", type: "react") : kits_path
end

#category_active(category, link) ⇒ Object



139
140
141
# File 'app/helpers/playbook/pb_doc_helper.rb', line 139

def category_active(category, link)
  (!category.nil? && category == nav_hash_category(link))
end


111
112
113
114
115
116
117
# File 'app/helpers/playbook/pb_doc_helper.rb', line 111

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



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

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


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

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

#get_kitsObject



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

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

#get_per_sample_descriptions(kit, key) ⇒ Object



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

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
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



143
144
145
# File 'app/helpers/playbook/pb_doc_helper.rb', line 143

def kit_active(kit, link)
  (!kit.nil? && kit == link)
end


127
128
129
130
131
132
133
# File 'app/helpers/playbook/pb_doc_helper.rb', line 127

def kit_link(type, link)
  if type == "react"
    kit_show_reacts_path(link)
  else
    kit_show_path(link)
  end
end

#kit_path(kit) ⇒ Object



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

def kit_path(kit)
  "#{Playbook::Engine.root}/app/pb_kits/playbook/pb_#{kit}"
end


103
104
105
# File 'app/helpers/playbook/pb_doc_helper.rb', line 103

def nav_hash_array(link)
  link.first.last
end


99
100
101
# File 'app/helpers/playbook/pb_doc_helper.rb', line 99

def nav_hash_category(link)
  link.keys.first
end

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



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

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



47
48
49
50
51
52
# File 'app/helpers/playbook/pb_doc_helper.rb', line 47

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



89
90
91
92
93
94
95
96
97
# File 'app/helpers/playbook/pb_doc_helper.rb', line 89

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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/playbook/pb_doc_helper.rb', line 54

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



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



82
83
84
85
86
87
# File 'app/helpers/playbook/pb_doc_helper.rb', line 82

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

#sub_category_active(kit, link) ⇒ Object



147
148
149
# File 'app/helpers/playbook/pb_doc_helper.rb', line 147

def sub_category_active(kit, link)
  (!kit.nil? && @kit == link)
end


119
120
121
122
123
124
125
# File 'app/helpers/playbook/pb_doc_helper.rb', line 119

def sub_category_link(type, link)
  if type == "react"
    kit_show_reacts_path(link)
  else
    kit_show_path(link)
  end
end