Skip to content

Commit f4c75c4

Browse files
add bdi core component & docs & tests
1 parent 0687c4f commit f4c75c4

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%bdi{@tag_attributes}
2+
- if options[:text].blank? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Matestack::Ui::Core::Bdi
2+
class Bdi < Matestack::Ui::Core::Component::Static
3+
end
4+
end

docs/components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ You can build your [own components](/docs/extend/README.md) as well, both static
1212
- [article](/docs/components/article.md)
1313
- [aside](/docs/components/aside.md)
1414
- [b](/docs/components/b.md)
15+
- [bdi](/docs/components/bdi.md)
1516
- [blockquote](/docs/components/blockquote.md)
1617
- [br](/docs/components/br.md)
1718
- [button](/docs/components/button.md)

docs/components/bdi.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# matestack core component: Bdi
2+
3+
Show [specs](/spec/usage/components/bdi_spec.rb)
4+
5+
The HTML `<bdi>` tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 2 optional configuration params and either yield content or display what gets passed to the `text` configuration param.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the `<bdi>` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `<bdi>` should have.
16+
17+
## Example 1: Yield a given block
18+
19+
```ruby
20+
bdi id: 'foo', class: 'bar' do
21+
plain 'Bdi example 1' # optional content
22+
end
23+
```
24+
25+
returns
26+
27+
```html
28+
<bdi id="foo" class="bar">
29+
Bdi example 1
30+
</bdi>
31+
```
32+
33+
## Example 2: Render `options[:text]` param
34+
35+
```ruby
36+
bdi id: 'foo', class: 'bar', text: 'Bdi example 2'
37+
```
38+
39+
returns
40+
41+
```html
42+
<bdi id="foo" class="bar">
43+
Bdi example 2
44+
</bdi>

spec/usage/components/bdi_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Bdi component', type: :feature, js: true do
5+
it 'Renders a simple and enhanced bdi tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# Simple bdi
10+
bdi text: 'Simple bdi tag'
11+
12+
# Enhanced bdi
13+
bdi id: 'my-id', class: 'my-class' do
14+
plain 'Enhanced bdi tag'
15+
end
16+
}
17+
end
18+
end
19+
20+
visit '/example'
21+
22+
static_output = page.html
23+
24+
expected_static_output = <<~HTML
25+
<bdi>Simple bdi tag</bdi>
26+
<bdi id="my-id" class="my-class">Enhanced bdi tag</bdi>
27+
HTML
28+
29+
expect(stripped(static_output)).to include(stripped(expected_static_output))
30+
end
31+
end

0 commit comments

Comments
 (0)