sinatra-videoman 0.0.1a → 0.0.1

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
- NWJiMGEyYzdkNmZjMzJmYTg0ZmRmYjkxNjA5YWMxNjI5N2U4N2FmNQ==
4
+ NDY4Mjk4NjI4MDM3MjFiNGI2NzAzMWI2M2JjMTQ2NzIzZGIwYWRiNw==
5
5
  data.tar.gz: !binary |-
6
- ZmQ0NGI1YWQ3NjZjMWVkZmI5YTAwMzVjMDBiMjQ0NDgwYTQwZjI0YQ==
6
+ MGM3ZDdkNzI0NDI5ZGI2ZDY1NWEwYWFmYzI1ZDJlYjg4OWMzYmRlNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjcxOWQ2ZGI5MTViZjgwYmUyM2MxZThhNTAzMWMyMTg4M2JiOTRjOGJiNWE1
10
- NWZjZjUzYTU3MmY3OGNiOWIxOWNiNzhkYjRmOTA2MDU0YWQ4NzM2MjlhOTA4
11
- NmNmMjZiOTc3ZDA1OThkZGU1NjE4ZDljMWE1ODI1YTVmZTJmMDY=
9
+ ODRmYjViN2Q0ZTg4YzY2ZmU0ZGQxMWFkYzk3MzQ2MzVhZWQ4NGYwNDY0Nzhm
10
+ NjI0NmNlNWZiMmFhMDMyYjU2YWFiYjJlNGYwYTJhODNjMDE5NGFkMjkxNGM0
11
+ NWM0NjAxOTRiMDZmYTg1N2U0MmQxN2VmMjkxY2QwYjczOGJmMmI=
12
12
  data.tar.gz: !binary |-
13
- MjQ2NGRmODEzYmZiYzRlZWFjNWMzMDI1YmRiZmI4NmQyNzFiYWRmYzU1MzFk
14
- YWMxODhiMzE4NjdkYjhiNjA5M2U4NzcyYmRhNGM1N2JkNDFjYWQ2ZjYwYjU4
15
- OGE5YzY4ZDIxNmM2OTYyMmNmZDFkMzM3NGUyMmFhNWIyMzM5Yzk=
13
+ NzNlZGQ2NzZmOGU1ZmNjMTE5MzkxZDdjNzMxZDE2OTg2YTdmOTE0OTM5YmZj
14
+ NzEzZDAzZTM4ZjZhNGI5NjZmN2JiYzM5N2RiYTdhYzVjNDcwNGNlOThjNTdi
15
+ Njg0ZGRlZTA5ODExOThlMTQyM2Q4NzFjMWM4NThjMmRjNDI5MDc=
@@ -1,100 +1,78 @@
1
1
  module Sinatra
2
2
  module Videoman
3
- module Middleware
3
+ class Middleware < Sinatra::Base
4
4
  include Manager
5
5
 
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
6
+ get '/videos/upload/?' do
7
+ erb :upload
8
+ end
19
9
 
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]
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]
39
18
  else
40
- Manager.call :after_video_save_failure, [request, response]
41
- flash[:error] = video.errors.messages
19
+ Manager.call :after_file_upload_failure, [request, response]
20
+ flash[:error] = file.errors.messages
42
21
  redirect '/videos/upload'
43
22
  end
44
23
  end
45
-
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
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'
53
33
  end
34
+ end
54
35
 
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
36
+ get '/videos/show/:id/?' do
37
+ @video = Video.find(params[:id])
38
+ erb :show
39
+ end
63
40
 
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
76
- end
41
+ get '/videos/edit/:id/?' do
42
+ @video = Video.find(params[:id])
43
+ erb :edit
44
+ end
77
45
 
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]
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]
92
58
  end
59
+ end
93
60
 
94
- app.get '/videos/?' do
95
- @video_links = Video.all
96
- erb 'videos/list'.to_sym
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]
97
69
  end
70
+ redirect Manager.config[:after_delete_path]
71
+ end
72
+
73
+ get '/videos/' do
74
+ @videos = Video.all
75
+ erb :index
98
76
  end
99
77
  end
100
78
  end
@@ -6,9 +6,6 @@ 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
-
12
9
  mount_uploader :thumbnail, ThumbUploader
13
10
  has_many :video_files
14
11
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Videoman
3
- VERSION = "0.0.1a"
3
+ VERSION = "0.0.1"
4
4
  end
5
5
  end
@@ -1,6 +0,0 @@
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 :show, :collection => @videos %>
@@ -0,0 +1,10 @@
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>
@@ -1,37 +1,36 @@
1
1
  <script type='text/javascript'>
2
2
  function addFields(){
3
- var container = document.getElementById("video_files");
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
4
6
  container.appendChild(document.createTextNode("Video: "));
7
+ // Create an <input> element, set its type and name attributes
5
8
  var input = document.createElement("input");
6
9
  input.type = "file";
7
10
  input.name = "video_files[]";
8
11
  container.appendChild(input);
12
+ // Append a line break
9
13
  container.appendChild(document.createElement("br"));
10
14
  }
11
15
  </script>
12
16
  <%= flash[:error] %>
13
17
  <%= flash[:notice] %>
14
18
  <form id="video_form" enctype="multipart/form-data" method="post" action="/videos/upload">
15
- <fieldset id="video_files">
16
- <legend><%= I18n.t 'video_files' %></legend>
17
- <%= I18n.t 'video' %>: <input type="file" name="video_files[]" required /></br>
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>
18
23
  </fieldset>
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>
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()" />
37
36
  </form>
@@ -1,18 +1,14 @@
1
1
  require "sinatra/videoman/version"
2
- require "sinatra/flash"
2
+ require "rack-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"
9
7
 
10
8
  module Sinatra
11
9
  module Videoman
12
10
  module Manager
13
11
  @@config = {
14
- :default_locale => :en,
15
-
16
12
  :video_upload_dir => nil,
17
13
  :video_file_extensions => %w(ogv webm mp4),
18
14
  :max_video_file_size => 400,
@@ -22,8 +18,13 @@ module Sinatra
22
18
  :max_thumb_file_size => 2,
23
19
 
24
20
  :after_video_save_path => '/',
25
- :after_video_update_path => '/',
26
- :after_video_delete_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!',
27
28
  }
28
29
  @@callbacks = {}
29
30
 
@@ -69,20 +70,20 @@ module Sinatra
69
70
  self.register :after_video_save_failure, &block
70
71
  end
71
72
 
72
- def self.after_video_update &block
73
- self.register :after_video_update, &block
73
+ def self.after_update &block
74
+ self.register :after_update, &block
74
75
  end
75
76
 
76
- def self.after_video_update_failure &block
77
- self.register :after_video_update_failure, &block
77
+ def self.after_update_failure &block
78
+ self.register :after_update_failure, &block
78
79
  end
79
80
 
80
- def self.before_video_delete &block
81
- self.register :before_video_delete, &block
81
+ def self.before_delete &block
82
+ self.register :after_delete, &block
82
83
  end
83
84
 
84
- def self.after_video_delete &block
85
- self.register :after_video_delete, &block
85
+ def self.after_delete &block
86
+ self.register :after_delete, &block
86
87
  end
87
88
  end
88
89
  end
@@ -22,10 +22,8 @@ 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"
26
25
  spec.add_runtime_dependency "activerecord"
27
26
  spec.add_runtime_dependency "protected_attributes"
28
27
  spec.add_runtime_dependency "bcrypt-ruby"
29
28
  spec.add_runtime_dependency "carrierwave"
30
- spec.add_runtime_dependency "i18n"
31
29
  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.1a
4
+ version: 0.0.1
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-02-05 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ 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'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: activerecord
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +108,6 @@ dependencies:
122
108
  - - ! '>='
123
109
  - !ruby/object:Gem::Version
124
110
  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'
139
111
  description: Sinatra video manager
140
112
  email:
141
113
  - dobromir0ivanov@gmail.com
@@ -149,22 +121,16 @@ files:
149
121
  - README.md
150
122
  - Rakefile
151
123
  - lib/sinatra/videoman.rb
152
- - lib/sinatra/videoman/locales/bg.yml
153
- - lib/sinatra/videoman/locales/en.yml
154
124
  - lib/sinatra/videoman/middleware.rb
155
125
  - lib/sinatra/videoman/models/video.rb
156
126
  - lib/sinatra/videoman/models/video_file.rb
157
- - lib/sinatra/videoman/rake.rb
158
- - lib/sinatra/videoman/tasks.rake
159
127
  - lib/sinatra/videoman/thumb_uploader.rb
160
128
  - lib/sinatra/videoman/version.rb
161
129
  - lib/sinatra/videoman/video_uploader.rb
162
130
  - lib/sinatra/videoman/views/edit.erb
163
- - lib/sinatra/videoman/views/list.erb
131
+ - lib/sinatra/videoman/views/index.erb
132
+ - lib/sinatra/videoman/views/show.erb
164
133
  - 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
168
134
  - sinatra-videoman.gemspec
169
135
  homepage: ''
170
136
  licenses:
@@ -181,9 +147,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
147
  version: '0'
182
148
  required_rubygems_version: !ruby/object:Gem::Requirement
183
149
  requirements:
184
- - - ! '>'
150
+ - - ! '>='
185
151
  - !ruby/object:Gem::Version
186
- version: 1.3.1
152
+ version: '0'
187
153
  requirements: []
188
154
  rubyforge_project:
189
155
  rubygems_version: 2.1.11
@@ -1,14 +0,0 @@
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: Видеото обновено успешно!
@@ -1,14 +0,0 @@
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,23 +0,0 @@
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
- File.open(File.join(views_dir, item), 'w') do |view|
12
- while line = file.gets
13
- view.write line
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
23
- load 'sinatra/videoman/tasks.rake'
@@ -1,8 +0,0 @@
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 +0,0 @@
1
- <%= partial 'videos/video_link'.to_sym, :collection => @video_links%>
@@ -1,10 +0,0 @@
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>
@@ -1,6 +0,0 @@
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>
@@ -1 +0,0 @@
1
- <%= partial 'videos/video'.to_sym, :locals => {:video => @video} %>