Skip to content

Commit c5af04e

Browse files
Merge branch 'develop' into add_object_component
2 parents fdb3614 + 5b2a975 commit c5af04e

File tree

5 files changed

+77
-27
lines changed

5 files changed

+77
-27
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
= video_tag(@tag_attributes, ActionController::Base.helpers.asset_path(options[:path]), height: options[:height], width: options[:width], preload: options[:preload], autoplay: options[:autoplay], muted: options[:muted], playsinline: options[:playsinline], loop: options[:loop], controls: options[:controls])
1+
%video{@tag_attributes}
2+
%source{:src => @source, :type => @type}
3+
Your browser does not support the video tag.
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
module Matestack::Ui::Core::Video
22
class Video < Matestack::Ui::Core::Component::Static
33

4-
REQUIRED_KEYS = [:path]
4+
REQUIRED_KEYS = [:path, :type]
5+
6+
def setup
7+
@tag_attributes.merge!({
8+
autoplay: options[:autoplay],
9+
controls: options[:controls],
10+
height: options[:height],
11+
loop: options[:loop],
12+
muted: options[:muted],
13+
playsinline: options[:playsinline],
14+
preload: options[:preload],
15+
width: options[:width]
16+
})
17+
18+
@source = ActionController::Base.helpers.asset_path(options[:path])
19+
@type = "video/#{@options[:type]}"
20+
end
521

622
end
723
end

docs/components/video.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,56 @@
22

33
Show [specs](/spec/usage/components/video_spec.rb)
44

5-
The HTML video tag implemented in ruby.
5+
The HTML video tag implemented in Ruby.
66

77
## Parameters
8-
The video tag takes a mandatory path argument and can take a number of optional configuration params.
8+
The video component takes mandatory path and type arguments and can take a number of optional configuration params.
99

10-
#### # path
11-
Expects a string with the source to the video. It looks for the video in the `assets/videos` folder and uses the standard Rails asset pipeline.
10+
#### # autoplay (optional)
11+
Expects a boolean and specifies whether the video should start playing as soon as it is ready.
1212

13-
#### # id, class
14-
Like most of the core components, you can give a video an id and a class.
13+
#### # controls (optional)
14+
Expects a boolean and specifies whether the video controls (play/pause button etc) should be displayed.
1515

1616
#### # height (optional)
1717
Expects an integer with the height of the video in px.
1818

19-
#### # width (optional)
20-
Expects an integer with the width of the video in px.
19+
#### # id, class (optional)
20+
Like most of the core components, you can give a video an id and a class.
2121

22-
#### # alt (optional)
23-
Expects a string with the alt text the video should have.
22+
#### # loop (optional)
23+
Expects a boolean and specifies whether the video will start over again every time it is finished.
2424

25-
#### # preload
26-
Expects a string (`auto`, `metadata` or `none`) and specifies whether the whole video/only metadata/nothing should be loaded on pageload. Default (if not specified) depends on the client's browser.
25+
#### # muted (optional)
26+
Expects a boolean and specifies whether the audio output of the video should be muted.
2727

28-
#### # autoplay
29-
Expects a boolean and specifies whether the video should start playing as soon as it is ready.
28+
#### # path
29+
Expects a string with the source to the video. It looks for the video in the `assets/videos` folder and uses the standard Rails asset pipeline.
3030

31-
#### # muted
32-
Expects a boolean and specifies whether the audio output of the video should be muted.
31+
#### # type
32+
Expects a string with the type to the video.
3333

34-
#### # playsinline
34+
#### # playsinline (optional)
3535
Expects a boolean and specifies whether the video should be played inline on iOS Safari.
3636

37-
#### # loop
38-
Expects a boolean and specifies whether the video will start over again every time it is finished.
37+
#### # preload (optional)
38+
Expects a string (`auto`, `metadata` or `none`) and specifies whether the whole video/only metadata/nothing should be loaded on pageload. Default (if not specified) depends on the client's browser.
3939

40-
#### # controls
41-
Expects a boolean and specifies whether the video controls (play/pause button etc) should be displayed.
40+
#### # width (optional)
41+
Expects an integer with the width of the video in px.
42+
43+
## Example
44+
45+
46+
```ruby
47+
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300
48+
```
49+
50+
returns
51+
52+
```HTML
53+
<video height='300' width='500'>
54+
<source src='/assets/corgi-[...].mp4' type='video/mp4'>
55+
Your browser does not support the video tag.
56+
</video>
57+
```
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
//= link_tree ../images
22
//= link_directory ../javascripts .js
33
//= link_directory ../stylesheets .css
4-
//= link matestack_ui_core_manifest.js

spec/usage/components/video_spec.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@
33

44
describe 'Video Component', type: :feature, js: true do
55

6-
it 'Renders a video tag on the page' do
6+
it 'Renders a simple video tag on the page' do
77
class ExamplePage < Matestack::Ui::Page
88
def response
99
components {
10-
video path: 'corgi.mp4', width: 500, height: 300
10+
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300
1111
}
1212
end
1313
end
1414

1515
visit '/example'
16-
expect(page).to have_xpath("//video[contains(@src,'corgi.mp4') and @width='500' and @height='300']")
16+
17+
expect(page).to have_xpath("//video[@width='500' and @height='300']")
18+
expect(page).to have_content('Your browser does not support the video tag.')
19+
end
20+
21+
it 'Renders a video tag with more attributes on the page' do
22+
class ExamplePage < Matestack::Ui::Page
23+
def response
24+
components {
25+
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300, autoplay: true, controls: true, loop: true, muted: true, playsinline: false, preload: 'auto'
26+
}
27+
end
28+
end
29+
30+
visit '/example'
31+
32+
expect(page).to have_xpath("//video[@width='500' and @height='300' and @autoplay and @controls and @loop and @muted and @preload='auto']")
33+
expect(page).to have_content('Your browser does not support the video tag.')
1734
end
1835
end

0 commit comments

Comments
 (0)