Skip to content

Commit 832fb2b

Browse files
committed
add output matestack core component
Closes #204
1 parent 50ccbbd commit 832fb2b

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%output{@tag_attributes}
2+
- if options[:text].blank? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Matestack::Ui::Core::Output
2+
class Output < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!(
5+
name: options[:name],
6+
for: options[:for],
7+
form: options[:form]
8+
)
9+
end
10+
end
11+
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
- [legend](/docs/components/legend.md)
4242
- [mark](/docs/components/mark.md)
4343
- [noscript](/docs/components/noscript.md)
44+
- [output](/docs/components/output.md)
4445
- [sup](/docs/components/sup.md)
4546
- [sub](/docs/components/sub.md)
4647
- [var](/docs/components/var.md)

docs/components/output.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# matestack core component: Output
2+
3+
Show [specs](/spec/usage/components/output_spec.rb)
4+
5+
The HTML `<output>` tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take up to 5 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 `<output>` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `<output>` should have.
16+
17+
#### # name (optional)
18+
Specifies a name for the `<output>` element
19+
20+
#### # for (optional)
21+
Specifies the relationship between the result of the calculation, and the elements used in the calculation
22+
23+
#### # form (optional)
24+
Specifies one or more forms the `<output>` element belongs to
25+
26+
## Example 1:
27+
28+
```ruby
29+
output name: 'x', for: 'a b', text: ''
30+
```
31+
32+
returns
33+
34+
```html
35+
<output for="a b" name="x"></output>
36+
```
37+
38+
## Example 2:
39+
40+
```ruby
41+
output id: 'my-id', class: 'my-class', name: 'x', for: 'a b', form: 'form_id' do
42+
plain 'All attributes'
43+
end
44+
```
45+
46+
returns
47+
48+
```html
49+
<output for="a b" form="form_id" id="my-id" name="x" class="my-class">
50+
All attributes
51+
</output>
52+
```

spec/usage/components/output_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 'Output component', type: :feature, js: true do
5+
it 'Renders a simple and enhanced output tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# Without content
10+
output name: 'x', for: 'a b'
11+
12+
# Only content
13+
output text: 'Only content'
14+
15+
# All attributes
16+
output id: 'my-id', class: 'my-class', name: 'x', for: 'a b', form: 'form_id' do
17+
plain 'All attributes'
18+
end
19+
}
20+
end
21+
end
22+
23+
visit '/example'
24+
25+
static_output = page.html
26+
27+
expected_static_output = <<~HTML
28+
<output for="a b" name="x"></output>
29+
<output>Only content</output>
30+
<output for="a b" form="form_id" id="my-id" name="x" class="my-class">All attributes</output>
31+
HTML
32+
33+
expect(stripped(static_output)).to include(stripped(expected_static_output))
34+
end
35+
end

0 commit comments

Comments
 (0)