application_helper.rb
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- encoding : utf-8 -*-
module ApplicationHelper
def display_base_errors resource
return '' if (resource.errors.empty?) or (resource.errors[:base].empty?)
messages = resource.errors[:base].map { |msg| content_tag(:p, msg) }.join
html = <<-HTML
<div class="alert alert-error alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
#{messages}
</div>
HTML
html.html_safe
end
def bootstrap_class_for(flash_type)
case flash_type.to_s
when "success"
"alert-success" # Green
when "error"
"alert-danger" # Red
when "alert"
"alert-warning" # Yellow
when "notice"
"alert-info" # Blue
else
flash_type
end
end
def request_status_label(request)
classes = [ 'badge' ]
status = request.status
case status
when 'created'
when 'processing'
classes << 'badge-warning'
when 'error'
classes << 'badge-important'
when 'success'
classes << 'badge-success'
end
content_tag(:a, t(status, scope: 'status'), :class => classes,
:data => { 'toggle' => "tooltip" }, :title => request.response)
end
def html5_video_tag(url, id, classes, data_options = nil, *args)
options = args.first || {}
options[:id] = id
options[:class] = "video-js vjs-default-skin vjs-big-play-centered #{classes}"
options[:width] = 'auto'
options[:height] = 'auto'
options['data-setup'] = data_options if data_options != nil
content_tag(:video, options) do
if url.class == String
content_tag(:source, '', :src => (url + "?t=" + Time.now.getutc.to_i.to_s), :type => mimetype_from_url(url))
else
url.each do |v|
concat content_tag(:source, '', :src => (v + "?t=" + Time.now.getutc.to_i.to_s), :type => mimetype_from_url(v))
end
end
end
end
def mimetype_from_url(url)
return 'video/mp4' if url.split('.').last == 'mp4'
return 'video/webm' if url.split('.').last == 'webm'
'video/mp4'
end
def include_videojs_assets
content_for(:css) do
stylesheet_link_tag "http://vjs.zencdn.net/4.6/video-js.css"
end
content_for(:js) do
javascript_include_tag "http://vjs.zencdn.net/4.6/video.js"
end
end
end