Skip to content

Add map and area component #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/concepts/matestack/ui/core/area/area.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%area{@tag_attributes}
18 changes: 18 additions & 0 deletions app/concepts/matestack/ui/core/area/area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Matestack::Ui::Core::Area
class Area < Matestack::Ui::Core::Component::Static
def setup
@tag_attributes.merge!({
alt: options[:alt],
coords: options[:coords].join(','),
download: options[:download],
href: options[:href],
hreflang: options[:hreflang],
media: options[:media],
rel: options[:rel],
shape: options[:shape],
target: options[:target],
type: options[:type]
})
end
end
end
1 change: 1 addition & 0 deletions app/concepts/matestack/ui/core/img/img.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def setup
src: ActionController::Base.helpers.asset_path(options[:path]),
height: options[:height],
width: options[:width],
usemap: options[:usemap],
alt: options[:alt]
})
end
Expand Down
3 changes: 3 additions & 0 deletions app/concepts/matestack/ui/core/map/map.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%map{@tag_attributes}
- if block_given?
= yield
11 changes: 11 additions & 0 deletions app/concepts/matestack/ui/core/map/map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Matestack::Ui::Core::Map
class Map < Matestack::Ui::Core::Component::Static
REQUIRED_KEYS = [:name]

def setup
@tag_attributes.merge!({
name: options[:name]
})
end
end
end
62 changes: 62 additions & 0 deletions docs/components/area.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# matestack core component: Area

Tested within the [map specs](/spec/usage/components/map_spec.rb).

The HTML `<area>` tag implemented in Ruby.

## Parameters
This component takes up to 10 optional configuration params. It is meant to be used within the `<map>` component.

#### # alt (optional)
Expects a string that specifies an alternate text for the `<area>`. Required if the href attribute is present.

#### # coords (optional)
Expects an array of integers that define the `<area>`'s coordinates. For more details, see the [official documentation](https://www.w3schools.com/tags/att_area_coords.asp).

#### # download (optional)
Expects a string to specify the target that will be downloaded when a user clicks on the hyperlink.

#### # href (optional)
Expects a string to specify the hyperlink target for the area.

#### # hreflang (optional)
Expects a string to specify the language of the target URL.

#### # media (optional)
Expects a string to specify what media/device the target URL is optimized for.

#### # rel (optional)
Expects a string to specify the relationship between the current document and the target URL.

#### # shape (optional)
Expects a string to specify the shape of the area: Default, rect, circle, poly.

#### # target (optional)
Expects a string to specify where to open the target URL.

#### # type (optional)
Expects a string to specify the media type of the target URL.

## Example:

```ruby
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"

map name: 'newmap' do
area shape: 'rect', coords: [0,0,100,100], href: 'first.htm', alt: 'First'
area shape: 'rect', coords: [0,0,100,100], href: 'second.htm', alt: 'Second'
area shape: 'rect', coords: [0,0,100,100], href: 'third.htm', alt: 'Third'
end
```

returns

```html
<img src="matestack-logo.png" alt="otherlogo" width="500" height="300" usemap="#newmap">

<map name="newmap">
<area shape="rect" coords="0,0,100,100" href="first.htm" alt="First">
<area shape="rect" coords="100,100,200,200" href="second.htm" alt="Second">
<area shape="rect" coords="200,200,300,300" href="third.htm" alt="Third">
</map>
```
15 changes: 9 additions & 6 deletions docs/components/img.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ The HTML img tag implemented in ruby.

## Parameters

The image takes a mandatory path argument and can take 3 optional configuration params.
The image takes a mandatory path argument and can take 4 optional configuration params.

#### # path
Expects a string with the source to the image. It looks for the image in the assets/images folder and uses the standard Rails asset pipeline.
#### # alt (optional)
Expects a string with the alt text the image should have.

#### # height (optional)
Expects an integer with the height of the image in px.

#### # path
Expects a string with the source to the image. It looks for the image in the assets/images folder and uses the standard Rails asset pipeline.

#### # usemap (optional)
Expects a string to specify the image as a client-side image-map.

#### # width (optional)
Expects an integer with the width of the image in px.

#### # alt (optional)
Expects a string with the alt text the image should have.
41 changes: 41 additions & 0 deletions docs/components/map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# matestack core component: Map

Show [specs](/spec/usage/components/map_spec.rb)

The HTML `<map>` tag implemented in Ruby.

## Parameters
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.

#### # id (optional)
Expects a string with all ids the `<map>` should have.

#### # class (optional)
Expects a string with all classes the `<map>` should have.

#### # name
Specifies the name of a parameter.

## Example:

```ruby
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"

map name: 'newmap' do
area shape: 'rect', coords: [0,0,100,100], href: 'first.htm', alt: 'First'
area shape: 'rect', coords: [0,0,100,100], href: 'second.htm', alt: 'Second'
area shape: 'rect', coords: [0,0,100,100], href: 'third.htm', alt: 'Third'
end
```

returns

```html
<img src="matestack-logo.png" alt="otherlogo" width="500" height="300" usemap="#newmap">

<map name="newmap">
<area shape="rect" coords="0,0,100,100" href="first.htm" alt="First">
<area shape="rect" coords="100,100,200,200" href="second.htm" alt="Second">
<area shape="rect" coords="200,200,300,300" href="third.htm" alt="Third">
</map>
```
4 changes: 4 additions & 0 deletions spec/usage/components/img_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
class ExamplePage < Matestack::Ui::Page
def response
components {
# simple image
img path: 'matestack-logo.png', width: 500, height: 300, alt: "logo"
# using usemap
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"
}
end
end

visit '/example'

expect(page).to have_xpath("//img[contains(@src,'matestack-logo') and @alt='logo' and @width='500' and @height='300']")
expect(page).to have_xpath("//img[contains(@src,'matestack-logo') and @alt='otherlogo' and @width='500' and @height='300' and @usemap='\#newmap']")
end
end
37 changes: 37 additions & 0 deletions spec/usage/components/map_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative '../../support/utils'
include Utils

describe 'Map Component', type: :feature, js: true do

it 'Renders an image and a map containing areas on the page' do

class ExamplePage < Matestack::Ui::Page
def response
components {
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"

map name: 'newmap' do
area shape: 'rect', coords: [0,0,100,100], href: 'first.htm', alt: 'First'
area shape: 'rect', coords: [100,100,200,200], href: 'second.htm', alt: 'Second'
area shape: 'rect', coords: [200,200,300,300], href: 'third.htm', alt: 'Third'
end
}
end
end

visit '/example'

static_output = page.html

expected_static_output = <<~HTML
<map name="newmap">
<area alt="First" coords="0,0,100,100" href="first.htm" shape="rect">
<area alt="Second" coords="100,100,200,200" href="second.htm" shape="rect">
<area alt="Third" coords="200,200,300,300" href="third.htm" shape="rect">
</map>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
expect(page).to have_xpath("//img[contains(@src,'matestack-logo') and @alt='otherlogo' and @width='500' and @height='300' and @usemap='\#newmap']")
end
end
2 changes: 1 addition & 1 deletion spec/usage/components/pre_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def response
expected_static_output = <<~HTML
<pre>This is preformatted text</pre>
HTML
p stripped(static_output)

expect(stripped(static_output)).to include(stripped(expected_static_output))
end

Expand Down