Skip to content

Commit 3a02970

Browse files
authored
Merge pull request #126 from basemate/add-address-tag
Add address tag, specs and documentation
2 parents 6a2f857 + a960c9c commit 3a02970

File tree

4 files changed

+122
-0
lines changed

4 files changed

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

docs/components/address.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# matestack core component: Address
2+
3+
Show [specs](../../spec/usage/components/address_spec.rb)
4+
5+
The HTML `<address>` 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 address should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the address should have.
16+
17+
#### # text (optional)
18+
Expects a ruby string with the text the address tag should show.
19+
20+
## Example 1 - yield a given block
21+
22+
```ruby
23+
address do
24+
plain 'Codey McCodeface'
25+
br
26+
plain '1 Developer Avenue'
27+
br
28+
plain 'Techville'
29+
end
30+
```
31+
32+
returns
33+
34+
```html
35+
<address>
36+
Codey McCodeface<br>
37+
1 Developer Avenue<br>
38+
Techville
39+
</address>
40+
```
41+
42+
## Example 2 - render options[:text] param
43+
44+
```ruby
45+
address text: 'PO Box 12345'
46+
```
47+
48+
returns
49+
50+
```html
51+
<address>
52+
PO Box 12345
53+
</address>
54+
```

spec/usage/components/address_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Address Component', type: :feature, js: true do
5+
6+
it 'Example 1 - yield a given block' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
10+
def response
11+
components {
12+
address do
13+
plain 'Codey McCodeface'
14+
br
15+
plain '1 Developer Avenue'
16+
br
17+
plain 'Techville'
18+
end
19+
}
20+
end
21+
22+
end
23+
24+
visit '/example'
25+
26+
static_output = page.html
27+
28+
expected_static_output = <<~HTML
29+
<address>Codey McCodeface<br>1 Developer Avenue<br>Techville</address>
30+
HTML
31+
32+
expect(stripped(static_output)).to include(stripped(expected_static_output))
33+
end
34+
35+
it 'Example 2 - render options[:text] param' do
36+
37+
class ExamplePage < Matestack::Ui::Page
38+
39+
def response
40+
components {
41+
address text: 'PO Box 12345'
42+
}
43+
end
44+
45+
end
46+
47+
visit '/example'
48+
49+
static_output = page.html
50+
51+
expected_static_output = <<~HTML
52+
<address>PO Box 12345</address>
53+
HTML
54+
55+
expect(stripped(static_output)).to include(stripped(expected_static_output))
56+
end
57+
58+
end

0 commit comments

Comments
 (0)