Skip to content

Commit 9bf3c53

Browse files
Merge pull request #275 from basemate/add_object_component
Add object core component incl. docs&specs
2 parents dbb41ef + d389603 commit 9bf3c53

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%object{@tag_attributes}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Matestack::Ui::Core::Object
2+
class Object < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!({
5+
width: options[:width],
6+
height: options[:height],
7+
data: options[:data],
8+
form: options[:form],
9+
name: options[:name],
10+
type: options[:type],
11+
usemap: options[:usemap]
12+
})
13+
end
14+
end
15+
end

docs/components/object.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# matestack core component: Object
2+
3+
Show [specs](/spec/usage/components/object_spec.rb)
4+
5+
The HTML `<object>` tag implemented in Ruby.
6+
7+
## Parameters
8+
9+
This component can take 9 optional configuration params, but at least one of the `data` or `type` attribute **MUST** be defined.
10+
11+
#### # class (optional)
12+
Expects a string with all classes the `<object>` should have.
13+
14+
#### # data (optional)
15+
Expects a string that specifies the URL of the resource to be used by the `<object`.
16+
17+
#### # form (optional)
18+
Expects a string that contains one or more *form_id*-s to specify one or more forms the `<object>` belongs to.
19+
20+
#### # height (optional)
21+
Expects a number to specify the height of the `<object>`.
22+
23+
#### # id (optional)
24+
Expects a string with all ids the `<object>` should have.
25+
26+
#### # name (optional)
27+
Expects a string that specifies a name for the `<object>`.
28+
29+
#### # type (optional)
30+
Expects a string to specify the media type of data specified in the data attribute.
31+
32+
#### # usemap (optional)
33+
Expects a string to specify the name of a client-side image map to be used with the `<object>`.
34+
35+
#### # width (optional)
36+
Expects a number to specify the width of the `<object>`.
37+
38+
39+
## Example 1
40+
41+
```ruby
42+
object width: 400, height: 400, data: 'helloworld.swf'
43+
```
44+
45+
returns
46+
47+
```html
48+
<object width="400" height="400" data="helloworld.swf"></object>
49+
```
50+
51+
## Example 2
52+
53+
```ruby
54+
object id: 'my-id', class: 'my-class', width: 400, height: 400, data: 'helloworld.swf'
55+
```
56+
57+
returns
58+
59+
```html
60+
<object id="my-id" class="my-class" width="400" height="400" data="helloworld.swf"></object>
61+
```

spec/usage/components/object_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 'Object Component', type: :feature, js: true do
5+
6+
it 'Example 1' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
10+
def response
11+
components {
12+
# simple object
13+
object width: 400, height: 400, data: 'helloworld.swf'
14+
15+
# enhanced object
16+
object id: 'my-id', class: 'my-class', width: 400, height: 400, data: 'helloworld.swf'
17+
18+
# using all attributes
19+
object id: 'my-id', class: 'my-class', width: 400, height: 400, form: '#my_form', data: 'helloworld.swf', name: 'my_object', type: 'application/vnd.adobe.flash-movie', usemap: '#my_map'
20+
}
21+
end
22+
23+
end
24+
25+
visit '/example'
26+
27+
static_output = page.html
28+
29+
expected_static_output = <<~HTML
30+
<object data="helloworld.swf" height="400" width="400"></object>
31+
<object data="helloworld.swf" height="400" id="my-id" width="400" class="my-class"></object>
32+
<object data="helloworld.swf" form="#my_form" height="400" id="my-id" name="my_object" type="application/vnd.adobe.flash-movie" usemap="#my_map" width="400" class="my-class"></object>
33+
HTML
34+
35+
expect(stripped(static_output)).to include(stripped(expected_static_output))
36+
end
37+
38+
end

0 commit comments

Comments
 (0)