mix-rails-videos 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Videos
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Videos'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,5 @@
1
+ module Admix
2
+ class VideosController < Admix::InheritedController
3
+
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class VideosController < ApplicationController
2
+
3
+ def index
4
+ @videos = Video.most_recent.all
5
+ end
6
+
7
+ def show
8
+ @video = Video.find(params[:id])
9
+ end
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ module Admix
2
+ class VideosDatagrid
3
+ include Datagrid
4
+
5
+ scope do
6
+ Video.most_recent
7
+ end
8
+
9
+ column :thumb, header: I18n.t('videos.fields.thumb') do |video|
10
+ ActionController::Base.helpers.image_tag(video.thumb)
11
+ end
12
+
13
+ column :title, header: I18n.t('videos.fields.title')
14
+
15
+ column :published_at, header: I18n.t('videos.fields.published_at') do |video|
16
+ video.published_at.strftime('%d/%m/%Y')
17
+ end
18
+
19
+ include Admix::TableActions
20
+ end
21
+ end
@@ -0,0 +1,83 @@
1
+ class Video
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Slug
5
+
6
+ scope :most_recent, order_by(published_at: -1, name: 1)
7
+
8
+ field :url, type: String
9
+ field :title, type: String
10
+ field :description, type: String
11
+ field :title, type: String
12
+ field :likes, type: Integer
13
+ field :dislikes, type: Integer
14
+ field :views, type: Integer
15
+ field :youtube_code, type: String
16
+ field :published_at, type: Time
17
+ field :seconds, type: Integer
18
+ field :category, type: String
19
+ field :active, type: Boolean, default: true
20
+
21
+ validates :url, presence: true, youtube: true
22
+
23
+ slug :title, history: true do |video|
24
+ video.title.parameterize
25
+ end
26
+
27
+ after_validation :insert_youtube_data
28
+
29
+ def insert_youtube_data
30
+ if self.errors.blank?
31
+ yt_code = self.extract_youtube_code
32
+
33
+ video = Youtube::Video.find(scope: yt_code, params: {v: '2'})
34
+ video = video.entry.first
35
+
36
+ self.title = video.title
37
+ self.description = video.group.description
38
+ self.seconds = video.group.duration.seconds
39
+ self.views = video.statistics.viewCount
40
+ self.likes = video.rating.last.numLikes
41
+ self.dislikes = video.rating.last.numDislikes
42
+ self.published_at = video.published.to_time
43
+ self.youtube_code = yt_code
44
+ self.category = video.group.category
45
+ end
46
+ end
47
+
48
+ # Atualmente validando URLs nos formatos:
49
+ # http://www.youtube.com/watch?v=9bZkp7q19f0
50
+ # TODO adicionar formato http://youtu.be/9bZkp7q19f0
51
+ def extract_youtube_code
52
+ url = self.url
53
+
54
+ url = URI(url)
55
+ query = CGI.parse(url.query)
56
+ query['v'].first
57
+ end
58
+
59
+ def iframe(params = {})
60
+ defaults = {
61
+ width: '100%',
62
+ height: '400'
63
+ }
64
+ params = defaults.merge(params)
65
+ "<iframe width='#{params[:width]}' height='#{params[:height]}' src='http://www.youtube-nocookie.com/embed/#{self.youtube_code}?rel=0' frameborder='0' allowfullscreen></iframe>"
66
+ end
67
+
68
+ def thumb(type = :p)
69
+ thumbs = {
70
+ # 120x90
71
+ p: 'http://i.ytimg.com/vi/:code/default.jpg',
72
+ # 320x180
73
+ m: 'http://i.ytimg.com/vi/:code/mqdefault.jpg',
74
+ # 480x360
75
+ g: 'http://i.ytimg.com/vi/:code/hqdefault.jpg',
76
+ # 640x480
77
+ gg: 'http://i.ytimg.com/vi/:code/sddefault.jpg'
78
+ }
79
+
80
+ thumbs[type].sub(':code', self.youtube_code)
81
+ end
82
+
83
+ end
@@ -0,0 +1 @@
1
+ = f.input :url
@@ -0,0 +1,20 @@
1
+ .container
2
+ %h3.fb.white.p= @video.title
3
+ .video-wrapper.p
4
+ != @video.iframe height: 410, width: 670
5
+ .video-details
6
+ .row
7
+ .span5.white
8
+ = raw(sanitize(simple_format(@video.description), :tags => %w(br p)))
9
+ .span2.ta-r
10
+ %h4 visualizações
11
+ %p= number_to_human @video.views
12
+
13
+ %h4 likes
14
+ %p= number_to_human @video.likes
15
+
16
+ %h4 dislikes
17
+ %p= number_to_human @video.dislikes
18
+
19
+ %a{href:@video.url, target: :blank} Ver no Youtube
20
+
@@ -0,0 +1,12 @@
1
+ - description = video.description.split.slice(0, 20).join(" ")
2
+ - description = raw(sanitize(simple_format(description), :tags => %w(br p)))
3
+ %li
4
+ .row
5
+ .span7
6
+ %a{:href => video_path(video)}
7
+ = image_tag video.thumb(:m)
8
+ .span8.offset1
9
+ %h3.fb.white=h truncate video.title, length: 27
10
+ %p= description
11
+ %a{:href => video_path(video)} Ver detalhes
12
+
@@ -0,0 +1,14 @@
1
+ %h3.fb.white.p= video.title
2
+ .video-wrapper.p
3
+ != video.iframe height: 410
4
+ .video-details
5
+ .row
6
+ .span10.white
7
+ = raw(sanitize(simple_format(video.description), :tags => %w(br p)))
8
+ .span6.ta-r
9
+ %h4 visualizações
10
+ %p= number_to_human video.views
11
+ %h4 likes
12
+ %p= number_to_human video.likes
13
+ %a{href:video.url, target: :blank} Ver no Youtube
14
+
@@ -0,0 +1,9 @@
1
+ - content_for(:videos_content) do
2
+ - if @videos.length > 0
3
+ %ul.list.sequential
4
+ = render @videos
5
+ - else
6
+ %p.muted
7
+ Ainda não há videos disponíveis
8
+
9
+ = render template: 'templates/videos/index'
@@ -0,0 +1,3 @@
1
+ - content_for(:video_content) do
2
+ = render partial: 'video_show', locals: {video: @video}
3
+ = render template: 'templates/videos/show'
@@ -0,0 +1,8 @@
1
+ pt-BR:
2
+ videos:
3
+ video: 'Vídeo'
4
+ videos: 'Vídeos'
5
+ fields:
6
+ title: 'Título'
7
+ published_at: 'Publicado em'
8
+ thumb: 'Imagem'
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ resources :videos, only: [:index, :show]
3
+
4
+ namespace :admix do
5
+ resources :videos
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require "mix-rails-videos/engine"
2
+ require "simple_youtube"
3
+
4
+ module MixRailsVideos
5
+ end
@@ -0,0 +1,19 @@
1
+ module MixRailsVideos
2
+ class Engine < ::Rails::Engine
3
+ def navigation
4
+ if defined? Admix
5
+
6
+ Admix::Navigation::NavBar.post_menu do
7
+ Admix::Navigation::NavBar.find(:content) do |menu|
8
+ menu.submenu do |submenu|
9
+ submenu.key = :videos
10
+ submenu.title = I18n.t 'videos.videos'
11
+ submenu.url = 'admix_videos_url'
12
+ end
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module MixRailsVideos
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 10
5
+ TINY = 2
6
+ PRE = nil
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :videos do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mix-rails-videos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rafael Garcia
9
+ - Sadjow Medeiros Leão
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-22 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.2.11
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 3.2.11
31
+ - !ruby/object:Gem::Dependency
32
+ name: simple_youtube
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 3.0.0
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
47
+ description: This is the videos module of mix-rails
48
+ email:
49
+ - rafbgarcia@gmail.com
50
+ - sadjow@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - app/controllers/admix/videos_controller.rb
56
+ - app/controllers/videos_controller.rb
57
+ - app/models/admix/videos_datagrid.rb
58
+ - app/models/video.rb
59
+ - app/views/admix/videos/_show.html.haml
60
+ - app/views/admix/videos/_form_fields.html.haml
61
+ - app/views/videos/index.html.haml
62
+ - app/views/videos/_video_show.html.haml
63
+ - app/views/videos/show.html.haml
64
+ - app/views/videos/_video.html.haml
65
+ - config/locales/videos.pt-BR.yml
66
+ - config/routes.rb
67
+ - lib/tasks/videos_tasks.rake
68
+ - lib/mix-rails-videos.rb
69
+ - lib/mix-rails-videos/version.rb
70
+ - lib/mix-rails-videos/engine.rb
71
+ - MIT-LICENSE
72
+ - Rakefile
73
+ - README.rdoc
74
+ homepage: https://github.com/mixinternet/mix-rails
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: 3410722501246175296
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: 3410722501246175296
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.24
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: This is the videos module of mix-rails
104
+ test_files: []