Skip to content

Commit 59c38cb

Browse files
Merge pull request #305 from marcoroth/picture_tag
add picture matestack core component
2 parents feb02c6 + 71a4001 commit 59c38cb

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%picture{@tag_attributes}
2+
- if block_given?
3+
= yield
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Matestack::Ui::Core::Picture
2+
class Picture < 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
@@ -54,6 +54,7 @@ You can build your [own components](/docs/extend/README.md) as well, both static
5454
- [paragraph](/docs/components/paragraph.md)
5555
- [param](/docs/components/param.md)
5656
- [pg](/docs/components/pg.md)
57+
- [picture](/docs/components/picture.md)
5758
- [plain](/docs/components/plain.md)
5859
- [pre](/docs/components/pre.md)
5960
- [progress](/docs/components/progress.md)

docs/components/picture.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# matestack core component: Picture
2+
3+
Show [specs](/spec/usage/components/picture_spec.rb)
4+
5+
The HTML `<picture>` tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 2 optional configuration params and yield the passed content.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the `<picture>` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `<picture>` should have.
16+
17+
## Example: Yield a given block
18+
19+
```ruby
20+
picture id: 'foo', class: 'bar' do
21+
img path: 'matestack-logo.png'
22+
end
23+
```
24+
25+
returns
26+
27+
```html
28+
<picture id="foo" class="bar">
29+
<img src="/assets/matestack-logo-XXXX.png" />
30+
</picture>
31+
```

spec/usage/components/picture_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 'Picture component', type: :feature, js: true do
5+
it 'Renders a picture tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# Just the tag
10+
picture
11+
12+
# With attributes
13+
picture id: 'my-id', class: 'my-class'
14+
15+
# With a sub-component
16+
picture do
17+
img path: 'matestack-logo.png'
18+
end
19+
}
20+
end
21+
end
22+
23+
visit '/example'
24+
25+
static_output = page.html
26+
27+
expected_static_output = <<~HTML
28+
<picture></picture>
29+
<picture id="my-id" class="my-class"></picture>
30+
HTML
31+
32+
expect(stripped(static_output)).to include(stripped(expected_static_output))
33+
expect(page).to have_xpath("//img[contains(@src,'matestack-logo')]")
34+
end
35+
end

0 commit comments

Comments
 (0)