Skip to content

Commit 627d275

Browse files
Merge pull request #230 from mayanktap/add-dl-tag
Add dl component
2 parents 186db0c + 451694f commit 627d275

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%dl{@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::Dl
2+
class Dl < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/dl.md

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

spec/usage/components/dl_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 'Dl 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+
dl id: 'my-id', class: 'my-class' do
13+
dt text: "dt component"
14+
dd text: "dd component"
15+
end
16+
}
17+
end
18+
19+
end
20+
21+
visit '/example'
22+
static_output = page.html
23+
24+
expected_static_output = <<~HTML
25+
<dl id="my-id" class="my-class"><dt>dt component</dt><dd>dd component</dd></dl>
26+
HTML
27+
expect(stripped(static_output)).to include(stripped(expected_static_output))
28+
end
29+
30+
it 'Example 2 - render options[:text]' do
31+
32+
class ExamplePage < Matestack::Ui::Page
33+
34+
def response
35+
components {
36+
# simple dl tag
37+
dl text: 'This is simple dl text'
38+
39+
# enhanced dl tag
40+
dl id: 'my-id', class: 'my-class', text: 'This is a enhanced dl with text'
41+
}
42+
end
43+
44+
end
45+
46+
visit '/example'
47+
48+
static_output = page.html
49+
50+
expected_static_output = <<~HTML
51+
<dl>This is simple dl text</dl>
52+
<dl id="my-id" class="my-class">This is a enhanced dl with text</dl>
53+
HTML
54+
55+
expect(stripped(static_output)).to include(stripped(expected_static_output))
56+
end
57+
58+
end

0 commit comments

Comments
 (0)