Class: Ecoportal::API::V2::Page::Component::ImagesField
- Inherits:
-
Ecoportal::API::V2::Page::Component
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Ecoportal::API::V2::Page::Component
- Ecoportal::API::V2::Page::Component::ImagesField
- Defined in:
- lib/ecoportal/api/v2/page/component/images_field.rb
Constant Summary
Constants included from Common::Content::StringDigest
Common::Content::StringDigest::MAX_HASH_LABEL
Constants included from Common::Content::DoubleModel::Diffable
Common::Content::DoubleModel::Diffable::DIFF_CLASS
Constants included from Common::Content::DoubleModel::Base
Common::Content::DoubleModel::Base::NOT_USED
Instance Attribute Summary
Attributes included from Common::Content::DoubleModel::Parented
Class Method Summary collapse
Instance Method Summary collapse
- #add_image(upload_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED) ⇒ Object
-
#configure(*conf) ⇒ Object
Quick config helper.
- #empty? ⇒ Boolean
- #ordered_images ⇒ Object
- #to_s ⇒ Object
Methods inherited from Ecoportal::API::V2::Page::Component
#attached?, #bindings, #bindings?, #delete!, #forces, get_class, #indexable_label, #move, #multi_section?, #ooze, #ref, #ref_backend, #replace, #replace_bindings, #section, #unattach!
Methods included from Common::Content::StringDigest
Methods inherited from Common::Content::DoubleModel
Methods included from Common::Content::DoubleModel::Diffable
Methods included from Common::Content::Includer
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel
Class Method Details
.new_doc ⇒ Object
8 9 10 11 12 |
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 8 def new_doc { 'layout' => 'third' } end |
Instance Method Details
#add_image(upload_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 23 def add_image(upload_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED) image_doc = images.items_class.new_doc images.upsert!(image_doc, pos: pos, before: before, after: after) do |image| image.upload_id = upload_id if (prev = previous_image(image)) image.weight = prev.weight end yield(image) if block_given? fix_image_positions! end end |
#configure(*conf) ⇒ Object
Quick config helper
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 59 def configure(*conf) conf.each_with_object([]) do |cnf, unused| case cnf when :strech self.strech = true when :popup self.no_popup = false when :layout_button self. = false when Hash supported = %i[layout_button layout] unless (rest = hash_except!(cnf.dup, *supported)).empty? unused.push(rest) end self. = !cnf[:layout_button] if cnf.key?(:layout_button) configure_layout(cnf[:layout]) if cnf.key?(:layout) else unused.push(cnf) end end.then do |unused| super(*unused) end end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 19 def empty? images.empty? end |
#ordered_images ⇒ Object
39 40 41 42 43 |
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 39 def ordered_images images.sort_by.with_index do |image, index| [image.weight, index] end end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 45 def to_s images.count end |