vident 0.11.0 → 0.12.0
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/CHANGELOG.md +10 -0
- data/lib/vident/root_component.rb +35 -13
- data/lib/vident/stable_id.rb +7 -1
- data/lib/vident/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 503019b8aac7501339acff5c350afbca9abb55599a696f348321554da15183c0
         | 
| 4 | 
            +
              data.tar.gz: 175ffd2794c1b7c81bf879a8bb3c9f65c42fa16cc92748be77df255c0b5fdcff
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0c76ae38a7c66032e99b130e21d67ba52f6c9fc946e3476fc945b682e5916ad406f90c12e0db2ab189ddf961e8c4f1a6e2cd64fc7e79bd6464ea5ccb1387e0de
         | 
| 7 | 
            +
              data.tar.gz: f25903b4f38418a6752f33190713f0d8c9b3f5c2e251fb83476a35b2894df4dc848a3e104c13cf1d10ad448e774f924194020781f23b2c6d9732b061e0351e34
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -15,6 +15,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |
| 15 15 | 
             
            ### Fixed
         | 
| 16 16 |  | 
| 17 17 |  | 
| 18 | 
            +
            ## [0.12.0] - 2024-02-25
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ### Added
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            - `outlet` DSL methods updated so that the selector is scoped to the component's root element by default. This 
         | 
| 23 | 
            +
              is probably the most common use case, and it's now the default.
         | 
| 24 | 
            +
            - `with_outlets` DSL method added to generate the data-* attributes for the outlets and return as a fragment  
         | 
| 25 | 
            +
              of HTML
         | 
| 26 | 
            +
             | 
| 27 | 
            +
             | 
| 18 28 | 
             
            ## [0.11.0] - 2024-02-21
         | 
| 19 29 |  | 
| 20 30 | 
             
            ### Added
         | 
| @@ -69,10 +69,15 @@ module Vident | |
| 69 69 | 
             
                  build_target_data_attributes([target(name)])
         | 
| 70 70 | 
             
                end
         | 
| 71 71 |  | 
| 72 | 
            +
                def build_outlet_selector(outlet_selector)
         | 
| 73 | 
            +
                  prefix = @id ? "##{@id} " : ""
         | 
| 74 | 
            +
                  "#{prefix}[data-controller~=#{outlet_selector}]"
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 72 77 | 
             
                def outlet(css_selector: nil)
         | 
| 73 78 | 
             
                  controller = implied_controller_name
         | 
| 74 79 | 
             
                  if css_selector.nil?
         | 
| 75 | 
            -
                    [controller,  | 
| 80 | 
            +
                    [controller, build_outlet_selector(controller)]
         | 
| 76 81 | 
             
                  else
         | 
| 77 82 | 
             
                    [controller, css_selector]
         | 
| 78 83 | 
             
                  end
         | 
| @@ -104,6 +109,13 @@ module Vident | |
| 104 109 | 
             
                end
         | 
| 105 110 | 
             
                alias_method :with_action, :with_actions
         | 
| 106 111 |  | 
| 112 | 
            +
                # Return the HTML `data-` attribute for the given outlets
         | 
| 113 | 
            +
                def with_outlets(*outlets)
         | 
| 114 | 
            +
                  attrs = build_outlet_data_attributes(outlets)
         | 
| 115 | 
            +
                  attrs.map { |dt, n| "data-#{dt}=\"#{n}\"" }.join(" ").html_safe
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
                alias_method :with_outlet, :with_outlets
         | 
| 118 | 
            +
             | 
| 107 119 | 
             
                private
         | 
| 108 120 |  | 
| 109 121 | 
             
                # An implicit Stimulus controller name is built from the implicit controller path
         | 
| @@ -150,19 +162,29 @@ module Vident | |
| 150 162 |  | 
| 151 163 | 
             
                def outlet_list
         | 
| 152 164 | 
             
                  return {} unless @outlets&.size&.positive?
         | 
| 165 | 
            +
                  build_outlet_data_attributes(@outlets)
         | 
| 166 | 
            +
                end
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                def parse_outlet(outlet_config)
         | 
| 169 | 
            +
                  if outlet_config.is_a?(String)
         | 
| 170 | 
            +
                    [outlet_config, build_outlet_selector(outlet_config)]
         | 
| 171 | 
            +
                  elsif outlet_config.is_a?(Symbol)
         | 
| 172 | 
            +
                    outlet_config = outlet_config.to_s.tr("_", "-")
         | 
| 173 | 
            +
                    [outlet_config, build_outlet_selector(outlet_config)]
         | 
| 174 | 
            +
                  elsif outlet_config.is_a?(Array)
         | 
| 175 | 
            +
                    outlet_config[..1]
         | 
| 176 | 
            +
                  elsif outlet_config.respond_to?(:stimulus_identifier) # Is a Component
         | 
| 177 | 
            +
                    [outlet_config.stimulus_identifier, build_outlet_selector(outlet_config.stimulus_identifier)]
         | 
| 178 | 
            +
                  elsif outlet_config.send(:implied_controller_name) # Is a RootComponent ?
         | 
| 179 | 
            +
                    [outlet_config.send(:implied_controller_name), build_outlet_selector(outlet_config.send(:implied_controller_name))]
         | 
| 180 | 
            +
                  else
         | 
| 181 | 
            +
                    raise ArgumentError, "Invalid outlet config: #{outlet_config}"
         | 
| 182 | 
            +
                  end
         | 
| 183 | 
            +
                end
         | 
| 153 184 |  | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
                    elsif outlet_config.is_a?(Array)
         | 
| 158 | 
            -
                      outlet_config[..1]
         | 
| 159 | 
            -
                    elsif outlet_config.respond_to?(:stimulus_identifier) # Is a Component
         | 
| 160 | 
            -
                      [outlet_config.stimulus_identifier, "[data-controller~=#{outlet_config.stimulus_identifier}]"]
         | 
| 161 | 
            -
                    elsif outlet_config.send(:implied_controller_name) # Is a RootComponent ?
         | 
| 162 | 
            -
                      [outlet_config.send(:implied_controller_name), "[data-controller~=#{outlet_config.send(:implied_controller_name)}]"]
         | 
| 163 | 
            -
                    else
         | 
| 164 | 
            -
                      raise ArgumentError, "Invalid outlet config: #{outlet_config}"
         | 
| 165 | 
            -
                    end
         | 
| 185 | 
            +
                def build_outlet_data_attributes(outlets)
         | 
| 186 | 
            +
                  outlets.each_with_object({}) do |outlet_config, obj|
         | 
| 187 | 
            +
                    identifier, css_selector = parse_outlet(outlet_config)
         | 
| 166 188 | 
             
                    obj[:"#{implied_controller_name}-#{identifier}-outlet"] = css_selector
         | 
| 167 189 | 
             
                  end
         | 
| 168 190 | 
             
                end
         | 
    
        data/lib/vident/stable_id.rb
    CHANGED
    
    
    
        data/lib/vident/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: vident
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.12.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Stephen Ierodiaconou
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-02- | 
| 11 | 
            +
            date: 2024-02-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: railties
         |