Skip to content

Commit 0b80217

Browse files
Merge pull request #265 from marcoroth/param_tag
add param matestack core component
2 parents 817bd53 + bfa553b commit 0b80217

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%param{@tag_attributes}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Matestack::Ui::Core::Param
2+
class Param < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!({
5+
name: options[:name],
6+
value: options[:value]
7+
})
8+
end
9+
end
10+
end

docs/components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
3434
- [button](/docs/components/button.md)
3535
- [link](/docs/components/link.md)
3636
- [label](/docs/components/label.md)
37+
- [param](/docs/components/param.md)
3738
- [progress](/docs/components/progress.md)
3839
- [ruby](/docs/components/ruby.md)
3940
- [rt](/docs/components/rb.md)

docs/components/param.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# matestack core component: Param
2+
3+
Show [specs](/spec/usage/components/param_spec.rb)
4+
5+
The HTML `<param>` tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 4 optional configuration params.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the `<param>` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `<param>` should have.
16+
17+
#### # name (optional)
18+
Specifies the name of a parameter.
19+
20+
#### # value (optional)
21+
Specifies the value of the parameter
22+
23+
24+
## Example 1:
25+
26+
```ruby
27+
param name: 'autoplay', value: 'true'
28+
```
29+
30+
returns
31+
32+
```html
33+
<param name="autoplay" value="true">
34+
```
35+
36+
## Example 2:
37+
38+
```ruby
39+
param name: 'autoplay', value: 'true', id: 'my-id', class: 'my-class'
40+
```
41+
42+
returns
43+
44+
```html
45+
<param id="my-id" name="autoplay" value="true" class="my-class">
46+
```

spec/usage/components/param_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Param component', type: :feature, js: true do
5+
it 'Renders a param tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# Just the tag
10+
param
11+
12+
# With some attributes
13+
param name: 'autoplay', value: 'true'
14+
15+
# All attributes
16+
param name: 'autoplay', value: 'true', id: 'my-id', class: 'my-class'
17+
}
18+
end
19+
end
20+
21+
visit '/example'
22+
23+
static_output = page.html
24+
25+
expected_static_output = <<~HTML
26+
<param>
27+
<param name="autoplay" value="true">
28+
<param id="my-id" name="autoplay" value="true" class="my-class">
29+
HTML
30+
31+
expect(stripped(static_output)).to include(stripped(expected_static_output))
32+
end
33+
end

0 commit comments

Comments
 (0)