amber_component 0.0.5 → 1.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/Gemfile.lock +6 -6
- data/README.md +97 -0
- data/banner.png +0 -0
- data/lib/amber_component/props.rb +1 -1
- data/lib/amber_component/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d81663eb6f3cd153cb0a277a0114f8cce4e2140f40685f23a688a60c8ce86226
|
4
|
+
data.tar.gz: 32abb3383e052466435f318e1f8c4010adfa5f3d7e93e588e7e2842ff7cd59e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3df277a91914b6a148cc72c1b3981f78c420e773b408c8555a8915424d11667c804f113c2a1fd76bce751083607086ab660f1634855fcec686bc433b875c12
|
7
|
+
data.tar.gz: 330efd82e1589a4804f72f4dcb1df1f9a9b90696ce2dfb542c69b91dd1b0a5b7797736c9fa8ce461f73ff7bb16a3966a8ed00b8340c6d047d289acde976240cc
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
amber_component (0.0
|
4
|
+
amber_component (1.0.0)
|
5
5
|
actionview (>= 6)
|
6
6
|
activemodel (>= 6)
|
7
7
|
activesupport (>= 6)
|
@@ -94,21 +94,21 @@ GEM
|
|
94
94
|
rainbow (3.1.1)
|
95
95
|
rake (13.0.6)
|
96
96
|
rchardet (1.8.0)
|
97
|
-
regexp_parser (2.
|
97
|
+
regexp_parser (2.6.0)
|
98
98
|
reverse_markdown (2.1.1)
|
99
99
|
nokogiri
|
100
100
|
rexml (3.2.5)
|
101
|
-
rubocop (1.
|
101
|
+
rubocop (1.38.0)
|
102
102
|
json (~> 2.3)
|
103
103
|
parallel (~> 1.10)
|
104
104
|
parser (>= 3.1.2.1)
|
105
105
|
rainbow (>= 2.2.2, < 4.0)
|
106
106
|
regexp_parser (>= 1.8, < 3.0)
|
107
107
|
rexml (>= 3.2.5, < 4.0)
|
108
|
-
rubocop-ast (>= 1.
|
108
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
109
109
|
ruby-progressbar (~> 1.7)
|
110
110
|
unicode-display_width (>= 1.4.0, < 3.0)
|
111
|
-
rubocop-ast (1.
|
111
|
+
rubocop-ast (1.23.0)
|
112
112
|
parser (>= 3.1.1.0)
|
113
113
|
ruby-progressbar (1.11.0)
|
114
114
|
ruby2_keywords (0.0.5)
|
@@ -124,7 +124,7 @@ GEM
|
|
124
124
|
simplecov (~> 0.19)
|
125
125
|
simplecov-html (0.12.3)
|
126
126
|
simplecov_json_formatter (0.1.4)
|
127
|
-
solargraph (0.
|
127
|
+
solargraph (0.47.2)
|
128
128
|
backport (~> 1.2)
|
129
129
|
benchmark
|
130
130
|
bundler (>= 1.17.2)
|
data/README.md
CHANGED
@@ -283,12 +283,14 @@ a block.
|
|
283
283
|
<!-- app/controller/tasks/show.html.erb -->
|
284
284
|
|
285
285
|
<%= ModalComponent.call id: 'update-task-modal' title: 'Update the task' do %>
|
286
|
+
<!-- You can provide HTML and render other components -->
|
286
287
|
<h2>This is your task!</h2>
|
287
288
|
<%= form_with model: @task do |f| %>
|
288
289
|
<%= f.text_field :name %>
|
289
290
|
<%= f.text_area :description %>
|
290
291
|
<%= f.submit %>
|
291
292
|
<% end %>
|
293
|
+
<%= OtherComponent.call some: 'prop' %>
|
292
294
|
<% end %>
|
293
295
|
```
|
294
296
|
|
@@ -299,6 +301,8 @@ only when it is present (will work without nested content)
|
|
299
301
|
you can use `yield.html_safe if block_given?`
|
300
302
|
|
301
303
|
In general `block_given?` will return `true` when a block/nested content is present, otherwise `false`.
|
304
|
+
You can use it to render content conditionally based on
|
305
|
+
whether nested content is present.
|
302
306
|
|
303
307
|
### Components with namespaces
|
304
308
|
|
@@ -358,6 +362,99 @@ $ bin/rails generate component FooBar
|
|
358
362
|
|
359
363
|
This will generate a new component in `app/components/foo_bar_component.rb` along with a view, stylesheet and test file.
|
360
364
|
|
365
|
+
### Testing Components
|
366
|
+
|
367
|
+
### Rails
|
368
|
+
|
369
|
+
After setting up this gem with the rails generator
|
370
|
+
`rails generate amber_component:install` a new abstract
|
371
|
+
test class will be available called `ApplicationComponentTestCase`.
|
372
|
+
|
373
|
+
It provides a handful of helper methods to make it
|
374
|
+
easier to inspect the rendered HTML.
|
375
|
+
|
376
|
+
A simple test file may look like this:
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
# test/components/foo_component_test.rb
|
380
|
+
|
381
|
+
require 'test_helper'
|
382
|
+
|
383
|
+
class FooComponentTest < ApplicationComponentTestCase
|
384
|
+
test 'render correct HTML' do
|
385
|
+
# Specify what the assertions are supposed to
|
386
|
+
# check against.
|
387
|
+
#
|
388
|
+
# There can be multiple renders in one test
|
389
|
+
# but they override the previous one.
|
390
|
+
# So there is only one rendered component
|
391
|
+
# at any given time.
|
392
|
+
render do
|
393
|
+
FooComponent.call some: 'prop'
|
394
|
+
end
|
395
|
+
|
396
|
+
# Assertions on the rendered HTML
|
397
|
+
|
398
|
+
# Use a CSS selector
|
399
|
+
assert_selector ".foo_component span.my_class", text: 'Some Text'
|
400
|
+
# Check text
|
401
|
+
assert_text 'Amber Component is awesome!'
|
402
|
+
end
|
403
|
+
end
|
404
|
+
```
|
405
|
+
|
406
|
+
A full list of available assertions can be found [here](https://rubydoc.info/github/jnicklas/capybara/Capybara/Node/Matchers).
|
407
|
+
|
408
|
+
### Non Rails
|
409
|
+
|
410
|
+
There is a test case class for minitest. You can
|
411
|
+
access it by requiring `'amber_component/minitest_test_case'`.
|
412
|
+
|
413
|
+
It has the same assertion methods as the Rails test case class.
|
414
|
+
It requires [capybara](https://github.com/teamcapybara/capybara) to be installed and present in the Gemfile.
|
415
|
+
|
416
|
+
A full list of available assertions can be found [here](https://rubydoc.info/github/jnicklas/capybara/Capybara/Node/Matchers).
|
417
|
+
|
418
|
+
```ruby
|
419
|
+
require 'amber_component/minitest_test_case'
|
420
|
+
|
421
|
+
class FooComponentTest < AmberComponent::MinitestTestCase
|
422
|
+
def test_render_correct_html
|
423
|
+
# Specify what the assertions are supposed to
|
424
|
+
# check against.
|
425
|
+
#
|
426
|
+
# There can be multiple renders in one test
|
427
|
+
# but they override the previous one.
|
428
|
+
# So there is only one rendered component
|
429
|
+
# at any given time.
|
430
|
+
render do
|
431
|
+
FooComponent.call some: 'prop'
|
432
|
+
end
|
433
|
+
|
434
|
+
# Assertions on the rendered HTML
|
435
|
+
|
436
|
+
# Use a CSS selector
|
437
|
+
assert_selector ".foo_component span.my_class", text: 'Some Text'
|
438
|
+
# Check text
|
439
|
+
assert_text 'Amber Component is awesome!'
|
440
|
+
end
|
441
|
+
end
|
442
|
+
```
|
443
|
+
|
444
|
+
There is also a helper module which provides all of these assertions
|
445
|
+
under `'amber_component/test_helper'`.
|
446
|
+
|
447
|
+
```ruby
|
448
|
+
require 'amber_component/test_helper'
|
449
|
+
|
450
|
+
class MyAbstractTestCase < ::Minitest::Test
|
451
|
+
include ::AmberComponent::TestHelper
|
452
|
+
end
|
453
|
+
```
|
454
|
+
|
455
|
+
Note that this module has only been tested with minitest and rails test suites,
|
456
|
+
so it may require overriding or implementing a few methods to work with other test suites.
|
457
|
+
|
361
458
|
## Contribute
|
362
459
|
|
363
460
|
Do you want to contribute to AmberComponent? Open the issues page and check for the help wanted label! But before you start coding, please read our [Contributing Guide](https://github.com/amber-ruby/amber_component/blob/main/CONTRIBUTING.md).
|
data/banner.png
CHANGED
Binary file
|