shimmer 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/shimmer/form/builder.rb +6 -4
- data/lib/shimmer/form/field.rb +3 -0
- data/lib/shimmer/form/radio_field.rb +9 -1
- data/lib/shimmer/form/radios_field.rb +13 -0
- data/lib/shimmer/utils/file_helper.rb +12 -4
- data/lib/shimmer/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 98504a2ff4a7a068681ac784ca6efc00e3d1ec91aabb0f4a5599a12e87f8decf
         | 
| 4 | 
            +
              data.tar.gz: '08a7c167d5fa3611f925194591c1697b32c8fc1d572d54ea4f642567eadbf3e5'
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a0adc008b3118a00a7ddcccb6d6541a50163cde552250871d33ed047a6299d7edcf9375f138eedb9240850bb47fd28e7913171f9df0dc89eabb5a11dab5de414
         | 
| 7 | 
            +
              data.tar.gz: 2c99878dfcaa144dcabb5a12920caf3626c3b15e86314c94aa38da5bc832bc4b194ed5c1e53396bcbbb679c23bbd6d590d339a260a104ac7cb2722fd72b55e2c
         | 
    
        data/lib/shimmer/form/builder.rb
    CHANGED
    
    | @@ -13,7 +13,7 @@ module Shimmer | |
| 13 13 | 
             
                    end
         | 
| 14 14 | 
             
                  end
         | 
| 15 15 |  | 
| 16 | 
            -
                  def input(method, as: guess_type(method), wrapper_options: {}, description: nil, **options)
         | 
| 16 | 
            +
                  def input(method, as: guess_type(method), wrapper_options: {}, description: nil, label_method: nil, **options)
         | 
| 17 17 | 
             
                    as ||= guess_type(method)
         | 
| 18 18 | 
             
                    options[:class] ||= "input__input"
         | 
| 19 19 | 
             
                    collection = options.delete :collection
         | 
| @@ -29,8 +29,10 @@ module Shimmer | |
| 29 29 | 
             
                    input_class = self.class.input_registry[as]
         | 
| 30 30 | 
             
                    raise "Unknown type #{as}" unless input_class
         | 
| 31 31 | 
             
                    input = input_class.new(builder: self, method: method, options: options, id_method: id_method, collection: collection, name_method: name_method)
         | 
| 32 | 
            +
                    input.prepare
         | 
| 32 33 | 
             
                    wrapper_options.reverse_merge! input.wrapper_options
         | 
| 33 | 
            -
                     | 
| 34 | 
            +
                    label_method ||= wrapper_options.delete(:label_method)
         | 
| 35 | 
            +
                    wrap method: method, content: input.render, classes: classes + ["input--#{as}"], label: options[:label], extra: extra, description: description, options: wrapper_options, label_method: label_method
         | 
| 34 36 | 
             
                  end
         | 
| 35 37 |  | 
| 36 38 | 
             
                  private
         | 
| @@ -65,12 +67,12 @@ module Shimmer | |
| 65 67 | 
             
                    object.class.types.keys if object.class.respond_to?(method.to_s.pluralize)
         | 
| 66 68 | 
             
                  end
         | 
| 67 69 |  | 
| 68 | 
            -
                  def wrap(method:, content:, classes:, label:, data: nil, extra: nil, description: nil, options: {})
         | 
| 70 | 
            +
                  def wrap(method:, content:, classes:, label:, data: nil, extra: nil, description: nil, options: {}, label_method: nil)
         | 
| 69 71 | 
             
                    if object&.errors&.[](method)&.any?
         | 
| 70 72 | 
             
                      classes << "input--error"
         | 
| 71 73 | 
             
                      errors = safe_join(object.errors[method].map { |e| content_tag :div, e, class: "input__error" })
         | 
| 72 74 | 
             
                    end
         | 
| 73 | 
            -
                    label = label == false ? nil : self.label(method, label, class: "input__label")
         | 
| 75 | 
            +
                    label = label == false ? nil : self.label(label_method || method, label, class: "input__label")
         | 
| 74 76 | 
             
                    description = description.presence ? content_tag(:div, description, class: "input__description") : nil
         | 
| 75 77 | 
             
                    content_tag(:div, safe_join([label, content, description, errors, extra].compact), class: ["input"] + classes, **options)
         | 
| 76 78 | 
             
                  end
         | 
    
        data/lib/shimmer/form/field.rb
    CHANGED
    
    
| @@ -5,8 +5,16 @@ module Shimmer | |
| 5 5 | 
             
                class RadioField < Field
         | 
| 6 6 | 
             
                  self.type = :radio
         | 
| 7 7 |  | 
| 8 | 
            +
                  def prepare
         | 
| 9 | 
            +
                    @value = options.delete(:value)
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 8 12 | 
             
                  def render
         | 
| 9 | 
            -
                    builder. | 
| 13 | 
            +
                    builder.radio_button method, @value, options
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def wrapper_options
         | 
| 17 | 
            +
                    {label_method: "#{method}_#{@value.to_s.underscore}".to_sym}
         | 
| 10 18 | 
             
                  end
         | 
| 11 19 | 
             
                end
         | 
| 12 20 | 
             
              end
         | 
| @@ -27,19 +27,27 @@ module Shimmer | |
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 29 | 
             
                def image_file_path(source, width: nil, height: nil)
         | 
| 30 | 
            -
                  image_file_proxy(source, width: width, height: height) | 
| 30 | 
            +
                  image_file_proxy(source, width: width, height: height, return_type: :path)
         | 
| 31 31 | 
             
                end
         | 
| 32 32 |  | 
| 33 33 | 
             
                def image_file_url(source, width: nil, height: nil)
         | 
| 34 | 
            -
                  image_file_proxy(source, width: width, height: height) | 
| 34 | 
            +
                  image_file_proxy(source, width: width, height: height, return_type: :url)
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 | 
            -
                def image_file_proxy(source, width: nil, height: nil)
         | 
| 37 | 
            +
                def image_file_proxy(source, width: nil, height: nil, return_type: nil)
         | 
| 38 38 | 
             
                  return if source.blank?
         | 
| 39 39 | 
             
                  return source if source.is_a?(String)
         | 
| 40 40 |  | 
| 41 41 | 
             
                  blob = source.try(:blob) || source
         | 
| 42 | 
            -
                  Shimmer::FileProxy.new(blob_id: blob.id, width: width, height: height)
         | 
| 42 | 
            +
                  proxy = Shimmer::FileProxy.new(blob_id: blob.id, width: width, height: height)
         | 
| 43 | 
            +
                  case return_type
         | 
| 44 | 
            +
                  when nil
         | 
| 45 | 
            +
                    proxy
         | 
| 46 | 
            +
                  when :path
         | 
| 47 | 
            +
                    proxy.path
         | 
| 48 | 
            +
                  when :url
         | 
| 49 | 
            +
                    proxy.url
         | 
| 50 | 
            +
                  end
         | 
| 43 51 | 
             
                end
         | 
| 44 52 | 
             
              end
         | 
| 45 53 | 
             
            end
         | 
    
        data/lib/shimmer/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: shimmer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.25
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jens Ravens
         | 
| @@ -158,6 +158,7 @@ files: | |
| 158 158 | 
             
            - lib/shimmer/form/password_field.rb
         | 
| 159 159 | 
             
            - lib/shimmer/form/pdf_field.rb
         | 
| 160 160 | 
             
            - lib/shimmer/form/radio_field.rb
         | 
| 161 | 
            +
            - lib/shimmer/form/radios_field.rb
         | 
| 161 162 | 
             
            - lib/shimmer/form/select_field.rb
         | 
| 162 163 | 
             
            - lib/shimmer/form/text_area_field.rb
         | 
| 163 164 | 
             
            - lib/shimmer/form/text_field.rb
         |