Class: Playbook::PbDocs::KitApi
- Defined in:
- app/pb_kits/playbook/pb_docs/kit_api.rb
Instance Attribute Summary
Attributes included from Playbook::Props
Instance Method Summary collapse
- #global_prop_data ⇒ Object
- #kit_global_props ⇒ Object
- #kit_local_props ⇒ Object
- #kit_props ⇒ Object
- #local_prop_data ⇒ Object
- #padding_margin_values ⇒ Object
Methods inherited from KitBase
Methods included from Playbook::Position
included, #position_options, #position_values
Methods included from Order
included, #order_options, #order_props, #order_values
Methods included from FlexShrink
#flex_shrink_options, #flex_shrink_props, #flex_shrink_values, included
Methods included from FlexGrow
#flex_grow_options, #flex_grow_props, #flex_grow_values, included
Methods included from Flex
#flex_options, #flex_props, #flex_values, included
Methods included from AlignSelf
#align_self_options, #align_self_props, #align_self_values, included
Methods included from AlignContent
#align_content_options, #align_content_props, #align_content_values, included
Methods included from AlignItems
#align_items_options, #align_items_props, #align_items_values, included
Methods included from JustifySelf
included, #justify_self_options, #justify_self_props, #justify_self_values
Methods included from JustifyContent
included, #justify_content_options, #justify_content_props, #justify_content_values
Methods included from FlexWrap
#flex_wrap_options, #flex_wrap_props, #flex_wrap_values, included
Methods included from FlexDirection
#flex_direction_options, #flex_direction_props, #flex_direction_values, included
Methods included from Cursor
#cursor_options, #cursor_props, #cursor_values, included
Methods included from Display
#display_options, #display_props, #display_size_values, #display_values, included
Methods included from LineHeight
included, #line_height_options, #line_height_props, #line_height_values
Methods included from Shadow
included, #shadow_options, #shadow_props, #shadow_values
Methods included from NumberSpacing
included, #number_spacing_options, #number_spacing_values
Methods included from ZIndex
included, #z_index_options, #z_index_values
Methods included from Spacing
included, #max_width_options, #max_width_props, #max_width_values, #spacing_options, #spacing_props, #spacing_values
Methods included from Classnames
#generate_classname, #generate_classname_without_spacing, included
Methods included from Playbook::Props
Methods included from Playbook::PbKitHelper
Methods included from Playbook::PbFormsHelper
Instance Method Details
#global_prop_data ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'app/pb_kits/playbook/pb_docs/kit_api.rb', line 127 def global_prop_data global_props = {} kit_global_props.each do |key, value| type = value[:type] values = value[:values] global_props[key] = { "type": type, "values": values } end global_props end |
#kit_global_props ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/pb_kits/playbook/pb_docs/kit_api.rb', line 33 def kit_global_props global_props = {} global_prop_names = [] global_prop_values = {} global_props_with_values = {} global_props_without_values = [] parent_child_object = {} updated_global_props_with_values = {} # extracts the modules from kit_base.rb, which is where we import all the global props that we inject into every rails kit pb_module = Playbook::KitBase.included_modules.select { |mod| mod.to_s.include?("Playbook::") } # loops through the kits and extracts each prop with its values and pushes that to the global_props hash kit_props.each do |key, value| value.kit == Playbook::KitBase && global_props[key.to_sym] = value end # loops through the global_props and extracts the name of each prop and pushes that to global_prop_names array global_props.each do |name, _values| global_prop_names.push(name) end # Loops through each module in pb_module and searches for methods that end in _values, as these methods hold the values for each prop # we then save the values and type and push that to the values hash as a key value pair pb_module.each do |mod| mod.instance_methods.each do |method_name| next unless method_name.to_s.end_with?("_values") value = send(method_name) type = value.class global_prop_values[method_name.to_s.chomp("_values").to_sym] = { "type": type, "values": value } end end # loops through the global_prop_names array # then loops through the global_prop_values hash and extracts the values that have the same name found in global_prop_names # this loop helps ensure only global props values are actually extracted, as there could be other methods that end in _values in the modules we are iterating over # these verified global props with values are then pushed to the global_props_with_values hash global_prop_names.each do |name, _prop| global_prop_values.each do |key, value| global_props_with_values[key] = value if key == name end end # now we grab all the global_prop_names that do not have a matching key in global_prop_values. # This gives us any global prop that did not have any predefined value. like classname and dark global_props_without_values = global_prop_names - global_prop_values.keys # Loops through each module in pb_module and searches for methods that end in _options, as these methods hold all the props in the module # save the prop names prop values and and parent module name to parent_child_object hash # this is a comprehensive list of all parent module and children props for edge cases like spacing.rb, that is not named after the props it represents pb_module.each do |mod| mod.instance_methods.each do |method_name| next unless method_name.to_s.end_with?("_options") props = send(method_name) parent = mod.to_s.split("::").last values = send("#{parent.underscore}_values") parent_child_object[parent] = { "props": props, "values": values } end end # loops through each object in parent_child_object and extracts its children (props and values) # loops through each child and extracts the individual props # Checks if the props match any of the props in global_props_without_values # if it does, then we push that prop to global_props_with_values hash # This extracts the props in the spacing.rb file and any file that is not named after the props it represents parent_child_object.each do |_parent, children| children.each do |_child, props| props.each do |prop, _value| type = children[:values].class values = children[:values] global_props_with_values[prop] = { "type": type, "values": values } if global_props_without_values.include?(prop) end end end # loop through the global_props hash and the global_props_with_values hash. # extract the props from global_props that are not found in global_props_with_values into updated_global_props_with_values # This is the last piece that grabs the global props that did not have values at all, like classname and dark, and adds it to our hash global_props.each do |prop, value| unless global_props_with_values.include?(prop) type = value.class.to_s.split("::").last updated_global_props_with_values[prop] = { "type": type } end end # Merge updated_global_props_with_values into global_props_with_values # global_props_with_values will now hold all the global props thier values and type global_props_with_values.merge!(updated_global_props_with_values) global_props_with_values end |
#kit_local_props ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/pb_kits/playbook/pb_docs/kit_api.rb', line 8 def kit_local_props local = [] kit_props.each do |key, value| value.kit != Playbook::KitBase && local.push({ key: key, value: value }) end local end |
#kit_props ⇒ Object
138 139 140 |
# File 'app/pb_kits/playbook/pb_docs/kit_api.rb', line 138 def kit_props kit_class.props end |
#local_prop_data ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/pb_kits/playbook/pb_docs/kit_api.rb', line 20 def local_prop_data local_props = {} kit_local_props.each do |key, _value| name = key[:value].instance_variable_get(:@name) type = key[:value].class.to_s.split("::").last default = key[:value].instance_variable_get(:@default) values = key[:value].instance_variable_get(:@values) local_props[name.to_sym] = { "type": type, "default": default, "values": values } end local_props end |
#padding_margin_values ⇒ Object
16 17 18 |
# File 'app/pb_kits/playbook/pb_docs/kit_api.rb', line 16 def padding_margin_values %w[none xxs xs sm md lg xl] end |