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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDY4Mjk4NjI4MDM3MjFiNGI2NzAzMWI2M2JjMTQ2NzIzZGIwYWRiNw==
4
+ YjE4YTY5MzIxZWE3ZTMyZTg2MDRjZWY2ODAxZjMxNTVjMzBlZmIyMg==
5
5
  data.tar.gz: !binary |-
6
- MGM3ZDdkNzI0NDI5ZGI2ZDY1NWEwYWFmYzI1ZDJlYjg4OWMzYmRlNg==
6
+ YWIxNGI0ZmRmZGEzMGNjMTFlZTdiOWRjMzA2ODAxOWIwY2Y5NjFlYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODRmYjViN2Q0ZTg4YzY2ZmU0ZGQxMWFkYzk3MzQ2MzVhZWQ4NGYwNDY0Nzhm
10
- NjI0NmNlNWZiMmFhMDMyYjU2YWFiYjJlNGYwYTJhODNjMDE5NGFkMjkxNGM0
11
- NWM0NjAxOTRiMDZmYTg1N2U0MmQxN2VmMjkxY2QwYjczOGJmMmI=
9
+ Y2FkMjA3ODc5NDgzZWMyNjE5YWIzMmNlYzNkZTMyZDZiOGM4NTUzZjYyMzI3
10
+ ZjlhOGFjMjRiMzE3MmU4ODU4M2MwMGNjMWJkNjgzYzRlYzQ5MzhlYzMwMzMy
11
+ ZDhlZjExZmI3NGIwZjNjMTYwNjFmOTZmMmNmY2MwMjNmMzVlMzg=
12
12
  data.tar.gz: !binary |-
13
- NzNlZGQ2NzZmOGU1ZmNjMTE5MzkxZDdjNzMxZDE2OTg2YTdmOTE0OTM5YmZj
14
- NzEzZDAzZTM4ZjZhNGI5NjZmN2JiYzM5N2RiYTdhYzVjNDcwNGNlOThjNTdi
15
- Njg0ZGRlZTA5ODExOThlMTQyM2Q4NzFjMWM4NThjMmRjNDI5MDc=
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
- class Middleware < Sinatra::Base
3
+ module Middleware
4
4
  include Manager
5
5
 
6
- get '/videos/upload/?' do
7
- erb :upload
8
- end
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
- post '/videos/upload' do
11
- video = Video.new(params[:video])
12
- params[:video_files].each do |file|
13
- file = VideoFile.new(:file => file, :content_type => file[:type])
14
- if file.valid?
15
- video.video_files << file
16
- file.save!
17
- Manager.call :after_file_upload, [file]
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 :after_file_upload_failure, [request, response]
20
- flash[:error] = file.errors.messages
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
- get '/videos/show/:id/?' do
37
- @video = Video.find(params[:id])
38
- erb :show
39
- end
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
- get '/videos/edit/:id/?' do
42
- @video = Video.find(params[:id])
43
- erb :edit
44
- end
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
- post '/videos/edit/:id' do
47
- video = Video.find(params[:id])
48
- video.update_atributes(params)
49
- if video.valid?
50
- video.save
51
- Manager.call :after_update, [video, request, response]
52
- flash[:notice] = Manager.config[:after_update_msg]
53
- redirect Manager.config[:after_update_path]
54
- else
55
- Manager.call :after_update_failure, [video, request, response]
56
- flash[:error] = video.errors.messages
57
- redirect Manager.config[:after_update_failure_path]
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
- post '/videos/delete/:id' do
62
- video = Video.find(params[:id])
63
- Manager.call :before_delete, [video, request, response]
64
- if video
65
- video.video.remove!
66
- video.delete
67
- Manager.call :after_delete, [request, response]
68
- flash[:notice] = Manager.config[:after_delete_msg]
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
- get '/videos/' do
74
- @videos = Video.all
75
- erb :index
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
@@ -6,6 +6,9 @@ require 'sinatra/videoman/thumb_uploader.rb'
6
6
 
7
7
  class Video < ActiveRecord::Base
8
8
  include Sinatra::Videoman
9
+
10
+ attr_accessible :title, :description, :thumbnail
11
+
9
12
  mount_uploader :thumbnail, ThumbUploader
10
13
  has_many :video_files
11
14
 
@@ -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,8 @@
1
+ require 'rake'
2
+
3
+ namespace :video_views do
4
+ desc 'Copy view files'
5
+ task :install do
6
+ Sinatra::Videoman::Tasks.install_views_task ENV["VIEWS_DIR"]
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Videoman
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -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
- // Container <div> where dynamic content will be placed
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="video_input_fields">
20
- <legend>Video files</legend>
21
- <label for="file">Video:</label>
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
- <label for="title">Title:</label>
26
- <input id="title" type="text" name="video[title]" placeholder="Video title" required /><br />
27
-
28
- <label for="description">Description:</label>
29
- <input id="description" type="text" name="video[description]" placeholder="Video description" required /><br />
30
-
31
- <label for="thumbnail">Thumbnail:</label>
32
- <input id="thumbnail" type="file" name="video[thumbnail]" required /><br />
33
-
34
- <input type="submit" value="Upload" />
35
- <input type="button" value="Add file" onclick="addFields()" />
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,6 @@
1
+ <div>
2
+ <a href=<%= "videos/watch/#{video_link.id}" %>>
3
+ <img src=<%= video_link.thumbnail.url %> width="120" height="90" />
4
+ <%= video_link.title %>
5
+ </a>
6
+ </div>
@@ -0,0 +1 @@
1
+ <%= partial 'videos/video'.to_sym, :locals => {:video => @video} %>
@@ -1,14 +1,18 @@
1
1
  require "sinatra/videoman/version"
2
- require "rack-flash"
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
- :after_video_save_msg => 'Successfully uploaded video!',
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.after_update &block
74
- self.register :after_update, &block
72
+ def self.after_video_update &block
73
+ self.register :after_video_update, &block
75
74
  end
76
75
 
77
- def self.after_update_failure &block
78
- self.register :after_update_failure, &block
76
+ def self.after_video_update_failure &block
77
+ self.register :after_video_update_failure, &block
79
78
  end
80
79
 
81
- def self.before_delete &block
82
- self.register :after_delete, &block
80
+ def self.before_video_delete &block
81
+ self.register :before_video_delete, &block
83
82
  end
84
83
 
85
- def self.after_delete &block
86
- self.register :after_delete, &block
84
+ def self.after_video_delete &block
85
+ self.register :after_video_delete, &block
87
86
  end
88
87
  end
89
88
  end
@@ -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.1
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-01-06 00:00:00.000000000 Z
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/index.erb
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>