amber_component 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1809ef804fefeb8ed7e05b8d1056895f7068663b92b74b464b99bb611981e7c
4
- data.tar.gz: 7a05630fb2c74850241378c1b2e176373258b0e3a63aa7eae26803fc0a7077d5
3
+ metadata.gz: d81663eb6f3cd153cb0a277a0114f8cce4e2140f40685f23a688a60c8ce86226
4
+ data.tar.gz: 32abb3383e052466435f318e1f8c4010adfa5f3d7e93e588e7e2842ff7cd59e6
5
5
  SHA512:
6
- metadata.gz: b554c4cbaafe3fd6e4cbebe34c4e99ea7d318e50aa38b599b87c35d72bf5a353e0099b0471d643543c6f6227275295f63c0f33432940d7d0de71b8ac29ddd488
7
- data.tar.gz: 69ef4f133acd94753d9108b56ef44f601fd59435a53dadaf194905190f53db8dcc368dcd3c5da68cfcc027a8a27a4b6a33d99f40b3bb3985cf3c80ce9c79e8bc
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.5)
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.5.0)
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.36.0)
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.20.1, < 2.0)
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.21.0)
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.46.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
@@ -75,7 +75,7 @@ module ::AmberComponent
75
75
  module InstanceMethods
76
76
  private
77
77
 
78
- # @param props [Hash{Symbol => Object}]
78
+ # @param kwargs [Hash{Symbol => Object}]
79
79
  def initialize(**kwargs)
80
80
  bind_props(kwargs)
81
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ::AmberComponent
4
- VERSION = '0.0.5'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amber_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby-Amber