rux-rails 1.5.0 → 2.0.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 +18 -0
- data/Gemfile +3 -0
- data/README.md +56 -0
- data/lib/rux-rails/{railtie.rb → engine.rb} +14 -4
- data/lib/rux-rails/tasks/transpile.rake +11 -10
- data/lib/rux-rails/version.rb +1 -1
- data/lib/rux-rails.rb +4 -1
- data/rux-rails.gemspec +4 -3
- data/spec/components/rails/button_spec.rb +18 -0
- data/spec/components/rails/button_to_spec.rb +24 -0
- data/spec/components/rails/content_tag_spec.rb +13 -0
- data/spec/components/rails/form_with_spec.rb +20 -0
- data/spec/components/rails/hidden_field_spec.rb +11 -0
- data/spec/components/rails/label_spec.rb +21 -0
- data/spec/components/rails/link_to_spec.rb +16 -0
- data/spec/components/rails/password_field_spec.rb +11 -0
- data/spec/components/rails/text_field_spec.rb +11 -0
- data/spec/components/rux/component_spec.rb +9 -0
- data/spec/controllers/home_controller_spec.rb +1 -1
- data/spec/dummy/app/components/image.rux +16 -0
- data/spec/dummy/log/test.log +534 -3384
- data/spec/dummy/tmp/local_secret.txt +1 -0
- data/spec/html_safety_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -36
- metadata +36 -14
- data/lib/rux-rails/components/audio.rb +0 -18
- data/lib/rux-rails/components/image.rb +0 -18
- data/lib/rux-rails/components/video.rb +0 -18
- data/lib/rux-rails/components.rb +0 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1dd540a2fa0ae930bc671d469c20928dc71faba5ad1ef3d52a13212f1e6373ef
         | 
| 4 | 
            +
              data.tar.gz: 6f8d5e0c2897d8c03c4bdea2b6fec7c170a1103c9ca2ef5a58edf07396c98328
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 694511000ee0f54d57a382d18986d50130811e2c74d3f5f8b4963f7e9472b4629174a893d659fe42b9e03fa6f683f3b1e9e0ffad9714411c34d2de9a13d61949
         | 
| 7 | 
            +
              data.tar.gz: 859fcf4b865afe9cd22f77d990263ac495acb275dccd21d487c0d01bf047b5ae0ab616ba57e61426c2d67d8eb8eebeadf90fea78048e7672e92376ba38849934
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,21 @@ | |
| 1 | 
            +
            ## 2.0.0
         | 
| 2 | 
            +
            * Remove the `Image`, `Audio`, and `Video` components (was anyone actually using these?)
         | 
| 3 | 
            +
            * Remove support for Rails 6.1 and 6.0.
         | 
| 4 | 
            +
            * Upgrade to onload v1.1 and rux to v1.3.
         | 
| 5 | 
            +
              - Add `config.rux.ignore_path` to Rails config for controlling which ignore file should be populated with generated paths.
         | 
| 6 | 
            +
            * Add a series of Rails helper components:
         | 
| 7 | 
            +
              - `Rails::ButtonTo`
         | 
| 8 | 
            +
              - `Rails::LinkTo`
         | 
| 9 | 
            +
              - `Rails::ContentTag`
         | 
| 10 | 
            +
              - `Rails::FormWith`
         | 
| 11 | 
            +
              - `Rails::Label`
         | 
| 12 | 
            +
              - `Rails::Button`
         | 
| 13 | 
            +
              - `Rails::HiddenField`
         | 
| 14 | 
            +
              - `Rails::PasswordField`
         | 
| 15 | 
            +
              - `Rails::TextField`
         | 
| 16 | 
            +
            * Add the `Rux::Component` component for rendering component instances.
         | 
| 17 | 
            +
              - Eg: `<Rux::Component instance={@child} />`.
         | 
| 18 | 
            +
             | 
| 1 19 | 
             
            ## 1.5.0
         | 
| 2 20 | 
             
            * Extract monkeypatches into the [onload gem](https://github.com/camertron/onload).
         | 
| 3 21 | 
             
            * Upgrade to rux v1.2.
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -282,6 +282,62 @@ There are also monkeypatches in place for Zeitwerk and `ActiveSupport::Dependenc | |
| 282 282 |  | 
| 283 283 | 
             
            Hit me up if you know of a less invasive way of enabling auto-transpilation.
         | 
| 284 284 |  | 
| 285 | 
            +
            ## Built-in Components
         | 
| 286 | 
            +
             | 
| 287 | 
            +
            The rux-rails gem contains several helper components to make it easier to work with Rails forms and tag helpers. Only a subset of Rails helpers are implemented. If you need others, please open an issue or, better yet, submit a pull request.
         | 
| 288 | 
            +
             | 
| 289 | 
            +
            ### Tag Helpers
         | 
| 290 | 
            +
             | 
| 291 | 
            +
            The following tag helpers are available as components:
         | 
| 292 | 
            +
             | 
| 293 | 
            +
            1. `button_to`: Use the `Rails::ButtonTo` component, eg: `<Rails::ButtonTo url: "http://example.com" label: "Click me" />`.
         | 
| 294 | 
            +
            1. `link_to`: Use the `Rails::LinkTo` component, eg: `<Rails::LinkTo url="http://example.com" label="Navigate" />`.
         | 
| 295 | 
            +
            1. `content_tag`: Use the `Rails::ContentTag` component, eg: `<Rails::ContentTag tag={:div}>content</Rails::ContentTag>`
         | 
| 296 | 
            +
             | 
| 297 | 
            +
            ### Form Helpers
         | 
| 298 | 
            +
             | 
| 299 | 
            +
            1. `form_with`: `Rails::FormWith`
         | 
| 300 | 
            +
            1. `button_tag` or `f.submit`: `Rails::Button`
         | 
| 301 | 
            +
            1. `label_tag` or `f.label`: `Rails::Label`
         | 
| 302 | 
            +
            1. `text_field_tag` or `f.text_field`: `Rails::TextField`
         | 
| 303 | 
            +
            1. `password_field_tag` or `f.password_field`: `Rails::PasswordField`
         | 
| 304 | 
            +
            1. `hidden_field_tag` or `f.hidden_field`: `Rails::HiddenField`
         | 
| 305 | 
            +
             | 
| 306 | 
            +
            ### Form Example
         | 
| 307 | 
            +
             | 
| 308 | 
            +
            Here's how to use the above components to build eg. a simple sign up form:
         | 
| 309 | 
            +
             | 
| 310 | 
            +
            ```ruby
         | 
| 311 | 
            +
            <Rails::FormWith model={User.new}>
         | 
| 312 | 
            +
              <Rails::Label name="name">Name</Rails::Label>
         | 
| 313 | 
            +
              <Rails::TextField name="name" />
         | 
| 314 | 
            +
              <Rails::Label name="email_address">Email address</Rails::Label>
         | 
| 315 | 
            +
              <Rails::TextField name="email_address" />
         | 
| 316 | 
            +
              <Rails::Label name="password">Password</Rails::Label>
         | 
| 317 | 
            +
              <Rails::PasswordField name="password" />
         | 
| 318 | 
            +
              <Rails::Label name="password_confirm">Confirm password</Rails::Label>
         | 
| 319 | 
            +
              <Rails::PasswordField name="password_confirmation" />
         | 
| 320 | 
            +
            </Rails::FormWith>
         | 
| 321 | 
            +
            ```
         | 
| 322 | 
            +
             | 
| 323 | 
            +
            ### The `Component` component
         | 
| 324 | 
            +
             | 
| 325 | 
            +
            Occasionally it can be useful to create an instance of a component outside the `call` method. While such a component can be rendered via the `render` method, doing so doesn't feel very "ruxy." That's where the `Rux::Component` component comes into play. It accepts a single `instance:` argument and renders it. For example:
         | 
| 326 | 
            +
             | 
| 327 | 
            +
            ```ruby
         | 
| 328 | 
            +
            class ParentComponent < ApplicationComponent
         | 
| 329 | 
            +
              def initialize
         | 
| 330 | 
            +
                @child = ChildComponent.new
         | 
| 331 | 
            +
              end
         | 
| 332 | 
            +
             | 
| 333 | 
            +
              def call
         | 
| 334 | 
            +
                <div>
         | 
| 335 | 
            +
                  <Rux::Component instance={@child} />
         | 
| 336 | 
            +
                </div>
         | 
| 337 | 
            +
              end
         | 
| 338 | 
            +
            end
         | 
| 339 | 
            +
            ```
         | 
| 340 | 
            +
             | 
| 285 341 | 
             
            ## Editor Support
         | 
| 286 342 |  | 
| 287 343 | 
             
            Sublime Text: [https://github.com/camertron/rux-SublimeText](https://github.com/camertron/rux-SublimeText)
         | 
| @@ -1,13 +1,12 @@ | |
| 1 | 
            -
            require 'rails/railtie'
         | 
| 2 1 | 
             
            require 'onload'
         | 
| 3 2 |  | 
| 4 3 | 
             
            module RuxRails
         | 
| 5 | 
            -
              class  | 
| 4 | 
            +
              class Engine < ::Rails::Engine
         | 
| 5 | 
            +
                isolate_namespace RuxRails
         | 
| 6 | 
            +
             | 
| 6 7 | 
             
                config.rux = ActiveSupport::OrderedOptions.new
         | 
| 7 8 |  | 
| 8 9 | 
             
                initializer 'rux-rails.initialize', before: 'onload.initialize' do |app|
         | 
| 9 | 
            -
                  ViewComponent::Base.send(:include, RuxRails::Components)
         | 
| 10 | 
            -
             | 
| 11 10 | 
             
                  if config.rux.transpile.nil? && (Rails.env.development? || Rails.env.test?)
         | 
| 12 11 | 
             
                    config.rux.transpile = true
         | 
| 13 12 | 
             
                    Onload.enabled = true
         | 
| @@ -29,6 +28,17 @@ module RuxRails | |
| 29 28 | 
             
                  end
         | 
| 30 29 | 
             
                end
         | 
| 31 30 |  | 
| 31 | 
            +
                config.after_initialize do
         | 
| 32 | 
            +
                  ignore_path = config.rux.ignore_path || Onload.config.ignore_path
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  if ignore_path.nil? && Rails.root.join(".gitignore").exist?
         | 
| 35 | 
            +
                    ignore_path = Rails.root.join(".gitignore").to_s
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  Onload.config.ignore_path = ignore_path
         | 
| 39 | 
            +
                  config.rux.ignore_path = ignore_path
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 32 42 | 
             
                rake_tasks do
         | 
| 33 43 | 
             
                  load File.expand_path(File.join(*%w(. tasks transpile.rake)), __dir__)
         | 
| 34 44 | 
             
                end
         | 
| @@ -3,18 +3,19 @@ require 'set' | |
| 3 3 |  | 
| 4 4 | 
             
            namespace :rux do
         | 
| 5 5 | 
             
              task transpile: :environment do
         | 
| 6 | 
            -
                 | 
| 7 | 
            -
             | 
| 6 | 
            +
                ignore_file = if Rails.application.config.rux.ignore_path
         | 
| 7 | 
            +
                  Onload::IgnoreFile.load(Rails.application.config.rux.ignore_path)
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                Dir.glob(Rails.root.join('**/*.rux')) do |file|
         | 
| 11 | 
            +
                  rux_file = Rux::File.new(file)
         | 
| 12 | 
            +
                  rux_file.write
         | 
| 8 13 |  | 
| 9 | 
            -
             | 
| 10 | 
            -
                  # Skip library paths. Libraries should ship with all their rux files
         | 
| 11 | 
            -
                  # pre-transpiled.
         | 
| 12 | 
            -
                  next if Rux.library_paths.include?(path)
         | 
| 14 | 
            +
                  puts "Wrote #{rux_file.default_outfile}"
         | 
| 13 15 |  | 
| 14 | 
            -
                   | 
| 15 | 
            -
                    Rux::File.new(file).write
         | 
| 16 | 
            -
                    puts "Wrote #{file}"
         | 
| 17 | 
            -
                  end
         | 
| 16 | 
            +
                  ignore_file&.add(rux_file.default_outfile)
         | 
| 18 17 | 
             
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ignore_file&.persist!
         | 
| 19 20 | 
             
              end
         | 
| 20 21 | 
             
            end
         | 
    
        data/lib/rux-rails/version.rb
    CHANGED
    
    
    
        data/lib/rux-rails.rb
    CHANGED
    
    
    
        data/rux-rails.gemspec
    CHANGED
    
    | @@ -10,10 +10,11 @@ Gem::Specification.new do |s| | |
| 10 10 | 
             
              s.description = s.summary = 'Rux view components on Rails.'
         | 
| 11 11 | 
             
              s.platform = Gem::Platform::RUBY
         | 
| 12 12 |  | 
| 13 | 
            -
              s.add_dependency 'rux', '~> 1. | 
| 13 | 
            +
              s.add_dependency 'rux', '~> 1.3'
         | 
| 14 14 | 
             
              s.add_dependency 'railties', '>= 5.0'
         | 
| 15 | 
            -
              s.add_dependency 'view_component', '>= 2', '<  | 
| 16 | 
            -
              s.add_dependency 'onload', '~> 1. | 
| 15 | 
            +
              s.add_dependency 'view_component', '>= 2', '< 5'
         | 
| 16 | 
            +
              s.add_dependency 'onload', '~> 1.1'
         | 
| 17 | 
            +
              s.add_dependency 'use_context', '~> 1.2'
         | 
| 17 18 |  | 
| 18 19 | 
             
              s.require_path = 'lib'
         | 
| 19 20 |  | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::Button, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(described_class.new)
         | 
| 6 | 
            +
                expect(rendered_content).to eq("<button name=\"button\" type=\"submit\">Button</button>")
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it 'renders with the given label' do
         | 
| 10 | 
            +
                render_inline(described_class.new(label: "Click me"))
         | 
| 11 | 
            +
                expect(rendered_content).to eq("<button name=\"button\" type=\"submit\">Click me</button>")
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              it 'renders with the given attributes' do
         | 
| 15 | 
            +
                render_inline(described_class.new(disabled: true))
         | 
| 16 | 
            +
                expect(rendered_content).to eq("<button name=\"button\" type=\"submit\" disabled=\"disabled\">Button</button>")
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::ButtonTo, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(described_class.new(url: "http://example.com"))
         | 
| 6 | 
            +
                expect(rendered_content).to include(
         | 
| 7 | 
            +
                  /<form .* action=\"http:\/\/example.com".*<button type=\"submit\"><\/button>/
         | 
| 8 | 
            +
                )
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              it 'renders with a label' do
         | 
| 12 | 
            +
                render_inline(described_class.new(label: "Click me", url: "http://example.com"))
         | 
| 13 | 
            +
                expect(rendered_content).to include(
         | 
| 14 | 
            +
                  /<form .* action=\"http:\/\/example.com".*<button type=\"submit\">Click me<\/button>/
         | 
| 15 | 
            +
                )
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              it 'renders with the content as the label' do
         | 
| 19 | 
            +
                render_inline(described_class.new(url: "http://example.com")) { "Click me" }
         | 
| 20 | 
            +
                expect(rendered_content).to include(
         | 
| 21 | 
            +
                  /<form .* action=\"http:\/\/example.com".*<button type=\"submit\">Click me<\/button>/
         | 
| 22 | 
            +
                )
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::ContentTag, type: :component do
         | 
| 4 | 
            +
              it 'renders an empty tag by default' do
         | 
| 5 | 
            +
                render_inline(described_class.new(tag: :div))
         | 
| 6 | 
            +
                expect(rendered_content).to eq("<div></div>")
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it 'renders content within the tags' do
         | 
| 10 | 
            +
                render_inline(described_class.new(tag: :div)) { 'Hello, world' }
         | 
| 11 | 
            +
                expect(rendered_content).to eq("<div>Hello, world</div>")
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::FormWith, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(described_class.new(url: "/foo"))
         | 
| 6 | 
            +
                expect(rendered_content).to include("<form action=\"/foo\" accept-charset=\"UTF-8\" method=\"post\"><input type=\"hidden\" name=\"authenticity_token\"")
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it 'adds the builder to the rux context' do
         | 
| 10 | 
            +
                builder = nil
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                render_inline(described_class.new(url: "/foo")) do
         | 
| 13 | 
            +
                  UseContext.use_context(:rux, :form_builder) do |f|
         | 
| 14 | 
            +
                    builder = f
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                expect(builder).to be_a(ActionView::Helpers::FormBuilder)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::HiddenField, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(Rails::FormWith.new(url: "/foo")) do
         | 
| 6 | 
            +
                  described_class.new(name: "bar").render_in(view_context)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                expect(rendered_content).to include("<input autocomplete=\"off\" type=\"hidden\" name=\"bar\" id=\"bar\" />")
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::Label, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(Rails::FormWith.new(url: "/foo")) do
         | 
| 6 | 
            +
                  described_class.new(name: "bar").render_in(view_context)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                expect(rendered_content).to include("<label for=\"bar\">Bar</label>")
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              it 'renders content within the tags' do
         | 
| 13 | 
            +
                render_inline(Rails::FormWith.new(url: "/foo")) do
         | 
| 14 | 
            +
                  described_class.new(name: "bar").render_in(view_context) do
         | 
| 15 | 
            +
                    "Hello, world"
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                expect(rendered_content).to include("<label for=\"bar\">Hello, world</label>")
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::LinkTo, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(described_class.new(url: "http://example.com", label: "foo"))
         | 
| 6 | 
            +
                expect(rendered_content).to eq("<a href=\"http://example.com\">foo</a>")
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it 'renders the content between the tags' do
         | 
| 10 | 
            +
                render_inline(described_class.new(url: "http://example.com")) do
         | 
| 11 | 
            +
                  "Hello, world"
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                expect(rendered_content).to eq("<a href=\"http://example.com\">Hello, world</a>")
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::PasswordField, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(Rails::FormWith.new(url: "/foo")) do
         | 
| 6 | 
            +
                  described_class.new(name: "bar").render_in(view_context)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                expect(rendered_content).to include("<input type=\"password\" name=\"bar\" id=\"bar\" />")
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rails::TextField, type: :component do
         | 
| 4 | 
            +
              it 'renders with defaults' do
         | 
| 5 | 
            +
                render_inline(Rails::FormWith.new(url: "/foo")) do
         | 
| 6 | 
            +
                  described_class.new(name: "bar").render_in(view_context)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                expect(rendered_content).to include("<input type=\"text\" name=\"bar\" id=\"bar\" />")
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Rux::Component, type: :component do
         | 
| 4 | 
            +
              it 'renders the given instance' do
         | 
| 5 | 
            +
                render_inline(Rux::Component.new(instance: Image.new(src: "foo.png")))
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                expect(rendered_content).to include("<img src=\"/images/foo.png\" />")
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
            end
         | 
| @@ -4,7 +4,7 @@ describe HomeController, type: :request do | |
| 4 4 | 
             
              describe '#index' do
         | 
| 5 5 | 
             
                before(:each) do
         | 
| 6 6 | 
             
                  # Force a recompile to avoid test pollution
         | 
| 7 | 
            -
                  HomeComponent.compile
         | 
| 7 | 
            +
                  HomeComponent.respond_to?(:__vc_compile) ? HomeComponent.__vc_compile : HomeComponent.compile
         | 
| 8 8 | 
             
                end
         | 
| 9 9 |  | 
| 10 10 | 
             
                it 'transpiles the file' do
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Image < ViewComponent::Base
         | 
| 4 | 
            +
              include ActionView::Helpers::AssetUrlHelper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              attr_reader :src, :params
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def initialize(src:, **params)
         | 
| 9 | 
            +
                @src = src
         | 
| 10 | 
            +
                @params = params
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def call
         | 
| 14 | 
            +
                image_tag(src, **params)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         |