Skip to content

Commit f14034d

Browse files
Update component & specs & docs
1 parent 4e005a0 commit f14034d

File tree

4 files changed

+71
-24
lines changed

4 files changed

+71
-24
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 => "video/mp4"}
3+
Your browser does not support the video tag.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,20 @@ class Video < Matestack::Ui::Core::Component::Static
33

44
REQUIRED_KEYS = [:path]
55

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+
end
20+
621
end
722
end

docs/components/video.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,53 @@
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. Right now, only the MP4 format is supported.
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 a mandatory path argument 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.
21+
22+
#### # loop (optional)
23+
Expects a boolean and specifies whether the video will start over again every time it is finished.
24+
25+
#### # muted (optional)
26+
Expects a boolean and specifies whether the audio output of the video should be muted.
2127

22-
#### # alt (optional)
23-
Expects a string with the alt text the video should have.
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.
30+
31+
#### # playsinline (optional)
32+
Expects a boolean and specifies whether the video should be played inline on iOS Safari.
2433

25-
#### # preload
34+
#### # preload (optional)
2635
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.
2736

28-
#### # autoplay
29-
Expects a boolean and specifies whether the video should start playing as soon as it is ready.
37+
#### # width (optional)
38+
Expects an integer with the width of the video in px.
3039

31-
#### # muted
32-
Expects a boolean and specifies whether the audio output of the video should be muted.
40+
## Example
3341

34-
#### # playsinline
35-
Expects a boolean and specifies whether the video should be played inline on iOS Safari.
3642

37-
#### # loop
38-
Expects a boolean and specifies whether the video will start over again every time it is finished.
43+
```ruby
44+
video path: 'corgi.mp4', width: 500, height: 300
45+
```
3946

40-
#### # controls
41-
Expects a boolean and specifies whether the video controls (play/pause button etc) should be displayed.
47+
returns
48+
49+
```HTML
50+
<video height='300' width='500'>
51+
<source src='/assets/corgi-[...].mp4' type='video/mp4'>
52+
Your browser does not support the video tag.
53+
</video>
54+
```

spec/usage/components/video_spec.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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 {
@@ -13,6 +13,23 @@ def response
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', 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)