rux-rails 2.0.0 → 2.0.1

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: 1dd540a2fa0ae930bc671d469c20928dc71faba5ad1ef3d52a13212f1e6373ef
4
- data.tar.gz: 6f8d5e0c2897d8c03c4bdea2b6fec7c170a1103c9ca2ef5a58edf07396c98328
3
+ metadata.gz: 165b4b8d75f8f86508bf707d2c94e57024b2ec9e43836bb4c0bb03fb281802dc
4
+ data.tar.gz: 167dfbce40a501d442f527f16a7164f6f63066ab6451a8d964a88de1e1833218
5
5
  SHA512:
6
- metadata.gz: 694511000ee0f54d57a382d18986d50130811e2c74d3f5f8b4963f7e9472b4629174a893d659fe42b9e03fa6f683f3b1e9e0ffad9714411c34d2de9a13d61949
7
- data.tar.gz: 859fcf4b865afe9cd22f77d990263ac495acb275dccd21d487c0d01bf047b5ae0ab616ba57e61426c2d67d8eb8eebeadf90fea78048e7672e92376ba38849934
6
+ metadata.gz: ffa5153d1254db96dededb72789176b59124990ffe2caffdd78afc1009d136bbe7dba88e5a24c4fc98fe6480be740e8bdd4c572330b5935e4a0b46078767fc2d
7
+ data.tar.gz: 4a342b9445f6d4784b5e8eca9a01e26f9f952c0c144cf62d697a0682f2cde075cee2dcd6be0b905a45504b40cea87b537a7c51a5bdf839b0ef2f984900789901
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.0.1
2
+ * Include app/ directory in published gem 🤦‍♂️
3
+
1
4
  ## 2.0.0
2
5
  * Remove the `Image`, `Audio`, and `Video` components (was anyone actually using these?)
3
6
  * Remove support for Rails 6.1 and 6.0.
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class BaseComponent < ViewComponent::Base
5
+ private
6
+
7
+ def normalize_kwargs(kwargs)
8
+ klass = kwargs.delete(:class)
9
+ klasses = kwargs.delete(:classes)
10
+ return kwargs unless klass || klasses
11
+
12
+ kwargs[:class] = class_names(klass, klasses)
13
+ kwargs
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class Button < BaseComponent
5
+ def initialize(label: "Button", **kwargs)
6
+ @label = label
7
+ @kwargs = normalize_kwargs(kwargs)
8
+ end
9
+
10
+ def call
11
+ button_tag(@label, **@kwargs)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class ButtonTo < BaseComponent
5
+ def initialize(url:, label: nil, **kwargs)
6
+ @url = url
7
+ @label = label
8
+ @kwargs = normalize_kwargs(kwargs)
9
+ end
10
+
11
+ def call
12
+ if @label
13
+ button_to(@label, @url, **@kwargs)
14
+ else
15
+ button_to(@url, **@kwargs) do
16
+ content
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class ContentTag < BaseComponent
5
+ def initialize(tag:, **kwargs)
6
+ @tag = tag
7
+ @kwargs = kwargs
8
+ @kwargs = normalize_kwargs(kwargs)
9
+ end
10
+
11
+ def call
12
+ content_tag(@tag, content, **@kwargs)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "use_context"
4
+
5
+ module Rails
6
+ class BuilderNotFoundError < StandardError; end
7
+
8
+ class FormInput < BaseComponent
9
+ include UseContext::ContextMethods
10
+
11
+ def builder
12
+ use_context(:rux, :form_builder).tap do |builder|
13
+ unless builder
14
+ raise BuilderNotFoundError, "expected #{self.class.name} to be used inside a Rails form_with or form_for block"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ <%= form_with(*@args, **@kwargs) do |f| %>
2
+ <% provide_context(:rux, { form_builder: f }) do %>
3
+ <%= content %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "use_context"
4
+
5
+ module Rails
6
+ class FormWith < BaseComponent
7
+ include UseContext::ContextMethods
8
+
9
+ def initialize(*args, **kwargs)
10
+ @args = args
11
+ @kwargs = normalize_kwargs(kwargs)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class HiddenField < FormInput
5
+ def initialize(name:, **kwargs)
6
+ @name = name
7
+ @kwargs = normalize_kwargs(kwargs)
8
+ end
9
+
10
+ def call
11
+ builder.hidden_field(@name, **@kwargs)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class Label < FormInput
5
+ def initialize(name:, **kwargs)
6
+ @name = name
7
+ @kwargs = normalize_kwargs(kwargs)
8
+ end
9
+
10
+ def call
11
+ builder.label(@name, content, **@kwargs)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class LinkTo < BaseComponent
5
+ def initialize(url:, label: nil, **kwargs)
6
+ @url = url
7
+ @label = label
8
+ @kwargs = normalize_kwargs(kwargs)
9
+ end
10
+
11
+ def call
12
+ if @label
13
+ link_to(@label, @url, **@kwargs)
14
+ else
15
+ link_to(@url, **@kwargs) do
16
+ content
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class PasswordField < FormInput
5
+ def initialize(name:, **kwargs)
6
+ @name = name
7
+ @kwargs = normalize_kwargs(kwargs)
8
+ end
9
+
10
+ def call
11
+ builder.password_field(@name, **@kwargs)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ class TextField < FormInput
5
+ def initialize(name:, **kwargs)
6
+ @name = name
7
+ @kwargs = normalize_kwargs(kwargs)
8
+ end
9
+
10
+ def call
11
+ builder.text_field(@name, **@kwargs)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rux
4
+ # For rendering a component that you already have an instance of, perhaps
5
+ # created in another component's constructor
6
+ class Component < ViewComponent::Base
7
+ def initialize(instance:)
8
+ @instance = instance
9
+ end
10
+
11
+ def call
12
+ render(@instance)
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module RuxRails
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
data/rux-rails.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.require_path = 'lib'
20
20
 
21
- s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'rux-rails.gemspec']
21
+ s.files = Dir['{app,lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'rux-rails.gemspec']
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rux-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
@@ -98,6 +98,19 @@ files:
98
98
  - LICENSE
99
99
  - README.md
100
100
  - Rakefile
101
+ - app/components/rails/base_component.rb
102
+ - app/components/rails/button.rb
103
+ - app/components/rails/button_to.rb
104
+ - app/components/rails/content_tag.rb
105
+ - app/components/rails/form_input.rb
106
+ - app/components/rails/form_with.html.erb
107
+ - app/components/rails/form_with.rb
108
+ - app/components/rails/hidden_field.rb
109
+ - app/components/rails/label.rb
110
+ - app/components/rails/link_to.rb
111
+ - app/components/rails/password_field.rb
112
+ - app/components/rails/text_field.rb
113
+ - app/components/rux/component.rb
101
114
  - lib/rux-rails.rb
102
115
  - lib/rux-rails/engine.rb
103
116
  - lib/rux-rails/output_buffer.rb