Skip to content

Commit 0a71485

Browse files
add var component
1 parent 88effec commit 0a71485

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
4141
- [sup](/docs/components/sup.md)
4242
- [sub](/docs/components/sub.md)
4343
- [kbd](/docs/components/kbd.md)
44+
- [var](/docs/components/var.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 `<code>` tag should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `<code>` 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)