Skip to content

Commit feb02c6

Browse files
Merge pull request #301 from basemate/add_bdo_component
Add bdo core component including tests & docs
2 parents 3ae4dac + 2f93545 commit feb02c6

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%bdo{@tag_attributes}
2+
- if options[:text].blank? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Matestack::Ui::Core::Bdo
2+
class Bdo < Matestack::Ui::Core::Component::Static
3+
REQUIRED_KEYS = [:dir]
4+
5+
def setup
6+
@tag_attributes.merge!({
7+
"dir": options[:dir]
8+
})
9+
end
10+
end
11+
end

docs/components/README.md

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

docs/components/bdo.md

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

spec/usage/components/bdo_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Bdo component', type: :feature, js: true do
5+
it 'Renders a simple and enhanced bdo tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# Simple bdo
10+
bdo dir: 'ltr', text: 'Simple bdo ltr tag'
11+
bdo dir: 'rtl', text: 'Simple bdo rtl tag'
12+
13+
# Enhanced bdo
14+
bdo id: 'foo', class: 'bar', dir: 'ltr' do
15+
plain 'This text will go left-to-right.' # optional content
16+
end
17+
bdo id: 'bar', class: 'foo', dir: 'rtl' do
18+
plain 'This text will go right-to-left.' # optional content
19+
end
20+
}
21+
end
22+
end
23+
24+
visit '/example'
25+
26+
static_output = page.html
27+
28+
expected_static_output = <<~HTML
29+
<bdo dir="ltr">Simple bdo ltr tag</bdo>
30+
<bdo dir="rtl">Simple bdo rtl tag</bdo>
31+
<bdo dir="ltr" id="foo" class="bar">This text will go left-to-right.</bdo>
32+
<bdo dir="rtl" id="bar" class="foo">This text will go right-to-left.</bdo>
33+
HTML
34+
35+
expect(stripped(static_output)).to include(stripped(expected_static_output))
36+
37+
end
38+
39+
it 'Fails if required dir tag is not set' do
40+
class ExamplePage < Matestack::Ui::Page
41+
def response
42+
components {
43+
bdo text: 'Simple bdo ltr tag'
44+
}
45+
end
46+
end
47+
48+
visit '/example'
49+
50+
expect(page).to have_content("required key 'dir' is missing")
51+
52+
end
53+
end

0 commit comments

Comments
 (0)