Skip to content

Commit 3bfbae8

Browse files
Merge pull request #247 from basemate/add_var_component
add var component
2 parents 88effec + 2bd16c9 commit 3bfbae8

File tree

5 files changed

+99
-9
lines changed

5 files changed

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

docs/components/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
55

66
## Static Core Components
77

8+
- [b](/docs/components/b.md)
9+
- [br](/docs/components/br.md)
810
- [div](/docs/components/div.md)
9-
- [header](/docs/components/header.md)
1011
- [footer](/docs/components/footer.md)
12+
- [header](/docs/components/header.md)
13+
- [heading](/docs/components/heading.md)
14+
- [kbd](/docs/components/kbd.md)
15+
- [hr](/docs/components/hr.md)
16+
- [icon](/docs/components/icon.md)
1117
- [main](/docs/components/main.md)
1218
- [nav](/docs/components/nav.md)
13-
- [section](/docs/components/section.md)
14-
- [br](/docs/components/br.md)
15-
- [hr](/docs/components/hr.md)
16-
- [heading](/docs/components/heading.md)
1719
- [plain](/docs/components/plain.md)
1820
- [pg](/docs/components/pg.md)
21+
- [section](/docs/components/section.md)
1922
- [span](/docs/components/span.md)
20-
- [b](/docs/components/b.md)
21-
- [icon](/docs/components/icon.md)
2223
- [list](/docs/components/list.md)
2324
- ul
2425
- ol
@@ -28,7 +29,6 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
2829
- tr
2930
- td
3031
- [img](/docs/components/img.md)
31-
- [video](/docs/components/video.md)
3232
- [button](/docs/components/button.md)
3333
- [link](/docs/components/link.md)
3434
- [label](/docs/components/label.md)
@@ -40,7 +40,8 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
4040
- [noscript](/docs/components/noscript.md)
4141
- [sup](/docs/components/sup.md)
4242
- [sub](/docs/components/sub.md)
43-
- [kbd](/docs/components/kbd.md)
43+
- [var](/docs/components/var.md)
44+
- [video](/docs/components/video.md)
4445

4546
## Dynamic Core Components
4647

docs/components/var.md

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

spec/usage/components/var_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Var 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+
# example 1
13+
var id: "foo", class: "bar" do
14+
plain 'I get yielded'
15+
end
16+
# example 2
17+
var id: "foo", class: "bar", text: 'I am text'
18+
}
19+
end
20+
21+
end
22+
23+
visit '/example'
24+
25+
static_output = page.html
26+
27+
expected_static_output = <<~HTML
28+
<var id="foo" class="bar">I get yielded</var>
29+
<var id="foo" class="bar">I am text</var>
30+
HTML
31+
32+
expect(stripped(static_output)).to include(stripped(expected_static_output))
33+
end
34+
35+
end

0 commit comments

Comments
 (0)