Module: Jigsaw::GridConfigurable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Layout, LayoutTemplate
- Defined in:
- app/models/concerns/jigsaw/grid_configurable.rb
Constant Summary collapse
- SCHEMA_PATH =
File.("../../jigsaw/schemas/layout_config.json", __dir__)
- SCHEMA =
JSONSchemer.schema(Pathname.new(SCHEMA_PATH))
Instance Method Summary collapse
- #colGap=(val) ⇒ Object
- #config=(val) ⇒ Object
- #rowGap=(val) ⇒ Object
-
#skip_config_validation? ⇒ Boolean
Override in models that support template linking.
- #sync_slots ⇒ Object
- #unique_area_names ⇒ Object
Instance Method Details
#colGap=(val) ⇒ Object
39 40 41 |
# File 'app/models/concerns/jigsaw/grid_configurable.rb', line 39 def colGap=(val) super(val.to_i) end |
#config=(val) ⇒ Object
30 31 32 33 |
# File 'app/models/concerns/jigsaw/grid_configurable.rb', line 30 def config=(val) val = JSON.parse(val) if val.is_a?(String) super(val) end |
#rowGap=(val) ⇒ Object
35 36 37 |
# File 'app/models/concerns/jigsaw/grid_configurable.rb', line 35 def rowGap=(val) super(val.to_i) end |
#skip_config_validation? ⇒ Boolean
Override in models that support template linking
26 27 28 |
# File 'app/models/concerns/jigsaw/grid_configurable.rb', line 26 def skip_config_validation? false end |
#sync_slots ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/concerns/jigsaw/grid_configurable.rb', line 51 def sync_slots if config["areas"].is_a?(Array) current_names = unique_area_names existing = slots.reload.index_by(&:area_name) obsolete = existing.reject { |name, _| current_names.include?(name) } obsolete.values.each(&:destroy!) obsolete.keys.each { |name| existing.delete(name) } current_names.each do |name| unless existing.key?(name) existing[name] = slots.create!(area_name: name) end end current_names.each_with_index do |name, position| slot = existing[name] slot.update_column(:position, position) if slot.position != position end end end |
#unique_area_names ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/concerns/jigsaw/grid_configurable.rb', line 43 def unique_area_names if config["areas"].is_a?(Array) config["areas"].flatten.uniq.reject { |s| s == "." } else [] end end |