Skip to content

Commit 49f89bd

Browse files
Merge branch 'develop' into add_object_component
2 parents cfc2b9d + dbb41ef commit 49f89bd

File tree

19 files changed

+1876
-881
lines changed

19 files changed

+1876
-881
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%area{@tag_attributes}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Matestack::Ui::Core::Area
2+
class Area < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!({
5+
alt: options[:alt],
6+
coords: options[:coords].join(','),
7+
download: options[:download],
8+
href: options[:href],
9+
hreflang: options[:hreflang],
10+
media: options[:media],
11+
rel: options[:rel],
12+
shape: options[:shape],
13+
target: options[:target],
14+
type: options[:type]
15+
})
16+
end
17+
end
18+
end

app/concepts/matestack/ui/core/img/img.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def setup
66
src: ActionController::Base.helpers.asset_path(options[:path]),
77
height: options[:height],
88
width: options[:width],
9+
usemap: options[:usemap],
910
alt: options[:alt]
1011
})
1112
end

app/concepts/matestack/ui/core/link/link.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def setup
99
"id": component_id,
1010
"method": options[:method],
1111
"target": options[:target] ||= nil,
12-
"href": link_path
12+
"href": link_path,
13+
"title": options[:title]
1314
})
1415
end
1516

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

builder/yarn.lock

Lines changed: 1566 additions & 853 deletions
Large diffs are not rendered by default.

docs/components/area.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# matestack core component: Area
2+
3+
Tested within the [map specs](/spec/usage/components/map_spec.rb).
4+
5+
The HTML `<area>` tag implemented in Ruby.
6+
7+
## Parameters
8+
This component takes up to 10 optional configuration params. It is meant to be used within the `<map>` component.
9+
10+
#### # alt (optional)
11+
Expects a string that specifies an alternate text for the `<area>`. Required if the href attribute is present.
12+
13+
#### # coords (optional)
14+
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).
15+
16+
#### # download (optional)
17+
Expects a string to specify the target that will be downloaded when a user clicks on the hyperlink.
18+
19+
#### # href (optional)
20+
Expects a string to specify the hyperlink target for the area.
21+
22+
#### # hreflang (optional)
23+
Expects a string to specify the language of the target URL.
24+
25+
#### # media (optional)
26+
Expects a string to specify what media/device the target URL is optimized for.
27+
28+
#### # rel (optional)
29+
Expects a string to specify the relationship between the current document and the target URL.
30+
31+
#### # shape (optional)
32+
Expects a string to specify the shape of the area: Default, rect, circle, poly.
33+
34+
#### # target (optional)
35+
Expects a string to specify where to open the target URL.
36+
37+
#### # type (optional)
38+
Expects a string to specify the media type of the target URL.
39+
40+
## Example:
41+
42+
```ruby
43+
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"
44+
45+
map name: 'newmap' do
46+
area shape: 'rect', coords: [0,0,100,100], href: 'first.htm', alt: 'First'
47+
area shape: 'rect', coords: [0,0,100,100], href: 'second.htm', alt: 'Second'
48+
area shape: 'rect', coords: [0,0,100,100], href: 'third.htm', alt: 'Third'
49+
end
50+
```
51+
52+
returns
53+
54+
```html
55+
<img src="matestack-logo.png" alt="otherlogo" width="500" height="300" usemap="#newmap">
56+
57+
<map name="newmap">
58+
<area shape="rect" coords="0,0,100,100" href="first.htm" alt="First">
59+
<area shape="rect" coords="100,100,200,200" href="second.htm" alt="Second">
60+
<area shape="rect" coords="200,200,300,300" href="third.htm" alt="Third">
61+
</map>
62+
```

docs/components/img.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ The HTML img tag implemented in ruby.
66

77
## Parameters
88

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

11-
#### # path
12-
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.
11+
#### # alt (optional)
12+
Expects a string with the alt text the image should have.
1313

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

17+
#### # path
18+
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.
19+
20+
#### # usemap (optional)
21+
Expects a string to specify the image as a client-side image-map.
22+
1723
#### # width (optional)
1824
Expects an integer with the width of the image in px.
19-
20-
#### # alt (optional)
21-
Expects a string with the alt text the image should have.

docs/components/link.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ The HTTP request method the link should implement.
2828
#### # target (optional, default is nil)
2929
Specify where to open the linked document.
3030

31+
#### # title (optional)
32+
Specify a title for the link (shown on mouseover).
33+
3134
## Example 1
3235
This example renders a simple link within a `<div`-tag
3336

@@ -50,7 +53,7 @@ This example renders a link without a specific link-text, so it wraps the rest o
5053

5154
```ruby
5255
div id: "foo", class: "bar" do
53-
link path: "https://matestack.org" do
56+
link path: "https://matestack.org", title: "The matestack website" do
5457
plain "Here"
5558
end
5659
end
@@ -59,7 +62,7 @@ end
5962
returns
6063

6164
```html
62-
<div id="foo" class="bar">
65+
<div id="foo" class="bar" title="The matestack website">
6366
<a href="https://matestack.org">Here</a>
6467
</div>
6568
```
@@ -107,3 +110,37 @@ returns
107110
</a>
108111
</div>
109112
```
113+
114+
## Example 5 - path from symbol
115+
This example renders a link with a get request to any within your Rails application. In case you want to switch between pages within one specific matestack app, using the `transition` component probably is a better idea though!
116+
117+
```ruby
118+
div id: "foo", class: "bar" do
119+
link path: :inline_edit_path, text: 'Click to edit'
120+
end
121+
```
122+
123+
returns
124+
125+
```html
126+
<div id="foo" class="bar">
127+
<a href="/inline_edit">Click to edit</a>
128+
</div>
129+
```
130+
131+
## Example 6 - path from symbol with params
132+
You can also dynamically create `paths` from symbols and params, as displayed below:
133+
134+
```ruby
135+
div id: "foo", class: "bar" do
136+
link path: :single_endpoint_path, params: {number: 1}, text: 'Call API endpoint 1'
137+
end
138+
```
139+
140+
returns
141+
142+
```html
143+
<div id="foo" class="bar">
144+
<a href="/api/single_endpoint/1">Call API endpoint 1</a>
145+
</div>
146+
```

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+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "matestack-ui-core",
3-
"version": "0.6.0",
3+
"version": "0.7.2.1",
44
"private": true,
55
"dependencies": {
66
"axios": "^0.18.1",

spec/dummy/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
scope :api do
4040
get 'data', to: 'api#data'
41+
get 'data/:number', to: 'api#single_endpoint', as: "single_endpoint"
4142
end
4243

4344
end

spec/dummy/yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,14 @@ locate-path@^2.0.0:
35143514
p-locate "^2.0.0"
35153515
path-exists "^3.0.0"
35163516

3517+
locate-path@^3.0.0:
3518+
version "3.0.0"
3519+
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
3520+
integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==
3521+
dependencies:
3522+
p-locate "^3.0.0"
3523+
path-exists "^3.0.0"
3524+
35173525
lodash._reinterpolate@^3.0.0:
35183526
version "3.0.0"
35193527
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"

spec/usage/components/img_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
class ExamplePage < Matestack::Ui::Page
99
def response
1010
components {
11+
# simple image
1112
img path: 'matestack-logo.png', width: 500, height: 300, alt: "logo"
13+
# using usemap
14+
img path: 'matestack-logo.png', width: 500, height: 300, alt: "otherlogo", usemap: "#newmap"
1215
}
1316
end
1417
end
1518

1619
visit '/example'
1720

1821
expect(page).to have_xpath("//img[contains(@src,'matestack-logo') and @alt='logo' and @width='500' and @height='300']")
22+
expect(page).to have_xpath("//img[contains(@src,'matestack-logo') and @alt='otherlogo' and @width='500' and @height='300' and @usemap='\#newmap']")
1923
end
2024
end

spec/usage/components/link_spec.rb

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ExamplePage < Matestack::Ui::Page
3737
def response
3838
components {
3939
div id: "foo", class: "bar" do
40-
link path: "https://matestack.org" do
40+
link path: "https://matestack.org", title: "The matestack website" do
4141
plain 'here'
4242
end
4343
end
@@ -53,7 +53,7 @@ def response
5353

5454
expected_static_output = <<~HTML
5555
<div id="foo" class="bar">
56-
<a href="https://matestack.org">here</a>
56+
<a href="https://matestack.org" title="The matestack website">here</a>
5757
</div>
5858
HTML
5959

@@ -125,4 +125,58 @@ def response
125125
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
126126
end
127127

128+
it 'Example 5 - Rails Routing using symbols' do
129+
130+
class ExamplePage < Matestack::Ui::Page
131+
132+
def response
133+
components {
134+
div id: "foo", class: "bar" do
135+
link text: 'Click', path: :inline_edit_path
136+
end
137+
}
138+
end
139+
140+
end
141+
142+
visit "/example"
143+
144+
static_output = page.html
145+
146+
expected_static_output = <<~HTML
147+
<div id="foo" class="bar">
148+
<a href="/my_app/inline_edit">Click</a>
149+
</div>
150+
HTML
151+
152+
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
153+
end
154+
155+
it 'Example 6 - Rails Routing using symbols with params' do
156+
157+
class ExamplePage < Matestack::Ui::Page
158+
159+
def response
160+
components {
161+
div id: "foo", class: "bar" do
162+
link path: :single_endpoint_path, params: {number: 1}, text: 'Call API endpoint 1'
163+
end
164+
165+
}
166+
end
167+
168+
end
169+
visit "/example"
170+
171+
static_output = page.html
172+
173+
expected_static_output = <<~HTML
174+
<div id="foo" class="bar">
175+
<a href="/api/data/1">Call API endpoint 1</a>
176+
</div>
177+
HTML
178+
179+
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
180+
end
181+
128182
end

0 commit comments

Comments
 (0)