Skip to content

Commit 0581977

Browse files
Merge pull request #124 from basemate/add-abbr-tag
Add abbr component with specs and documentation
2 parents 522f75e + 3ca0bce commit 0581977

File tree

4 files changed

+119
-0
lines changed

4 files changed

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

docs/components/abbr.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# matestack core component: abbr
2+
3+
Show [specs](../../spec/usage/components/abbr_spec.rb)
4+
5+
The HTML `abbr` tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component expects 1 required param, 2 optional configuration params and either yield content or display what gets passed to the `text` configuration param.
10+
11+
#### # title - required
12+
Expects a string with the meaning of the abbreviation contained within the tag.
13+
14+
#### # id - optional
15+
Expects a string with all ids the `abbr` should have.
16+
17+
#### # class - optional
18+
Expects a string with all classes the `abbr` should have.
19+
20+
#### # text - optional
21+
Expects a string which will be displayed as the content inside the `abbr`. If this is not passed, a block must be passed instead.
22+
23+
## Example 1 - render options[:text] param
24+
25+
```ruby
26+
abbr title: 'Hypertext Markup Language', text: 'HTML'
27+
```
28+
29+
returns
30+
31+
```html
32+
<abbr title="Hypertext Markup Language">HTML</abbr>
33+
```
34+
35+
36+
## Example 2 - yield a given block
37+
38+
```ruby
39+
abbr title: 'Cascading Style Sheets' do
40+
span text: 'CSS'
41+
end
42+
```
43+
44+
returns
45+
46+
```html
47+
<abbr title="Cascading Style Sheets">CSS</abbr>
48+
```

spec/usage/components/abbr_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Abbr Component', type: :feature, js: true do
5+
6+
it 'Example 1' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
10+
def response
11+
components {
12+
abbr title: 'Hypertext Markup Language', text: 'HTML'
13+
}
14+
end
15+
16+
end
17+
18+
visit '/example'
19+
20+
static_output = page.html
21+
22+
expected_static_output = <<~HTML
23+
<abbr title="Hypertext Markup Language">HTML</abbr>
24+
HTML
25+
26+
expect(stripped(static_output)).to include(stripped(expected_static_output))
27+
end
28+
29+
it 'Example 2' do
30+
31+
class ExamplePage < Matestack::Ui::Page
32+
33+
def response
34+
components {
35+
abbr title: 'Cascading Style Sheets' do
36+
span text: 'CSS'
37+
end
38+
}
39+
end
40+
41+
end
42+
43+
visit '/example'
44+
45+
static_output = page.html
46+
47+
expected_static_output = <<~HTML
48+
<abbr title="Cascading Style Sheets"><span>CSS</span></abbr>
49+
HTML
50+
51+
expect(stripped(static_output)).to include(stripped(expected_static_output))
52+
end
53+
54+
end

0 commit comments

Comments
 (0)