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 +4 -4
- data/CHANGELOG.md +3 -0
- data/app/components/rails/base_component.rb +16 -0
- data/app/components/rails/button.rb +14 -0
- data/app/components/rails/button_to.rb +21 -0
- data/app/components/rails/content_tag.rb +15 -0
- data/app/components/rails/form_input.rb +19 -0
- data/app/components/rails/form_with.html.erb +5 -0
- data/app/components/rails/form_with.rb +14 -0
- data/app/components/rails/hidden_field.rb +14 -0
- data/app/components/rails/label.rb +14 -0
- data/app/components/rails/link_to.rb +21 -0
- data/app/components/rails/password_field.rb +14 -0
- data/app/components/rails/text_field.rb +14 -0
- data/app/components/rux/component.rb +15 -0
- data/lib/rux-rails/version.rb +1 -1
- data/rux-rails.gemspec +1 -1
- metadata +14 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 165b4b8d75f8f86508bf707d2c94e57024b2ec9e43836bb4c0bb03fb281802dc
|
|
4
|
+
data.tar.gz: 167dfbce40a501d442f527f16a7164f6f63066ab6451a8d964a88de1e1833218
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffa5153d1254db96dededb72789176b59124990ffe2caffdd78afc1009d136bbe7dba88e5a24c4fc98fe6480be740e8bdd4c572330b5935e4a0b46078767fc2d
|
|
7
|
+
data.tar.gz: 4a342b9445f6d4784b5e8eca9a01e26f9f952c0c144cf62d697a0682f2cde075cee2dcd6be0b905a45504b40cea87b537a7c51a5bdf839b0ef2f984900789901
|
data/CHANGELOG.md
CHANGED
|
@@ -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,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,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,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,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
|
data/lib/rux-rails/version.rb
CHANGED
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.
|
|
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
|