pxs-forms 0.0.3 → 0.0.5
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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d104c5306510402433e059fc586670ef5e5a1b74e4b9bf2c77c06b2afcb4f670
         | 
| 4 | 
            +
              data.tar.gz: d44594a3c375515f24a25b408a7823525d42ccd03825378d1cccf389b59890d1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0d582f3edaf4ba27891152fa3559fd217ddc23a348143b35d4d8fabd4a5696448733dbede256ba1df927d8da718d4703e3d2a740a22c363dc4014762afda989c
         | 
| 7 | 
            +
              data.tar.gz: 5a48c1ae301869a9a27c797f552edff87e2aaa6587a3a28fc360a91d880865c0100ba1d0af8292d5d2c4c20e0592e7bc3be2d1f5da3189281c66d0de248caf61
         | 
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            module Pxs
         | 
| 2 2 | 
             
                module Forms
         | 
| 3 | 
            -
                    module  | 
| 3 | 
            +
                    module LinksHelper
         | 
| 4 4 | 
             
                        def turbo_link_button(text, target, method = :get)
         | 
| 5 5 | 
             
                            link_to text, target, class: "button", data: { turbo_stream: true, turbo_method: method }
         | 
| 6 6 | 
             
                        end
         | 
| @@ -12,4 +12,4 @@ module Pxs | |
| 12 12 | 
             
                end
         | 
| 13 13 | 
             
            end
         | 
| 14 14 |  | 
| 15 | 
            -
            ActionView::Base.send :include, Pxs::Forms:: | 
| 15 | 
            +
            ActionView::Base.send :include, Pxs::Forms::LinksHelper
         | 
| @@ -2,22 +2,37 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder | |
| 2 2 |  | 
| 3 3 | 
             
                delegate :tag, :safe_join, to: :@template
         | 
| 4 4 |  | 
| 5 | 
            +
                # define a model field
         | 
| 6 | 
            +
                # the format is deduced from the column type or attribute name
         | 
| 5 7 | 
             
                def field(attribute, options = {})
         | 
| 8 | 
            +
                    puts attribute
         | 
| 9 | 
            +
                    puts options.inspect
         | 
| 6 10 | 
             
                    @form_options = options
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    # extract the object type from the attribute
         | 
| 7 13 | 
             
                    object_type = object_type_for_attribute(attribute)
         | 
| 8 14 |  | 
| 15 | 
            +
                    puts object_type.inspect
         | 
| 16 | 
            +
                    # set the input type depending on the attribute type
         | 
| 9 17 | 
             
                    input_type = case object_type
         | 
| 10 18 | 
             
                        when :date then :string
         | 
| 11 19 | 
             
                        when :integer then :string
         | 
| 12 20 | 
             
                        else object_type
         | 
| 13 21 | 
             
                    end
         | 
| 14 22 |  | 
| 23 | 
            +
                    puts input_type.inspect
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    # if as: :input_type is set, use it to set input type
         | 
| 15 26 | 
             
                    override_input_type = if options[:as]
         | 
| 16 27 | 
             
                        options[:as]
         | 
| 28 | 
            +
                    # for collections, use a Select
         | 
| 17 29 | 
             
                    elsif options[:collection]
         | 
| 18 30 | 
             
                        :select
         | 
| 19 31 | 
             
                    end
         | 
| 20 32 |  | 
| 33 | 
            +
                    puts override_input_type.inspect
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    # return result of [input_type]_input method
         | 
| 21 36 | 
             
                    send("#{override_input_type || input_type}_input", attribute, options)
         | 
| 22 37 | 
             
                end
         | 
| 23 38 |  | 
| @@ -74,10 +89,10 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder | |
| 74 89 | 
             
                    end
         | 
| 75 90 | 
             
                end
         | 
| 76 91 |  | 
| 77 | 
            -
                def collection_input( | 
| 78 | 
            -
                    field_block( | 
| 92 | 
            +
                def collection_input(attribute, options, &block)
         | 
| 93 | 
            +
                    field_block(attribute, options) do
         | 
| 79 94 | 
             
                        safe_join [
         | 
| 80 | 
            -
                            label( | 
| 95 | 
            +
                            label(attribute, options[:label]),
         | 
| 81 96 | 
             
                            block.call,
         | 
| 82 97 | 
             
                        ]
         | 
| 83 98 | 
             
                    end
         | 
| @@ -85,8 +100,10 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder | |
| 85 100 |  | 
| 86 101 | 
             
                def select_input(attribute, options = {})
         | 
| 87 102 |  | 
| 88 | 
            -
                     | 
| 89 | 
            -
                     | 
| 103 | 
            +
                    # default value method to :id
         | 
| 104 | 
            +
                    value_method = options[:value_method] || :id
         | 
| 105 | 
            +
                    # default text method to :name
         | 
| 106 | 
            +
                    text_method = options[:text_method] || :name
         | 
| 90 107 | 
             
                    input_options = options[:input_html] || {}
         | 
| 91 108 |  | 
| 92 109 | 
             
                    multiple = input_options[:multiple]
         | 
| @@ -166,7 +183,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder | |
| 166 183 | 
             
                end
         | 
| 167 184 |  | 
| 168 185 | 
             
                def field_block(attribute, options = {}, &block)
         | 
| 169 | 
            -
                    tag.div class: "field #{attribute}" do
         | 
| 186 | 
            +
                    tag.div class: "field #{attribute}", id: options[:field_id] do
         | 
| 170 187 | 
             
                        safe_join [
         | 
| 171 188 | 
             
                            block.call,
         | 
| 172 189 | 
             
                            hint_text(options[:hint]),
         | 
| @@ -187,7 +204,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder | |
| 187 204 |  | 
| 188 205 | 
             
                def error_text(attribute)
         | 
| 189 206 | 
             
                    if has_error? attribute
         | 
| 190 | 
            -
                        tag.div @object.errors[ | 
| 207 | 
            +
                        tag.div @object.errors[attribute].join("<br />").html_safe, class: "form-errors"
         | 
| 191 208 | 
             
                    end
         | 
| 192 209 | 
             
                end
         | 
| 193 210 |  | 
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            module Pxs
         | 
| 2 2 | 
             
                module Forms
         | 
| 3 | 
            -
                    module  | 
| 3 | 
            +
                    module ModelsHelper
         | 
| 4 4 | 
             
                        # base_path: the model's CRUD base path as an URL string, like the result of article_path(:id)
         | 
| 5 5 | 
             
                        def model_edit_delete_actions(base_path)
         | 
| 6 6 | 
             
                            [
         | 
| @@ -47,10 +47,10 @@ module Pxs | |
| 47 47 |  | 
| 48 48 | 
             
                        def model_form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
         | 
| 49 49 | 
             
                            options = options.reverse_merge(builder: ModelFormBuilder)
         | 
| 50 | 
            -
                            form_with(model: model, scope: scope, url: url, format: format, class: "form#{options.has_key? :class ? " #{options[:class]}" : ""}", **options, &block)
         | 
| 50 | 
            +
                            form_with(model: model, scope: scope, url: url, format: format, class: "form#{(options.has_key? :class) ? " #{options[:class]}" : ""}", **options, &block)
         | 
| 51 51 | 
             
                        end
         | 
| 52 52 | 
             
                    end
         | 
| 53 53 | 
             
                end
         | 
| 54 54 | 
             
            end
         | 
| 55 55 |  | 
| 56 | 
            -
            ActionView::Base.send :include, Pxs::Forms:: | 
| 56 | 
            +
            ActionView::Base.send :include, Pxs::Forms::ModelsHelper
         | 
    
        data/lib/pxs/forms/version.rb
    CHANGED
    
    
    
        data/lib/pxs/forms.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            require_relative "forms/version"
         | 
| 4 | 
            -
            require_relative "forms/ | 
| 5 | 
            -
            require_relative "forms/ | 
| 4 | 
            +
            require_relative "forms/links_helper"
         | 
| 5 | 
            +
            require_relative "forms/models_helper"
         | 
| 6 6 | 
             
            require_relative "forms/model_form_builder"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pxs-forms
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Poubelle
         | 
| @@ -24,9 +24,9 @@ files: | |
| 24 24 | 
             
            - README.md
         | 
| 25 25 | 
             
            - Rakefile
         | 
| 26 26 | 
             
            - lib/pxs/forms.rb
         | 
| 27 | 
            -
            - lib/pxs/forms/ | 
| 27 | 
            +
            - lib/pxs/forms/links_helper.rb
         | 
| 28 28 | 
             
            - lib/pxs/forms/model_form_builder.rb
         | 
| 29 | 
            -
            - lib/pxs/forms/ | 
| 29 | 
            +
            - lib/pxs/forms/models_helper.rb
         | 
| 30 30 | 
             
            - lib/pxs/forms/version.rb
         | 
| 31 31 | 
             
            - pxs-forms.gemspec
         | 
| 32 32 | 
             
            - sig/pxs/forms.rbs
         |