Skip to content

Commit f26552e

Browse files
committed
Add abbr component with specs and documentation
1 parent 3d0d618 commit f26552e

File tree

5 files changed

+116
-0
lines changed

5 files changed

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

spec/dummy/dummy/db/development.sqlite3

Whitespace-only changes.

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+
class ExamplePage < Matestack::Ui::Page
8+
9+
def response
10+
components {
11+
abbr title: 'Hypertext Markup Language', text: 'HTML'
12+
}
13+
end
14+
15+
end
16+
17+
visit '/example'
18+
19+
static_output = page.html
20+
21+
expected_static_output = <<~HTML
22+
<abbr title="Hypertext Markup Language">HTML</abbr>
23+
HTML
24+
25+
expect(stripped(static_output)).to include(stripped(expected_static_output))
26+
end
27+
28+
it 'Example 2' do
29+
class ExamplePage < Matestack::Ui::Page
30+
31+
def response
32+
components {
33+
abbr title: 'Cascading Style Sheets' do
34+
span do
35+
plain 'CSS'
36+
end
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)