module Ecoportal module API class V2 class Page class Component class ImagesField < Page::Component class << self def new_doc { "layout" => "third" } end end passthrough :layout passboolean :strech, :no_popup, :hide_options embeds_many :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight # Quick config helper # @param conf [Symbol, Array] # - `:strech` to make the image fit the full size of the image field # - `:popup` to set to enable disable poupup on `click` # - `:layout_button` to offer layout options to user # - `:layout` with the following available values # - `:three_crop` to specify _3 across_ by cutting the image to equalize size # - `:three` to specify _3 across_ # - `:two` to specify _2 across_ # - `:one` to specify _Full width (1 Across)_ 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.hide_options = false when Hash supported = [:layout_button, :layout] unless (rest = hash_except(cnf.dup, *supported)).empty? unused.push(rest) end if cnf.key?(:layout_button) then self.hide_options = !cnf[:layout_button] end if cnf.key?(:layout) then configure_layour cnf[:layout] end else unused.push(cnf) end end.yield_self do |unused| super(*unused) end end private def configure_layout(value) case value when :three self.layout = "third" when :two self.layout = "half" when :one self.layout = "fill" when :three_crop self.layout = "third_crop" else # Unsupported end end end end end end end end require 'ecoportal/api/v2/page/component/image'