Skip to content

Commit 824a576

Browse files
Merge pull request #217 from mayanktap/add-dd-tag
Add dd component.
2 parents ab61ab8 + f07c1d3 commit 824a576

File tree

4 files changed

+120
-0
lines changed

4 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+
%dd{@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::Dd
2+
class Dd < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/dd.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# matestack core component: Dd
2+
3+
Show [specs](/spec/usage/components/dd_spec.rb)
4+
5+
The HTML dd tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 3 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 `dd` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `dd` should have.
16+
17+
## Example 1: Yield a given block
18+
19+
```ruby
20+
dd id: "foo", class: "bar" do
21+
plain 'Hello World'
22+
end
23+
```
24+
25+
returns
26+
27+
```html
28+
<dd id="foo" class="bar">
29+
Hello World
30+
</dd>
31+
```
32+
33+
## Example 2: Render options[:text] param
34+
35+
```ruby
36+
dd id: "foo", class: "bar", text: 'Hello World'
37+
```
38+
39+
returns
40+
41+
```html
42+
<dd id="foo" class="bar">
43+
Hello World
44+
</dd>
45+
```
46+

spec/usage/components/dd_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require_relative "../../support/utils"
2+
include Utils
3+
4+
describe 'Dd Component', type: :feature, js: true do
5+
6+
it 'Example 1 - yield, no options[:text]' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
10+
def response
11+
components {
12+
# simple dd tag
13+
dd do
14+
plain 'This is simple dd text'
15+
end
16+
17+
# enhanced dd tag
18+
dd id: 'my-id', class: 'my-class' do
19+
plain 'This is a enhanced dd with text'
20+
end
21+
}
22+
end
23+
24+
end
25+
26+
visit '/example'
27+
static_output = page.html
28+
29+
expected_static_output = <<~HTML
30+
<dd>This is simple dd text</dd>
31+
<dd id="my-id" class="my-class">This is a enhanced dd with text</dd>
32+
HTML
33+
expect(stripped(static_output)).to include(stripped(expected_static_output))
34+
end
35+
36+
it 'Example 2 - render options[:text]' do
37+
38+
class ExamplePage < Matestack::Ui::Page
39+
40+
def response
41+
components {
42+
# simple dd tag
43+
dd text: 'This is simple dd text'
44+
45+
# enhanced dd tag
46+
dd id: 'my-id', class: 'my-class', text: 'This is a enhanced dd with text'
47+
}
48+
end
49+
50+
end
51+
52+
visit '/example'
53+
54+
static_output = page.html
55+
56+
expected_static_output = <<~HTML
57+
<dd>This is simple dd text</dd>
58+
<dd id="my-id" class="my-class">This is a enhanced dd with text</dd>
59+
HTML
60+
61+
expect(stripped(static_output)).to include(stripped(expected_static_output))
62+
end
63+
64+
end

0 commit comments

Comments
 (0)