Skip to content

Commit f05c875

Browse files
committed
Add abbr component with specs and documentation
1 parent cf82a65 commit f05c875

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
end
11+
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
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+
21+
## Example 1 - render options[:text] param
22+
23+
```ruby
24+
abbr title: 'Hypertext Markup Language', text: 'HTML'
25+
```
26+
27+
returns
28+
29+
```html
30+
<abbr title="Hypertext Markup Language">HTML</abbr>
31+
```
32+
33+
34+
## Example 2 - yield a given block
35+
36+
```ruby
37+
abbr title: 'Cascading Style Sheets' do
38+
span do
39+
plain 'CSS'
40+
end
41+
end
42+
```
43+
44+
returns
45+
46+
```html
47+
<abbr title="Cascading Style Sheets">CSS</abbr>
48+
```

spec/dummy/dummy/db/development.sqlite3

Whitespace-only changes.

spec/usage/components/abbr_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 do
37+
plain 'CSS'
38+
end
39+
end
40+
}
41+
end
42+
43+
end
44+
45+
visit '/example'
46+
47+
static_output = page.html
48+
49+
expected_static_output = <<~HTML
50+
<abbr title="Cascading Style Sheets"><span>CSS</span></abbr>
51+
HTML
52+
53+
expect(stripped(static_output)).to include(stripped(expected_static_output))
54+
end
55+
56+
end

0 commit comments

Comments
 (0)