Skip to content

Commit bb10eaa

Browse files
Add map core component including docs&specs
1 parent b711543 commit bb10eaa

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%map{@tag_attributes}
2+
- if block_given?
3+
= yield
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Matestack::Ui::Core::Map
2+
class Map < Matestack::Ui::Core::Component::Static
3+
REQUIRED_KEYS = [:name]
4+
5+
def setup
6+
@tag_attributes.merge!({
7+
name: options[:name]
8+
})
9+
end
10+
end
11+
end

docs/components/map.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# matestack core component: Map
2+
3+
Show [specs](/spec/usage/components/map_spec.rb)
4+
5+
The HTML `<map>` tag implemented in Ruby.
6+
7+
## Parameters
8+
This component has a required `name` attribute and takes 2 optional configuration params. It contains a number of `<area>` elements that define the clickable areas in the image map.
9+
10+
#### # id (optional)
11+
Expects a string with all ids the `<map>` should have.
12+
13+
#### # class (optional)
14+
Expects a string with all classes the `<map>` should have.
15+
16+
#### # name
17+
Specifies the name of a parameter.
18+
19+
## Example:
20+
21+
```ruby
22+
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"
23+
24+
map name: 'newmap' do
25+
area shape: 'rect', coords: [0,0,100,100], href: 'first.htm', alt: 'First'
26+
area shape: 'rect', coords: [0,0,100,100], href: 'second.htm', alt: 'Second'
27+
area shape: 'rect', coords: [0,0,100,100], href: 'third.htm', alt: 'Third'
28+
end
29+
```
30+
31+
returns
32+
33+
```html
34+
<img src="matestack-logo.png" alt="otherlogo" width="500" height="300" usemap="#newmap">
35+
36+
<map name="newmap">
37+
<area shape="rect" coords="0,0,100,100" href="first.htm" alt="First">
38+
<area shape="rect" coords="100,100,200,200" href="second.htm" alt="Second">
39+
<area shape="rect" coords="200,200,300,300" href="third.htm" alt="Third">
40+
</map>
41+
```

spec/usage/components/map_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Map Component', type: :feature, js: true do
5+
6+
it 'Renders an image and a map containing areas on the page' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
def response
10+
components {
11+
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"
12+
13+
map name: 'newmap' do
14+
area shape: 'rect', coords: [0,0,100,100], href: 'first.htm', alt: 'First'
15+
area shape: 'rect', coords: [0,0,100,100], href: 'second.htm', alt: 'Second'
16+
area shape: 'rect', coords: [0,0,100,100], href: 'third.htm', alt: 'Third'
17+
end
18+
}
19+
end
20+
end
21+
22+
visit '/example'
23+
24+
static_output = page.html
25+
26+
expected_static_output = <<~HTML
27+
<img src="matestack-logo.png" alt="otherlogo" width="500" height="300" usemap="#newmap">
28+
29+
<map name="newmap">
30+
<area shape="rect" coords="0,0,100,100" href="first.htm" alt="First">
31+
<area shape="rect" coords="100,100,200,200" href="second.htm" alt="Second">
32+
<area shape="rect" coords="200,200,300,300" href="third.htm" alt="Third">
33+
</map>
34+
HTML
35+
36+
expect(stripped(static_output)).to include(stripped(expected_static_output))
37+
end
38+
end

0 commit comments

Comments
 (0)