sinatra-videoman 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/sinatra/videoman/locales/bg.yml +14 -0
- data/lib/sinatra/videoman/locales/en.yml +14 -0
- data/lib/sinatra/videoman/middleware.rb +81 -59
- data/lib/sinatra/videoman/models/video.rb +3 -0
- data/lib/sinatra/videoman/rake.rb +25 -0
- data/lib/sinatra/videoman/tasks.rake +8 -0
- data/lib/sinatra/videoman/version.rb +1 -1
- data/lib/sinatra/videoman/views/edit.erb +6 -0
- data/lib/sinatra/videoman/views/list.erb +1 -0
- data/lib/sinatra/videoman/views/upload.erb +22 -21
- data/lib/sinatra/videoman/views/video.erb +10 -0
- data/lib/sinatra/videoman/views/video_link.erb +6 -0
- data/lib/sinatra/videoman/views/watch.erb +1 -0
- data/lib/sinatra/videoman.rb +15 -16
- data/sinatra-videoman.gemspec +2 -0
- metadata +38 -4
- data/lib/sinatra/videoman/views/index.erb +0 -1
- data/lib/sinatra/videoman/views/show.erb +0 -10
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjE4YTY5MzIxZWE3ZTMyZTg2MDRjZWY2ODAxZjMxNTVjMzBlZmIyMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWIxNGI0ZmRmZGEzMGNjMTFlZTdiOWRjMzA2ODAxOWIwY2Y5NjFlYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2FkMjA3ODc5NDgzZWMyNjE5YWIzMmNlYzNkZTMyZDZiOGM4NTUzZjYyMzI3
|
10
|
+
ZjlhOGFjMjRiMzE3MmU4ODU4M2MwMGNjMWJkNjgzYzRlYzQ5MzhlYzMwMzMy
|
11
|
+
ZDhlZjExZmI3NGIwZjNjMTYwNjFmOTZmMmNmY2MwMjNmMzVlMzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDcwMmMyNGQ2MWYwZmJkZTRlMDE4ZjNiYzEyMTRjNWNiMzY2NDM5MjYzMTE4
|
14
|
+
ODMwYjRjZWUyOWVjN2JmZDk0NTZhYTkzNDg5YTc1NDI0ZGE3MzAwNGIwNGVh
|
15
|
+
NTk2Njk2YjA4ZjMxMDBmMzhmOGNhNjdlNWI2ZWVhODZkNzI3NTA=
|
@@ -0,0 +1,14 @@
|
|
1
|
+
en:
|
2
|
+
title: Заглавие
|
3
|
+
description: Описание
|
4
|
+
thumbnail: Миниатюра
|
5
|
+
submit: Изпращане
|
6
|
+
upload: Качване
|
7
|
+
video_files: Видео Файлове
|
8
|
+
video: Видео
|
9
|
+
add_field: Добавяна на полета
|
10
|
+
video_tag_unsupported: Браузърът ви не поддържа HTML5 видеа.
|
11
|
+
vide_not_found: Видеото не беше намерено!
|
12
|
+
video_deleted: Видеото изтрито успешно!
|
13
|
+
video_uploaded: Видеото качено успешно!
|
14
|
+
video_edited: Видеото обновено успешно!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
en:
|
2
|
+
title: Title
|
3
|
+
description: Description
|
4
|
+
thumbnail: Thumbnail
|
5
|
+
submit: Submit
|
6
|
+
upload: Upload
|
7
|
+
video_files: Video Files
|
8
|
+
video: Video
|
9
|
+
add_field: Add Fields
|
10
|
+
video_tag_unsupported: Your browser does not support video tags.
|
11
|
+
vide_not_found: Could not find the video you are looking for!
|
12
|
+
video_deleted: Successfully deleted video!
|
13
|
+
video_updated: Successfully uploaded video!
|
14
|
+
video_edited: Successfully edited video!
|
@@ -1,78 +1,100 @@
|
|
1
1
|
module Sinatra
|
2
2
|
module Videoman
|
3
|
-
|
3
|
+
module Middleware
|
4
4
|
include Manager
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
7
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__)+'/locales', '*.yml')]
|
8
|
+
I18n.backend.load_translations
|
9
|
+
I18n.enforce_available_locales = true
|
10
|
+
I18n.default_locale = Manager.config[:default_locale]
|
11
|
+
|
12
|
+
def self.registered(app)
|
13
|
+
app.register Sinatra::Partial
|
14
|
+
app.set :partial_template_engine, :erb
|
15
|
+
|
16
|
+
app.get '/videos/upload/?' do
|
17
|
+
erb 'videos/upload'.to_sym
|
18
|
+
end
|
9
19
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
app.post '/videos/upload' do
|
21
|
+
video = Video.new(params[:video])
|
22
|
+
params[:video_files].each do |file|
|
23
|
+
file = VideoFile.new(:file => file, :content_type => file[:type])
|
24
|
+
if file.valid?
|
25
|
+
video.video_files << file
|
26
|
+
file.save!
|
27
|
+
Manager.call :after_file_upload, [file]
|
28
|
+
else
|
29
|
+
Manager.call :after_file_upload_failure, [request, response]
|
30
|
+
flash[:error] = file.errors.messages
|
31
|
+
redirect '/videos/upload'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
if video.valid? && video.video_files.size >= 1
|
35
|
+
video.save!
|
36
|
+
Manager.call :after_video_save, [video, request, response]
|
37
|
+
flash[:notice] = I18n.t 'video_uploaded'
|
38
|
+
redirect Manager.config[:after_video_save_path]
|
18
39
|
else
|
19
|
-
Manager.call :
|
20
|
-
flash[:error] =
|
40
|
+
Manager.call :after_video_save_failure, [request, response]
|
41
|
+
flash[:error] = video.errors.messages
|
21
42
|
redirect '/videos/upload'
|
22
43
|
end
|
23
44
|
end
|
24
|
-
if video.valid? && video.video_files.size >= 1
|
25
|
-
video.save!
|
26
|
-
Manager.call :after_video_save, [video, request, response]
|
27
|
-
flash[:notice] = Manager.config[:after_video_save_msg]
|
28
|
-
redirect Manager.config[:after_video_save_path]
|
29
|
-
else
|
30
|
-
Manager.call :after_video_save_failure, [request, response]
|
31
|
-
flash[:error] = video.errors.messages
|
32
|
-
redirect '/videos/upload'
|
33
|
-
end
|
34
|
-
end
|
35
45
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
46
|
+
app.get '/videos/watch/:id/?' do
|
47
|
+
@video = Video.find_by(id: params[:id])
|
48
|
+
if @video
|
49
|
+
erb 'videos/watch'.to_sym
|
50
|
+
else
|
51
|
+
I18n.t 'video_not_found'
|
52
|
+
end
|
53
|
+
end
|
40
54
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
55
|
+
app.get '/videos/edit/:id/?' do
|
56
|
+
@video = Video.find_by(id: params[:id])
|
57
|
+
if @video
|
58
|
+
erb 'videos/edit'.to_sym
|
59
|
+
else
|
60
|
+
I18n.t 'video_not_found'
|
61
|
+
end
|
62
|
+
end
|
45
63
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
64
|
+
app.post '/videos/edit/:id' do
|
65
|
+
video = Video.find(params[:id])
|
66
|
+
if video.update_attributes(params)
|
67
|
+
video.save
|
68
|
+
Manager.call :after_video_update, [video, request, response]
|
69
|
+
flash[:notice] = I18n.t 'video_edited'
|
70
|
+
redirect Manager.config[:after_video_update_path]
|
71
|
+
else
|
72
|
+
Manager.call :after_video_update_failure, [video, request, response]
|
73
|
+
flash[:error] = video.errors.messages
|
74
|
+
redirect "/videos/edit/#{video.id}"
|
75
|
+
end
|
58
76
|
end
|
59
|
-
end
|
60
77
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
app.post '/videos/delete/:id' do
|
79
|
+
video = Video.find_by(id: params[:id])
|
80
|
+
if video
|
81
|
+
Manager.call :before_video_delete, [video, request, response]
|
82
|
+
video.thumbnail.remove!
|
83
|
+
video.video_files.each do |file|
|
84
|
+
file.file.remove!
|
85
|
+
file.destroy!
|
86
|
+
end
|
87
|
+
video.destroy!
|
88
|
+
Manager.call :after_video_delete, [request, response]
|
89
|
+
flash[:notice] = I18n.t 'video_deleted'
|
90
|
+
end
|
91
|
+
redirect Manager.config[:after_video_delete_path]
|
69
92
|
end
|
70
|
-
redirect Manager.config[:after_delete_path]
|
71
|
-
end
|
72
93
|
|
73
|
-
|
74
|
-
|
75
|
-
|
94
|
+
app.get '/videos/?' do
|
95
|
+
@video_links = Video.all
|
96
|
+
erb 'videos/list'.to_sym
|
97
|
+
end
|
76
98
|
end
|
77
99
|
end
|
78
100
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module Videoman
|
5
|
+
module Tasks
|
6
|
+
def self.install_views_task views_dir
|
7
|
+
current_path = File.expand_path(File.dirname(__FILE__))
|
8
|
+
Dir.foreach(current_path + '/views') do |item|
|
9
|
+
next if item == '.' or item == '..'
|
10
|
+
File.open(File.join(current_path, 'views', item), 'r') do |file|
|
11
|
+
if !File.exists?(File.join(views_dir, item))
|
12
|
+
File.open(File.join(views_dir, item), 'w') do |view|
|
13
|
+
while line = file.gets
|
14
|
+
view.write line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
load 'sinatra/videoman/tasks.rake'
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<form method="post" action="/videos/edit/<%= @video.id %>">
|
2
|
+
<p><%= I18n.t 'title' %>: <input type="text" value=<%= @video.title %> name="title" /></p>
|
3
|
+
<p><%= I18n.t 'description' %>: <input type="text" value=<%= @video.description %> name="description" /></p>
|
4
|
+
<p><%= I18n.t 'thumbnail' %>: <input type="file" value=<%= @video.thumbnail.url%> name="thumbnail" /></p>
|
5
|
+
<input type="submit" value=<%= I18n.t 'submit' %> />
|
6
|
+
</form>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= partial 'videos/video_link'.to_sym, :collection => @video_links%>
|
@@ -1,36 +1,37 @@
|
|
1
1
|
<script type='text/javascript'>
|
2
2
|
function addFields(){
|
3
|
-
|
4
|
-
var container = document.getElementById("video_input_fields");
|
5
|
-
// Append a node with a random text
|
3
|
+
var container = document.getElementById("video_files");
|
6
4
|
container.appendChild(document.createTextNode("Video: "));
|
7
|
-
// Create an <input> element, set its type and name attributes
|
8
5
|
var input = document.createElement("input");
|
9
6
|
input.type = "file";
|
10
7
|
input.name = "video_files[]";
|
11
8
|
container.appendChild(input);
|
12
|
-
// Append a line break
|
13
9
|
container.appendChild(document.createElement("br"));
|
14
10
|
}
|
15
11
|
</script>
|
16
12
|
<%= flash[:error] %>
|
17
13
|
<%= flash[:notice] %>
|
18
14
|
<form id="video_form" enctype="multipart/form-data" method="post" action="/videos/upload">
|
19
|
-
<fieldset id="
|
20
|
-
<legend
|
21
|
-
<
|
22
|
-
<input id="file" type="file" name="video_files[]" required /></br>
|
15
|
+
<fieldset id="video_files">
|
16
|
+
<legend><%= I18n.t 'video_files' %></legend>
|
17
|
+
<%= I18n.t 'video' %>: <input type="file" name="video_files[]" required /></br>
|
23
18
|
</fieldset>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
<table border="0">
|
20
|
+
<tr>
|
21
|
+
<td><label for="title"><%= I18n.t 'title' %>:</label></td>
|
22
|
+
<td><input id="title" type="text" name="video[title]" placeholder="Video title" required /></td>
|
23
|
+
</tr>
|
24
|
+
<tr>
|
25
|
+
<td><label for="description"><%= I18n.t 'description' %>:</label></td>
|
26
|
+
<td><input id="description" type="text" name="video[description]" placeholder="Video description" required /></td>
|
27
|
+
</tr>
|
28
|
+
<tr>
|
29
|
+
<td><label for="thumbnail"><%= I18n.t 'thumbnail' %>:</label></td>
|
30
|
+
<td><input id="thumbnail" type="file" name="video[thumbnail]" required /></td>
|
31
|
+
</tr>
|
32
|
+
<tr>
|
33
|
+
<td><input type="submit" value=<%= I18n.t 'upload' %> /></td>
|
34
|
+
<td><input type="button" value=<%= I18n.t 'add_field' %> onclick="addFields()" /></td>
|
35
|
+
</tr>
|
36
|
+
</table>
|
36
37
|
</form>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h3><%= video.title %></h3>
|
2
|
+
<video width="640" height="360" controls>
|
3
|
+
<% video.video_files.each do |source| %>
|
4
|
+
<source src=<%= source.file.url %> type=<%= source.content_type %> />
|
5
|
+
<% end %>
|
6
|
+
<%= I18n.t 'video_tag_not_supported' %>
|
7
|
+
</video>
|
8
|
+
<div id="description">
|
9
|
+
<%= video.description %>
|
10
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= partial 'videos/video'.to_sym, :locals => {:video => @video} %>
|
data/lib/sinatra/videoman.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require "sinatra/videoman/version"
|
2
|
-
require "
|
2
|
+
require "sinatra/flash"
|
3
3
|
require "bcrypt"
|
4
4
|
require "sinatra/base"
|
5
5
|
require "active_record"
|
6
6
|
require "carrierwave"
|
7
|
+
require "i18n"
|
8
|
+
require "i18n/backend/fallbacks"
|
7
9
|
|
8
10
|
module Sinatra
|
9
11
|
module Videoman
|
10
12
|
module Manager
|
11
13
|
@@config = {
|
14
|
+
:default_locale => :en,
|
15
|
+
|
12
16
|
:video_upload_dir => nil,
|
13
17
|
:video_file_extensions => %w(ogv webm mp4),
|
14
18
|
:max_video_file_size => 400,
|
@@ -18,13 +22,8 @@ module Sinatra
|
|
18
22
|
:max_thumb_file_size => 2,
|
19
23
|
|
20
24
|
:after_video_save_path => '/',
|
21
|
-
:
|
22
|
-
|
23
|
-
:after_update_path => '/',
|
24
|
-
:after_update_msg => 'Successfully updated video!',
|
25
|
-
|
26
|
-
:after_delete_path => '/',
|
27
|
-
:after_delete_msg => 'Successfully deleted video!',
|
25
|
+
:after_video_update_path => '/',
|
26
|
+
:after_video_delete_path => '/',
|
28
27
|
}
|
29
28
|
@@callbacks = {}
|
30
29
|
|
@@ -70,20 +69,20 @@ module Sinatra
|
|
70
69
|
self.register :after_video_save_failure, &block
|
71
70
|
end
|
72
71
|
|
73
|
-
def self.
|
74
|
-
self.register :
|
72
|
+
def self.after_video_update &block
|
73
|
+
self.register :after_video_update, &block
|
75
74
|
end
|
76
75
|
|
77
|
-
def self.
|
78
|
-
self.register :
|
76
|
+
def self.after_video_update_failure &block
|
77
|
+
self.register :after_video_update_failure, &block
|
79
78
|
end
|
80
79
|
|
81
|
-
def self.
|
82
|
-
self.register :
|
80
|
+
def self.before_video_delete &block
|
81
|
+
self.register :before_video_delete, &block
|
83
82
|
end
|
84
83
|
|
85
|
-
def self.
|
86
|
-
self.register :
|
84
|
+
def self.after_video_delete &block
|
85
|
+
self.register :after_video_delete, &block
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
data/sinatra-videoman.gemspec
CHANGED
@@ -22,8 +22,10 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
|
24
24
|
spec.add_runtime_dependency "sinatra"
|
25
|
+
spec.add_runtime_dependency "sinatra-partial"
|
25
26
|
spec.add_runtime_dependency "activerecord"
|
26
27
|
spec.add_runtime_dependency "protected_attributes"
|
27
28
|
spec.add_runtime_dependency "bcrypt-ruby"
|
28
29
|
spec.add_runtime_dependency "carrierwave"
|
30
|
+
spec.add_runtime_dependency "i18n"
|
29
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-videoman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dobromir Ivanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sinatra-partial
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activerecord
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - ! '>='
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: i18n
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Sinatra video manager
|
112
140
|
email:
|
113
141
|
- dobromir0ivanov@gmail.com
|
@@ -121,16 +149,22 @@ files:
|
|
121
149
|
- README.md
|
122
150
|
- Rakefile
|
123
151
|
- lib/sinatra/videoman.rb
|
152
|
+
- lib/sinatra/videoman/locales/bg.yml
|
153
|
+
- lib/sinatra/videoman/locales/en.yml
|
124
154
|
- lib/sinatra/videoman/middleware.rb
|
125
155
|
- lib/sinatra/videoman/models/video.rb
|
126
156
|
- lib/sinatra/videoman/models/video_file.rb
|
157
|
+
- lib/sinatra/videoman/rake.rb
|
158
|
+
- lib/sinatra/videoman/tasks.rake
|
127
159
|
- lib/sinatra/videoman/thumb_uploader.rb
|
128
160
|
- lib/sinatra/videoman/version.rb
|
129
161
|
- lib/sinatra/videoman/video_uploader.rb
|
130
162
|
- lib/sinatra/videoman/views/edit.erb
|
131
|
-
- lib/sinatra/videoman/views/
|
132
|
-
- lib/sinatra/videoman/views/show.erb
|
163
|
+
- lib/sinatra/videoman/views/list.erb
|
133
164
|
- lib/sinatra/videoman/views/upload.erb
|
165
|
+
- lib/sinatra/videoman/views/video.erb
|
166
|
+
- lib/sinatra/videoman/views/video_link.erb
|
167
|
+
- lib/sinatra/videoman/views/watch.erb
|
134
168
|
- sinatra-videoman.gemspec
|
135
169
|
homepage: ''
|
136
170
|
licenses:
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= partial :show, :collection => @videos %>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<h3><%= @video.title %></h3>
|
2
|
-
<video width="320" height="240" controls>
|
3
|
-
<% @video.video_files.each do |source| %>
|
4
|
-
<source src=<%= source.file.url %> type=<%= source.content_type %> />
|
5
|
-
<% end %>
|
6
|
-
Your browser does not support the video tag.
|
7
|
-
</video>
|
8
|
-
<div id="description">
|
9
|
-
<%= @video.description %>
|
10
|
-
</div>
|