phocoder-rails 0.0.33
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +46 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +44 -0
- data/LICENSE.txt +20 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +56 -0
- data/VERSION +5 -0
- data/app/controllers/phocoder_controller.rb +118 -0
- data/app/helpers/phocoder_helper.rb +320 -0
- data/app/models/encodable_job.rb +91 -0
- data/app/views/phocoder/_offline_video_embed.html.erb +19 -0
- data/app/views/phocoder/_thumbnail_update.html.erb +3 -0
- data/app/views/phocoder/_video_embed.html.erb +23 -0
- data/app/views/phocoder/multi_thumbnail_update.json.erb +7 -0
- data/app/views/phocoder/thumbnail_update.js.erb +9 -0
- data/config/routes.rb +8 -0
- data/lib/generators/phocoder_rails/model_update_generator.rb +52 -0
- data/lib/generators/phocoder_rails/scaffold_generator.rb +94 -0
- data/lib/generators/phocoder_rails/setup_generator.rb +33 -0
- data/lib/generators/phocoder_rails/templates/controller.rb +71 -0
- data/lib/generators/phocoder_rails/templates/helper.rb +5 -0
- data/lib/generators/phocoder_rails/templates/migration.rb +24 -0
- data/lib/generators/phocoder_rails/templates/model.rb +20 -0
- data/lib/generators/phocoder_rails/templates/model_migration.rb +56 -0
- data/lib/generators/phocoder_rails/templates/model_thumbnail.rb +5 -0
- data/lib/generators/phocoder_rails/templates/model_update_migration.rb +64 -0
- data/lib/generators/phocoder_rails/templates/phocodable.yml +28 -0
- data/lib/generators/phocoder_rails/templates/views/_form.html.erb.tt +23 -0
- data/lib/generators/phocoder_rails/templates/views/index.html.erb.tt +26 -0
- data/lib/generators/phocoder_rails/templates/views/new.html.erb.tt +5 -0
- data/lib/generators/phocoder_rails/templates/views/show.html.erb.tt +12 -0
- data/lib/phocoder_rails.rb +12 -0
- data/lib/phocoder_rails/acts_as_phocodable.rb +1153 -0
- data/lib/phocoder_rails/engine.rb +24 -0
- data/lib/phocoder_rails/errors.rb +46 -0
- data/phocoder-rails.gemspec +219 -0
- data/public/images/building.gif +0 -0
- data/public/images/error.png +0 -0
- data/public/images/play_small.png +0 -0
- data/public/images/storing.gif +0 -0
- data/public/images/waiting.gif +0 -0
- data/public/javascripts/phocodable.js +110 -0
- data/public/javascripts/video-js-2.0.2/.DS_Store +0 -0
- data/public/javascripts/video-js-2.0.2/LICENSE.txt +165 -0
- data/public/javascripts/video-js-2.0.2/README.markdown +202 -0
- data/public/javascripts/video-js-2.0.2/demo-subtitles.srt +13 -0
- data/public/javascripts/video-js-2.0.2/demo.html +101 -0
- data/public/javascripts/video-js-2.0.2/skins/hu.css +116 -0
- data/public/javascripts/video-js-2.0.2/skins/tube.css +111 -0
- data/public/javascripts/video-js-2.0.2/skins/vim.css +89 -0
- data/public/javascripts/video-js-2.0.2/video-js.css +242 -0
- data/public/javascripts/video-js-2.0.2/video.js +1758 -0
- data/public/stylesheets/phocodable.css +19 -0
- data/spec/controllers/phocoder_controller_spec.rb +123 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +7 -0
- data/spec/dummy/app/controllers/images_controller.rb +72 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/images_helper.rb +5 -0
- data/spec/dummy/app/models/image.rb +20 -0
- data/spec/dummy/app/models/image_thumbnail.rb +5 -0
- data/spec/dummy/app/models/image_upload.rb +11 -0
- data/spec/dummy/app/views/images/_form.html.erb +23 -0
- data/spec/dummy/app/views/images/index.html.erb +26 -0
- data/spec/dummy/app/views/images/new.html.erb +5 -0
- data/spec/dummy/app/views/images/show.html.erb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +18 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +8 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +40 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/migrate/001_create_image_uploads.rb +37 -0
- data/spec/dummy/db/migrate/20110523165213_add_parent_type_to_image_uploads.rb +11 -0
- data/spec/dummy/db/migrate/20110523165522_create_encodable_jobs.rb +24 -0
- data/spec/dummy/db/migrate/20111101024507_create_images.rb +56 -0
- data/spec/dummy/db/schema.rb +99 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +239 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/jquery-1.6.4.js +9046 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +175 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/engine_spec.rb +12 -0
- data/spec/fixtures/big_eye_tiny.jpg +0 -0
- data/spec/fixtures/octologo.png +0 -0
- data/spec/fixtures/test.txt +2 -0
- data/spec/fixtures/video-test.mov +0 -0
- data/spec/helpers/phocoder_helper_spec.rb +421 -0
- data/spec/integration/navigation_spec.rb +10 -0
- data/spec/models/acts_as_phocodable_spec.rb +664 -0
- data/spec/models/encodable_job_spec.rb +50 -0
- data/spec/phocoder_rails_spec.rb +8 -0
- data/spec/routing/phocoder_routing_spec.rb +19 -0
- data/spec/spec_helper.rb +75 -0
- metadata +375 -0
data/.autotest
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/bin/ruby
|
2
|
+
#require 'redgreen'
|
3
|
+
require 'autotest/timestamp'
|
4
|
+
|
5
|
+
#module Autotest::GnomeNotify
|
6
|
+
# def self.notify title, msg, img
|
7
|
+
# system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000"
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Autotest.add_hook :ran_command do |at|
|
11
|
+
# image_root = "~/.autotest_images"
|
12
|
+
# results = [at.results].flatten.join("\n")
|
13
|
+
# results.gsub!(/\\e\[\d+m/,'')
|
14
|
+
# output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?/)
|
15
|
+
# puts output.inspect
|
16
|
+
# if output
|
17
|
+
# if $~[2].to_i > 0
|
18
|
+
# notify "FAIL", "#{output}", "#{image_root}/fail.png"
|
19
|
+
# else
|
20
|
+
# notify "Pass", "#{output}", "#{image_root}/pass.png"
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
|
25
|
+
|
26
|
+
Autotest.add_hook :initialize do |autotest|
|
27
|
+
autotest.add_mapping(%r%^spec/(app|lib)/.*rb$%) do|filename, _|
|
28
|
+
filename
|
29
|
+
end
|
30
|
+
|
31
|
+
#autotest.add_mapping(%r%^.*rb$%) do|filename, _|
|
32
|
+
# filename
|
33
|
+
#end
|
34
|
+
|
35
|
+
autotest.add_exception(%r%spec/dummy/app%)
|
36
|
+
autotest.add_exception(%r%spec/dummy/db%)
|
37
|
+
autotest.add_exception(%r%spec/dummy/lib%)
|
38
|
+
autotest.add_exception(%r%spec/dummy/config%)
|
39
|
+
autotest.add_exception(%r%spec/dummy/log%)
|
40
|
+
autotest.add_exception(%r%spec/dummy/public%)
|
41
|
+
autotest.add_exception(%r%\.git%)
|
42
|
+
end
|
43
|
+
|
44
|
+
#end
|
45
|
+
|
46
|
+
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", ">=3.0.0"
|
4
|
+
gem "capybara", ">= 0.3.9"
|
5
|
+
gem "webrat"
|
6
|
+
|
7
|
+
#puts "phocoder-rails : RUBY_VERSION = #{RUBY_VERSION}"
|
8
|
+
#puts RUBY_VERSION < '1.9'
|
9
|
+
|
10
|
+
#
|
11
|
+
|
12
|
+
#developing against postgres for now since I have an old version of SQLite3
|
13
|
+
#gem 'pg'
|
14
|
+
|
15
|
+
gem 'phocoder-rb'
|
16
|
+
gem 'zencoder'
|
17
|
+
gem 'aws-s3', :require => 'aws/s3'
|
18
|
+
#gem "spawn", :git => "git://github.com/jagthedrummer/spawn.git"
|
19
|
+
gem "spawn", :git => 'git://github.com/tra/spawn', :branch => "edge"
|
20
|
+
#if RUBY_VERSION < '1.9'
|
21
|
+
# gem "ruby-debug", ">= 0.10.3"
|
22
|
+
#end
|
23
|
+
|
24
|
+
#gem "rspec", "~> 2.1.0"
|
25
|
+
#gem "rspec-rails", ">= 2.0.0.beta"
|
26
|
+
|
27
|
+
group :development do
|
28
|
+
gem 'rspec-rails', '2.4.1'
|
29
|
+
gem "bundler", "~> 1.0.0"
|
30
|
+
gem "jeweler", "~> 1.5.1"
|
31
|
+
gem "rcov", ">= 0"
|
32
|
+
end
|
33
|
+
|
34
|
+
group :test do
|
35
|
+
gem "sqlite3-ruby", :require => "sqlite3"
|
36
|
+
gem 'rspec', '2.4.0'
|
37
|
+
gem 'rspec-rails', '2.4.1'
|
38
|
+
gem "bundler", "~> 1.0.0"
|
39
|
+
gem "jeweler", "~> 1.5.1"
|
40
|
+
gem "rcov", ">= 0"
|
41
|
+
gem 'autotest', '4.4.4'
|
42
|
+
gem 'redgreen', '1.2.2'
|
43
|
+
gem "webmock"
|
44
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jeremy Green
|
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/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 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
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated this engine with docs found here:
|
2
|
+
# http://nepalonrails.com/blog/2010/09/Creating-a-Rails-engine-with-tests-and-a-dummy-rails-application-embedded-in-it
|
3
|
+
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler'
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
require 'rake'
|
15
|
+
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
19
|
+
gem.name = "phocoder-rails"
|
20
|
+
gem.homepage = "http://github.com/jagthedrummer/phocoder-rails"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = %Q{Rails engine for easy integration with phocoder.com}
|
23
|
+
gem.description = %Q{Rails engine for easy integration with phocoder.com}
|
24
|
+
gem.email = "jagthedrummer@gmail.com"
|
25
|
+
gem.authors = ["Jeremy Green"]
|
26
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
27
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
28
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
29
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
30
|
+
end
|
31
|
+
Jeweler::RubygemsDotOrgTasks.new
|
32
|
+
|
33
|
+
require 'rspec/core'
|
34
|
+
require 'rspec/core/rake_task'
|
35
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
36
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
40
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
41
|
+
spec.rcov = true
|
42
|
+
spec.spec_opts = ['--color']
|
43
|
+
spec.rcov_opts = ['--exclude', '^spec,/gems/,/\.bundler/']
|
44
|
+
end
|
45
|
+
|
46
|
+
task :default => :spec
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "phocoder-rails #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
class PhocoderController < ApplicationController
|
2
|
+
|
3
|
+
protect_from_forgery :except=>[:phocoder_notification_update,:zencoder_notification_update,:thumbnail_update,:multi_thumbnail_update]
|
4
|
+
|
5
|
+
def phocoder_notification_update
|
6
|
+
full_params = nil
|
7
|
+
if false and RUBY_VERSION.match /1.8/ #disable this for now
|
8
|
+
# Sometimes Rails does not like to honor either the 'Accept' or 'Content Type' headers.
|
9
|
+
# It also wan't follow :format => js, or :format => json and just refuses to parse the body.
|
10
|
+
# This is a brute force way around the problem for now.
|
11
|
+
# It would be nice to know what's at the root of this problem.
|
12
|
+
# The TVN Media project (rarearth) is a prime example.
|
13
|
+
payload = symbolize_keys(ActiveSupport::JSON.decode(request.body))
|
14
|
+
logger.debug "the params = #{params.to_json} - #{payload.to_json}"
|
15
|
+
full_params = params.merge payload
|
16
|
+
else
|
17
|
+
full_params = params
|
18
|
+
end
|
19
|
+
#@image_upload = full_params[:class].constantize.update_from_phocoder(full_params)
|
20
|
+
EncodableJob.update_from_phocoder(full_params)
|
21
|
+
# This may have been due to a screwy Rails upgrade.
|
22
|
+
# 3.0.3 seems to break this and make routes all screwy
|
23
|
+
#@image_upload = params[:class].constantize.update_from_phocoder(params)
|
24
|
+
|
25
|
+
|
26
|
+
#@image_upload = ImageUpload.update_from_phocoder(params)
|
27
|
+
respond_to do |format|
|
28
|
+
#format.html { render :json => {} }
|
29
|
+
format.json { render :json => {} }
|
30
|
+
#format.xml { render :xml => {} }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def zencoder_notification_update
|
36
|
+
full_params = nil
|
37
|
+
if false and RUBY_VERSION.match /1.8/ #disable this for now
|
38
|
+
# Sometimes Rails does not like to honor either the 'Accept' or 'Content Type' headers.
|
39
|
+
# It also wan't follow :format => js, or :format => json and just refuses to parse the body.
|
40
|
+
# This is a brute force way around the problem for now.
|
41
|
+
# It would be nice to know what's at the root of this problem.
|
42
|
+
# The TVN Media project (rarearth) is a prime example.
|
43
|
+
payload = symbolize_keys(ActiveSupport::JSON.decode(request.body))
|
44
|
+
logger.debug "the params = #{params.to_json} - #{payload.to_json}"
|
45
|
+
full_params = params.merge payload
|
46
|
+
else
|
47
|
+
full_params = params
|
48
|
+
end
|
49
|
+
#@image_upload = full_params[:class].constantize.update_from_zencoder(full_params)
|
50
|
+
EncodableJob.update_from_zencoder(full_params)
|
51
|
+
|
52
|
+
#@image_upload = ImageUpload.update_from_phocoder(params)
|
53
|
+
respond_to do |format|
|
54
|
+
#format.html { render :json => {} }
|
55
|
+
format.json { render :json => {} }
|
56
|
+
#format.xml { render :xml => {} }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def thumbnail_update
|
61
|
+
@img = Kernel.const_get(params[:class]).find params[:id]
|
62
|
+
@random = params[:random]
|
63
|
+
@live_vide = params[:live_video]
|
64
|
+
respond_to do |format|
|
65
|
+
format.js {}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def multi_thumbnail_update
|
70
|
+
@outputs = []
|
71
|
+
params[:encodables].each do |encodable|
|
72
|
+
# Format ex : Image_1_medium_db0ce8ba5d55c25eee7c767220d654fe
|
73
|
+
# Format is : class_id_thumbnail_random
|
74
|
+
match = encodable.match /^(.*)_(.*)_(.*)_(.*)$/
|
75
|
+
hash = {
|
76
|
+
:elem_id => encodable,
|
77
|
+
:class_name => match[1],
|
78
|
+
:id => match[2],
|
79
|
+
:thumbnail => match[3],
|
80
|
+
:random => match[4],
|
81
|
+
:encodable => Kernel.const_get(match[1]).find(match[2])
|
82
|
+
}
|
83
|
+
@outputs << hash
|
84
|
+
end
|
85
|
+
respond_to do |format|
|
86
|
+
format.json {}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
#thanks to http://grosser.it/2009/04/14/recursive-symbolize_keys/
|
92
|
+
def new_symbolize_keys hash
|
93
|
+
return hash if !hash.is_a?(Hash)
|
94
|
+
hash.symbolize_keys!
|
95
|
+
hash.values.select{|v| v.is_a? Hash}.each{|h| recursive_symbolize_keys!(h)}
|
96
|
+
end
|
97
|
+
|
98
|
+
# thanks to http://avdi.org/devblog/2009/07/14/recursively-symbolize-keys/
|
99
|
+
def symbolize_keys(hash)
|
100
|
+
puts "the hash = #{hash.class} : #{hash}"
|
101
|
+
return hash if !hash.is_a?(Hash)
|
102
|
+
hash.inject({}){|result, (key, value)|
|
103
|
+
new_key = case key
|
104
|
+
when String then key.to_sym
|
105
|
+
else key
|
106
|
+
end
|
107
|
+
new_value = case value
|
108
|
+
when Hash then symbolize_keys(value)
|
109
|
+
else value
|
110
|
+
end
|
111
|
+
result[new_key] = new_value
|
112
|
+
result
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
module PhocoderHelper
|
2
|
+
|
3
|
+
require 'active_support/secure_random'
|
4
|
+
|
5
|
+
def preview_reload_timeout
|
6
|
+
#time in ms between preview reloading
|
7
|
+
10000
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def phocoder_includes
|
12
|
+
tag = javascript_include_tag 'phocodable.js'
|
13
|
+
tag += "\n"
|
14
|
+
tag += stylesheet_link_tag 'phocodable.css'
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def phocoder_video_includes
|
19
|
+
tag = stylesheet_link_tag '/javascripts/video-js-2.0.2/video-js.css'
|
20
|
+
tag += "\n"
|
21
|
+
tag += javascript_include_tag 'video-js-2.0.2/video.js'
|
22
|
+
tag += "\n"
|
23
|
+
tag += %[<script type="text/javascript" charset="utf-8">VideoJS.setupAllWhenReady();</script>].html_safe
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def phocoder_link(text,file)
|
28
|
+
if file.encodable_status == "ready" or file.encodable_status == "s3"
|
29
|
+
link_to text, file.public_filename
|
30
|
+
else
|
31
|
+
text
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# for now we'll assume that a thumbnail is needed
|
37
|
+
# some files aren't displayable in a native way (NEF etc...)
|
38
|
+
#
|
39
|
+
def phocoder_thumbnail(encodable,thumbnail="small",live_video=true,options={})
|
40
|
+
|
41
|
+
if encodable.video?
|
42
|
+
return phocoder_video_thumbnail(encodable,thumbnail,live_video,options)
|
43
|
+
elsif encodable.image?
|
44
|
+
return phocoder_image_thumbnail(encodable,thumbnail,options)
|
45
|
+
else
|
46
|
+
return error_div("This #{encodable.class} is not an image or a video.")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# def old_phocoder_thumbnail(image_upload,thumbnail="small",live_video=true,options={})
|
51
|
+
# #get the details about this particular thumbnail size
|
52
|
+
# thumbnail_atts = image_upload.class.thumbnail_attributes_for thumbnail
|
53
|
+
# if ActsAsPhocodable.storeage_mode == "offline" and (thumbnail.nil? or !thumbnail_atts.blank?)
|
54
|
+
# return offline_phocoder_thumbnail(image_upload,thumbnail_atts,options)
|
55
|
+
# elsif image_upload.image?
|
56
|
+
# phocoder_image_thumbnail image_upload, thumbnail,options
|
57
|
+
# elsif (image_upload.video? and !live_video)
|
58
|
+
# tag = %[<span class="phocoder_video_poster">]
|
59
|
+
# tag += phocoder_image_thumbnail(image_upload, thumbnail,thumbnail_atts,options)
|
60
|
+
# tag += %[<img src="/images/play_small.png" alt="Play" width="25" height="25" class="play"/>]
|
61
|
+
# tag += "</span>"
|
62
|
+
# tag.html_safe
|
63
|
+
# elsif image_upload.video?
|
64
|
+
# phocoder_video_thumbnail image_upload, thumbnail,thumbnail_atts, options
|
65
|
+
# else # this seems to happen in some rare cases. I need to figure out which cases...
|
66
|
+
# image_tag "error.png"
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
|
70
|
+
|
71
|
+
# Passing a thumbnail is STRONGLY ADVISED
|
72
|
+
# Unless you are abosultely sure that you are only accepting web safe image formats you'll want to supply a thumbnail arg
|
73
|
+
#
|
74
|
+
def phocoder_image_thumbnail(image_upload,thumbnail="small",options={})
|
75
|
+
if ActsAsPhocodable.storeage_mode == "offline"
|
76
|
+
phocoder_image_offline(image_upload,thumbnail,options)
|
77
|
+
else
|
78
|
+
phocoder_image_online(image_upload,thumbnail,options)
|
79
|
+
end
|
80
|
+
#return display_image(image_upload,options) if thumbnail.blank?
|
81
|
+
#thumbnail = find_or_create_thumbnail(image_upload,thumbnail,options)
|
82
|
+
#return display_image_thumbnail(image_upload,thumbnail,options) if thumbnail
|
83
|
+
#return error_div "Could not find a thumbnail for: class=#{image_upload.class} thumbnail=#{thumbnail.to_json}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def phocoder_image_offline(image_upload,thumbnail="small",options={})
|
87
|
+
if !image_upload.web_safe?
|
88
|
+
error_div "#{image_upload.filename} can not be displayed directly because it is not web safe. Content type = #{image_upload.content_type}"
|
89
|
+
elsif thumbnail.blank?
|
90
|
+
image_tag(image_upload.public_url,options)
|
91
|
+
else
|
92
|
+
begin
|
93
|
+
# since we're in offline mode here we don't actually have files created for the thumbnail
|
94
|
+
# so we return an image with the path to the original, we don't care about encodable_status
|
95
|
+
thumbnail = find_thumbnail_attributes(image_upload,thumbnail,options)
|
96
|
+
image_tag image_upload.public_url, {:width => thumbnail[:width],:height => thumbnail[:height]}.merge(options)
|
97
|
+
rescue ActsAsPhocodable::ThumbnailAttributesNotFoundError
|
98
|
+
error_div "'#{thumbnail}' is not a valid thumbnail name or size string."
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def phocoder_image_online(image_upload,thumbnail="small",options={})
|
104
|
+
if thumbnail.blank? and !image_upload.web_safe?
|
105
|
+
error_div "#{image_upload.filename} can not be displayed directly because it is not web safe. Content type = #{image_upload.content_type}"
|
106
|
+
elsif thumbnail.blank? and !image_upload.ready?
|
107
|
+
# don't know width and height yet
|
108
|
+
image_tag(image_upload.public_url,options)
|
109
|
+
elsif thumbnail.blank?
|
110
|
+
# now we have width and height
|
111
|
+
image_tag(image_upload.public_url,options.merge(:width => image_upload.width, :height => image_upload.height))
|
112
|
+
elsif !image_upload.ready?
|
113
|
+
begin
|
114
|
+
# We can only look for attributes now to show a pending message with the correct dimensions
|
115
|
+
thumb_atts = find_thumbnail_attributes(image_upload,thumbnail,options)
|
116
|
+
pending_phocoder_thumbnail(image_upload,thumb_atts,false,options)
|
117
|
+
rescue ActsAsPhocodable::ThumbnailAttributesNotFoundError
|
118
|
+
error_div "'#{thumbnail}' is not a valid thumbnail name or size string."
|
119
|
+
end
|
120
|
+
else
|
121
|
+
begin
|
122
|
+
thumb = find_or_create_thumbnail(image_upload,thumbnail,options)
|
123
|
+
if thumb.ready?
|
124
|
+
image_tag thumb.public_url, {:width => thumb[:width],:height => thumb[:height]}.merge(options)
|
125
|
+
else
|
126
|
+
pending_phocoder_thumbnail(image_upload,thumb,false,options)
|
127
|
+
end
|
128
|
+
rescue ActsAsPhocodable::ThumbnailNotFoundError
|
129
|
+
error_div "'#{thumbnail}' is not a valid thumbnail name or size string."
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# def display_image(image_upload,options={})
|
135
|
+
# if ActsAsPhocodable.storeage_mode == "offline"
|
136
|
+
# offline_phocoder_image_thumbnail(image_upload,image_upload,options)
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
def find_thumbnail_attributes(image_upload,thumbnail,options)
|
140
|
+
if thumbnail.is_a? String
|
141
|
+
thumb_atts = image_upload.thumbnail_attributes_for(thumbnail)
|
142
|
+
elsif thumbnail.is_a? Hash
|
143
|
+
thumb_atts = thumbnail
|
144
|
+
end
|
145
|
+
thumb_atts
|
146
|
+
end
|
147
|
+
|
148
|
+
def find_or_create_thumbnail(image_upload,thumbnail="small",options={})
|
149
|
+
if thumbnail.is_a? String
|
150
|
+
thumb = image_upload.thumbnail_for(thumbnail)
|
151
|
+
end
|
152
|
+
thumb
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
# # image = the original upload
|
158
|
+
# # thumbnail = a record representing the dimensions of the thumbnail
|
159
|
+
# # options = some other stuff
|
160
|
+
# def display_image_thumbnail(image_upload,thumbnail,options)
|
161
|
+
# puts "Thumbnail = #{thumbnail.to_json}"
|
162
|
+
# if ActsAsPhocodable.storeage_mode == "offline"
|
163
|
+
# offline_phocoder_image_thumbnail(image_upload,thumbnail,options)
|
164
|
+
# elsif thumbnail.encodable_status != "ready"
|
165
|
+
# pending_phocoder_thumbnail(image_upload,thumbnail,false,options)
|
166
|
+
# else
|
167
|
+
# image_tag thumbnail.public_url, {:width => thumbnail[:width],:height => thumbnail[:height]}.merge(options)
|
168
|
+
# end
|
169
|
+
# end
|
170
|
+
|
171
|
+
# # A special handler when the mode is 'offline'
|
172
|
+
# # The thumbnail record will contain the proper dimensions, but the path will be no good.
|
173
|
+
# # This combines the path of the original with the dimensions of the original and serves from the local store.
|
174
|
+
# def offline_phocoder_image_thumbnail(photo,thumbnail_atts,options={})
|
175
|
+
# image_tag photo.local_url, {:width => thumbnail_atts[:width],:height => thumbnail_atts[:height]}.merge(options)
|
176
|
+
# #if thumbnail_atts.blank?
|
177
|
+
# # image_tag photo.local_url, options
|
178
|
+
# #elsif thumbnail_atts[:aspect_mode] == "stretch"
|
179
|
+
# #
|
180
|
+
# #else
|
181
|
+
# # "<div style='overflow:hidden;background:#ccc;width:#{thumbnail_atts[:width]}px;height:#{thumbnail_atts[:height]}px'>#{image_tag(photo.local_url,{:width => thumbnail_atts[:width]}.merge(options))}</div>".html_safe
|
182
|
+
# #end
|
183
|
+
# end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
# Thumbnail should either be an ActiveRecord or a Hash
|
188
|
+
def pending_phocoder_thumbnail(photo,thumbnail,options,live_video=false,spinner='waiting')
|
189
|
+
random = ActiveSupport::SecureRandom.hex(16)
|
190
|
+
Rails.logger.debug "======================================================"
|
191
|
+
Rails.logger.debug "building pending thumbnail for #{thumbnail.class} #{thumbnail.to_json}"
|
192
|
+
if thumbnail.is_a? Hash
|
193
|
+
thumb_name = thumbnail[:label]
|
194
|
+
else
|
195
|
+
thumb_name = thumbnail.thumbnail
|
196
|
+
end
|
197
|
+
width = thumbnail[:width]
|
198
|
+
height = thumbnail[:height]
|
199
|
+
|
200
|
+
elemId = "#{photo.class.to_s}_#{photo.id.to_s}_#{thumb_name}_#{random}"
|
201
|
+
|
202
|
+
tag = image_tag "#{spinner}.gif", :size=>"#{width}x#{height}", :id => elemId, "data-phocoder-waiting" => true
|
203
|
+
end
|
204
|
+
|
205
|
+
# def error_phocoder_thumbnail(photo,thumbnail,options,spinner='error')
|
206
|
+
# width = thumbnail.try :width
|
207
|
+
# height = thumbnail.try :height
|
208
|
+
# tag = image_tag "#{spinner}.gif", :size=>"#{width}x#{height}"
|
209
|
+
# end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
# # for now we'll assume that a thumbnail is needed
|
214
|
+
# # some files aren't displayable in a native way (NEF etc...)
|
215
|
+
# #
|
216
|
+
# def old_phocoder_image_thumbnail(image_upload,thumbnail="small",options={})
|
217
|
+
# puts "thumbnail = #{thumbnail}"
|
218
|
+
# thumbnail_atts = image_upload.class.thumbnail_attributes_for thumbnail
|
219
|
+
# if ActsAsPhocodable.storeage_mode == "offline" and (thumbnail.blank? or !thumbnail_atts.blank?)
|
220
|
+
# return offline_phocoder_thumbnail(image_upload,thumbnail_atts,options)
|
221
|
+
# elsif thumbnail.nil? and (image_upload.encodable_status == "ready")
|
222
|
+
# return image_tag image_upload.public_url, {:size=>"#{image_upload.width}x#{image_upload.height}"}.merge(options)
|
223
|
+
# elsif thumbnail_atts.blank?
|
224
|
+
# return error_div("'#{thumbnail}' is not a valid thumbnail size for #{image_upload.class}")
|
225
|
+
# elsif image_upload.encodable_status != "ready" #and image_upload.zencoder_status != "ready"
|
226
|
+
# puts "image_upload is not ready!!!!!!!!!!!!!!!!!!!!!!!!"
|
227
|
+
# return pending_phocoder_thumbnail(image_upload,thumbnail,false,thumbnail_atts)
|
228
|
+
# #else
|
229
|
+
# # return "<div class='notice'>Online mode is coming soon!</div>"
|
230
|
+
# end
|
231
|
+
#
|
232
|
+
# thumb = image_upload.thumbnail_for(thumbnail)
|
233
|
+
# if thumb.blank? or thumb.encodable_status != "ready"
|
234
|
+
# puts "thumb (#{thumb.to_json}) is not ready!!!!!!!!!!!!!!!!!!!!!!!!"
|
235
|
+
# #this happens if the main image has been notified, but not this thumbnail
|
236
|
+
# return pending_phocoder_thumbnail(image_upload,thumbnail,false,thumbnail_atts)
|
237
|
+
# end
|
238
|
+
# image_tag thumb.public_url, {:size=>"#{thumb.width}x#{thumb.height}"}.merge(options)
|
239
|
+
# end
|
240
|
+
|
241
|
+
|
242
|
+
def error_div(msg)
|
243
|
+
%[<div class="phocoder_error">#{msg}</div>].html_safe
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
# def offline_phocoder_thumbnail(image_upload,thumbnail_atts,options={})
|
248
|
+
# if image_upload.image?
|
249
|
+
# offline_phocoder_image_thumbnail(image_upload,thumbnail_atts,options)
|
250
|
+
# else
|
251
|
+
# offline_phocoder_video_embed(image_upload,thumbnail_atts,options)
|
252
|
+
# end
|
253
|
+
# end
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
def phocoder_video_thumbnail(image_upload,thumbnail="small",live_video = true,options={})
|
261
|
+
thumbnail_atts = image_upload.class.thumbnail_attributes_for thumbnail
|
262
|
+
if image_upload.encodable_status != 'ready'
|
263
|
+
#thumb = find_or_create_thumbnail(image_upload,thumbnail,options)
|
264
|
+
pending_phocoder_thumbnail(image_upload,thumbnail_atts,true,thumbnail_atts)
|
265
|
+
elsif live_video
|
266
|
+
phocoder_video_embed(image_upload,thumbnail_atts,options)
|
267
|
+
else # Video stuff needs work.
|
268
|
+
tag = %[<span class="phocoder_video_poster">]
|
269
|
+
tag += phocoder_image_thumbnail(image_upload, thumbnail,options)
|
270
|
+
tag += %[<img src="/images/play_small.png" alt="Play" width="25" height="25" class="play"/>]
|
271
|
+
tag += "</span>"
|
272
|
+
tag.html_safe
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
|
277
|
+
#def jquery_updater(photo,thumbnail,random)
|
278
|
+
# %[
|
279
|
+
# <script type="text/javascript">
|
280
|
+
# setTimeout(function() {
|
281
|
+
# $.ajax({ type: 'POST',
|
282
|
+
# url : '/phocoder/thumbnail_update.js',
|
283
|
+
# dataType : 'script',
|
284
|
+
# data : { class:'#{photo.class.to_s}', id:#{photo.id.to_s},thumbnail:'#{thumbnail}',random:'#{random}' }
|
285
|
+
# });
|
286
|
+
# },#{preview_reload_timeout});
|
287
|
+
# </script>
|
288
|
+
# ]
|
289
|
+
#end
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
#def prototype_updater(photo,thumbnail,random)
|
294
|
+
# %[
|
295
|
+
# <script type="text/javascript">
|
296
|
+
# setTimeout(function() {
|
297
|
+
# new Ajax.Request( '/phocoder/thumbnail_update', {
|
298
|
+
# evalScripts:true,
|
299
|
+
# parameters: { class:'#{photo.class.to_s}', id:#{photo.id.to_s},thumbnail:'#{thumbnail}',random:'#{random}' }
|
300
|
+
# });
|
301
|
+
# },#{preview_reload_timeout});
|
302
|
+
# </script>
|
303
|
+
# ]
|
304
|
+
#end
|
305
|
+
|
306
|
+
def phocoder_video_embed(image_upload,thumbnail_atts,options={} )
|
307
|
+
options.merge!(:video => image_upload, :width=>image_upload.calc_width(thumbnail_atts),:height=>image_upload.calc_height(thumbnail_atts))
|
308
|
+
render(:partial => 'phocoder/video_embed', :locals => options)
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
def offline_phocoder_video_embed(image_upload,thumbnail_atts,options={} )
|
313
|
+
options.merge!(:video => image_upload, :width=>image_upload.calc_width(thumbnail_atts),:height=>image_upload.calc_height(thumbnail_atts))
|
314
|
+
render(:partial => 'phocoder/offline_video_embed', :locals => options)
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
end
|