From 5b502e59d288e9aeb48bcd60e267604c88a6eb19 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos <81665687568@serpro-1541727.(none)> Date: Tue, 1 Oct 2013 18:30:47 -0300 Subject: [PATCH] Initial version of Video plugin --- plugins/video/README | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/controllers/video_plugin_admin_controller.rb | 5 +++++ plugins/video/controllers/video_plugin_module.rb | 3 +++ plugins/video/controllers/video_plugin_myprofile_controller.rb | 5 +++++ plugins/video/lib/.video_block.rb.swp | Bin 0 -> 12288 bytes plugins/video/lib/video_block.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/lib/video_plugin.rb | 19 +++++++++++++++++++ plugins/video/test/functional/display_content_plugin_admin_controller_test.rb | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/test/functional/display_content_plugin_myprofile_controller_test.rb | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/test/test_helper.rb | 1 + plugins/video/test/unit/video_block_test.rb | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/test/unit/video_plugin_test.rb | 9 +++++++++ plugins/video/views/box_organizer/_html5_video_block.rhtml | 3 +++ plugins/video/views/box_organizer/_iframe_video_block.rhtml | 1 + plugins/video/views/box_organizer/_video_block.rhtml | 11 +++++++++++ plugins/video/views/environment_design | 1 + plugins/video/views/profile_design | 1 + plugins/video/views/video_block.rhtml | 15 +++++++++++++++ 18 files changed, 662 insertions(+), 0 deletions(-) create mode 100644 plugins/video/README create mode 100644 plugins/video/controllers/video_plugin_admin_controller.rb create mode 100644 plugins/video/controllers/video_plugin_module.rb create mode 100644 plugins/video/controllers/video_plugin_myprofile_controller.rb create mode 100644 plugins/video/lib/.video_block.rb.swp create mode 100644 plugins/video/lib/video_block.rb create mode 100644 plugins/video/lib/video_plugin.rb create mode 100644 plugins/video/test/functional/display_content_plugin_admin_controller_test.rb create mode 100644 plugins/video/test/functional/display_content_plugin_myprofile_controller_test.rb create mode 100644 plugins/video/test/test_helper.rb create mode 100644 plugins/video/test/unit/video_block_test.rb create mode 100644 plugins/video/test/unit/video_plugin_test.rb create mode 100644 plugins/video/views/box_organizer/_html5_video_block.rhtml create mode 100644 plugins/video/views/box_organizer/_iframe_video_block.rhtml create mode 100644 plugins/video/views/box_organizer/_video_block.rhtml create mode 120000 plugins/video/views/environment_design create mode 120000 plugins/video/views/profile_design create mode 100644 plugins/video/views/video_block.rhtml diff --git a/plugins/video/README b/plugins/video/README new file mode 100644 index 0000000..1344ccb --- /dev/null +++ b/plugins/video/README @@ -0,0 +1,70 @@ +README - DisplayContent (DisplayContent Plugin) +================================ + +DisplayContent is a plugin to allow the user adds a block where you could choose any of your content for display it. + +The DisplayContent block will be available for all layout columns of communities, peole, enterprises and environments. + +All the articles choosen are displayed as a list with a link for the title and the lead content. + +If a Blog or a Folder is choosen the block will display all articles inside the blog or the folder. + +Galleries are not displayed in this block. + +INSTALL +======= + +Enable Plugin +------------- + +Also, you need to enable DisplayContent Plugin at you Noosfero: + +cd +./script/noosfero-plugins enable display_content + +Active Plugin +------------- + +As a Noosfero administrator user, go to administrator panel: + +- Click on "Enable/disable plugins" option +- Click on "Display Content Plugin" check-box + +DEVELOPMENT +=========== + +Noosfero uses jQuery 1.5.1 and the jsTree doesn't works fine with this jQuery version. +Until Noosfero upgrade its JQuery version to a newer one is necessary to load jQuery 1.8.3 inside plugin and apply some changes in jsTree to avoid jQuery conflit. + +Get the Display Content (Noosfero with Display Content Plugin) development repository: + +$ git clone https://gitorious.org/+noosfero/noosfero/display_content + +Running DisplayContent tests +-------------------- + +$ rake test:noosfero_plugins:display_content + + +Get Involved +============ + +If you found any bug and/or want to collaborate, please send an e-mail to leandronunes@gmail.com + +LICENSE +======= + +Copyright (c) The Author developers. + +See Noosfero license. + + +AUTHORS +======= + + Leandro Nunes dos Santos (leandronunes at gmail.com) + +ACKNOWLEDGMENTS +=============== + +The author have been supported by Serpro diff --git a/plugins/video/controllers/video_plugin_admin_controller.rb b/plugins/video/controllers/video_plugin_admin_controller.rb new file mode 100644 index 0000000..a11b9ed --- /dev/null +++ b/plugins/video/controllers/video_plugin_admin_controller.rb @@ -0,0 +1,5 @@ +class VideoPluginAdminController < AdminController + + append_view_path File.join(File.dirname(__FILE__) + '/../views') + +end diff --git a/plugins/video/controllers/video_plugin_module.rb b/plugins/video/controllers/video_plugin_module.rb new file mode 100644 index 0000000..1f79047 --- /dev/null +++ b/plugins/video/controllers/video_plugin_module.rb @@ -0,0 +1,3 @@ +module VideoPluginController + +end diff --git a/plugins/video/controllers/video_plugin_myprofile_controller.rb b/plugins/video/controllers/video_plugin_myprofile_controller.rb new file mode 100644 index 0000000..710af80 --- /dev/null +++ b/plugins/video/controllers/video_plugin_myprofile_controller.rb @@ -0,0 +1,5 @@ +class VideoPluginMyprofileController < MyProfileController + + append_view_path File.join(File.dirname(__FILE__) + '/../views') + +end diff --git a/plugins/video/lib/.video_block.rb.swp b/plugins/video/lib/.video_block.rb.swp new file mode 100644 index 0000000..f0515d9 Binary files /dev/null and b/plugins/video/lib/.video_block.rb.swp differ diff --git a/plugins/video/lib/video_block.rb b/plugins/video/lib/video_block.rb new file mode 100644 index 0000000..d4ec929 --- /dev/null +++ b/plugins/video/lib/video_block.rb @@ -0,0 +1,56 @@ +class VideoBlock < Block + + settings_items :url, :type => :string, :default => "" + settings_items :width, :type => :integer, :default => 400 + settings_items :height, :type => :integer, :default => 315 + + def is_valid_source? + + if url.match(/.*youtu(.be|be.com).*v=[[:alnum:]].*/) + true + elsif url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]].*/) + true + else + false + end + end + + def is_file? + false + + extensions = [".mp4", ".ogg", ".ogv", ".wmv"] + if extensions.include? url[-4, 4] + true + end + end + + def format_embed_video_url_for_youtube + self.url.gsub("watch?v=", "embed/") + end + + def format_embed_video_url_for_vimeo + self.url.gsub("vimeo.com/", "player.vimeo.com/video/") + end + + def self.description + _('Add Video') + end + + def help + _('This block presents a video block.') + end + + def content(args={}) + block = self + + lambda do + render :file => 'video_block', :locals => { :block => block } + end + end + + + def cacheable? + false + end + +end diff --git a/plugins/video/lib/video_plugin.rb b/plugins/video/lib/video_plugin.rb new file mode 100644 index 0000000..f77588a --- /dev/null +++ b/plugins/video/lib/video_plugin.rb @@ -0,0 +1,19 @@ +require_dependency File.dirname(__FILE__) + '/video_block' + +class VideoPlugin < Noosfero::Plugin + + def self.plugin_name + "Video Block Plugin" + end + + def self.plugin_description + _("A plugin that adds a block where you could add videos from youtube, vimeo and html5.") + end + + def self.extra_blocks + { + VideoBlock => {} + } + end + +end diff --git a/plugins/video/test/functional/display_content_plugin_admin_controller_test.rb b/plugins/video/test/functional/display_content_plugin_admin_controller_test.rb new file mode 100644 index 0000000..363ab45 --- /dev/null +++ b/plugins/video/test/functional/display_content_plugin_admin_controller_test.rb @@ -0,0 +1,179 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/display_content_plugin_admin_controller' + + +# Re-raise errors caught by the controller. +class DisplayContentPluginAdminControllerController; def rescue_action(e) raise e end; end + +class DisplayContentPluginAdminControllerTest < ActionController::TestCase + + def setup + @controller = DisplayContentPluginAdminController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @environment = Environment.default + user_login = create_admin_user(@environment) + login_as(user_login) + @admin = User[user_login].person + @environment.enabled_plugins = ['DisplayContentPlugin'] + @environment.portal_community = fast_create(Community, :name => 'my test profile', :identifier => 'mytestcommunity') + @environment.save! + + box = Box.new(:owner => @environment, :position => 1) + box.save + + DisplayContentBlock.delete_all + @block = DisplayContentBlock.new + @block.box = environment.boxes.first + @block.save! + end + + attr_accessor :environment, :block + + should 'access index action' do + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + assert_response :success + end + + should 'index action returns a empty json if there is no content' do + Article.delete_all + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + assert_equal [], json_response + end + + should 'index action returns an json with node content' do + Article.delete_all + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => article.title} + expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with node checked if the node is in the nodes list' do + Article.delete_all + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) + block.nodes= [article.id] + block.save! + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => article.title} + expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} + expected_json['attr'].merge!({'class' => 'jstree-checked'}) + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with node undetermined if the node is in the parent nodes list' do + Article.delete_all + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) + block.parent_nodes= [article.id] + block.save! + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => article.title} + expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} + expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) + expected_json['children'] = [] + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with node closed if the node has article with children' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => f.title} + expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + expected_json['state'] = 'closed' + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with all the children nodes if some parent is in the parents list' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) + block.parent_nodes = [f.id] + block.save! + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => f.title} + expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + children = [ + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} + ] + expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) + expected_json['children'] = children + expected_json['state'] = 'closed' + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => environment.portal_community.id) + block.parent_nodes = [f.id] + block.save! + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = [] + value = {'data' => f.title} + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + children = [ + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} + ] + value['attr'].merge!({'class' => 'jstree-undetermined'}) + value['children'] = children + value['state'] = 'closed' + expected_json.push(value) + + value = {'data' => a3.title} + value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} + expected_json.push(value) + + assert_equal expected_json, json_response + end + + should 'index action returns an json without children nodes if the parent is not in the parents list' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => environment.portal_community.id) + + get :index, :block_id => block.id + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = [] + value = {'data' => f.title} + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + value['state'] = 'closed' + expected_json.push(value) + + value = {'data' => a3.title} + value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} + expected_json.push(value) + + assert_equal expected_json, json_response + end + +end diff --git a/plugins/video/test/functional/display_content_plugin_myprofile_controller_test.rb b/plugins/video/test/functional/display_content_plugin_myprofile_controller_test.rb new file mode 100644 index 0000000..1ad04f7 --- /dev/null +++ b/plugins/video/test/functional/display_content_plugin_myprofile_controller_test.rb @@ -0,0 +1,180 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/display_content_plugin_myprofile_controller' + + +# Re-raise errors caught by the controller. +class DisplayContentPluginMyprofileControllerController; def rescue_action(e) raise e end; end + +class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase + + def setup + @controller = DisplayContentPluginMyprofileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + user = create_user('testinguser') + login_as(user.login) + @profile = user.person + @environment = @profile.environment + + @environment.enabled_plugins = ['DisplaContentPlugin'] + @environment.save! + +# box = Box.new(:owner => @environment, :position => 1) +# box.save + + DisplayContentBlock.delete_all + @block = DisplayContentBlock.new + @block.box = @profile.boxes.first + @block.save! + end + + attr_accessor :profile, :block + + should 'access index action' do + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + assert_response :success + end + + should 'index action returns a empty json if there is no content' do + Article.delete_all + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + assert_equal [], json_response + end + + should 'index action returns an json with node content' do + Article.delete_all + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => article.title} + expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with node checked if the node is in the nodes list' do + Article.delete_all + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) + block.nodes= [article.id] + block.save! + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => article.title} + expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} + expected_json['attr'].merge!({'class' => 'jstree-checked'}) + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with node undetermined if the node is in the parent nodes list' do + Article.delete_all + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) + block.parent_nodes= [article.id] + block.save! + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => article.title} + expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} + expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) + expected_json['children'] = [] + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with node closed if the node has article with children' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) + block.save! + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => f.title} + expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + expected_json['state'] = 'closed' + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with all the children nodes if some parent is in the parents list' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) + block.parent_nodes = [f.id] + block.save! + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = {'data' => f.title} + expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + children = [ + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} + ] + expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) + expected_json['children'] = children + expected_json['state'] = 'closed' + + assert_equal [expected_json], json_response + end + + should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) + block.parent_nodes = [f.id] + block.save! + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = [] + value = {'data' => f.title} + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + children = [ + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} + ] + value['attr'].merge!({'class' => 'jstree-undetermined'}) + value['children'] = children + value['state'] = 'closed' + expected_json.push(value) + + value = {'data' => a3.title} + value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} + expected_json.push(value) + + assert_equal expected_json, json_response + end + + should 'index action returns an json without children nodes if the parent is not in the parents list' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = [] + value = {'data' => f.title} + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + value['state'] = 'closed' + expected_json.push(value) + + value = {'data' => a3.title} + value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} + expected_json.push(value) + + assert_equal expected_json, json_response + end + +end diff --git a/plugins/video/test/test_helper.rb b/plugins/video/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/video/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/video/test/unit/video_block_test.rb b/plugins/video/test/unit/video_block_test.rb new file mode 100644 index 0000000..5525476 --- /dev/null +++ b/plugins/video/test/unit/video_block_test.rb @@ -0,0 +1,103 @@ +require File.dirname(__FILE__) + '/../test_helper' +class VideoBlockTest < ActiveSupport::TestCase + + ### Tests for YouTube + + should "is_valid_source return true when the url contains http://youtube.com" do + block = VideoBlock.new + block.url = "http://youtube.com/?v=XXXXX" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains https://youtube.com" do + block = VideoBlock.new + block.url = "https://youtube.com/?v=XXXXX" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains https://www.youtube.com" do + block = VideoBlock.new + block.url = "https://www.youtube.com/?v=XXXXX" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains www.youtube.com" do + block = VideoBlock.new + block.url = "www.youtube.com/?v=XXXXX" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains youtube.com" do + block = VideoBlock.new + block.url = "youtube.com/?v=XXXXX" + assert block.is_valid_source? + end + + should "is_valid_source return false when the url not contains youtube video ID" do + block = VideoBlock.new + block.url = "youtube.com/" + assert !block.is_valid_source? + end + + should "is_valid_source return false when the url contains empty youtube video ID" do + block = VideoBlock.new + block.url = "youtube.com/?v=" + assert !block.is_valid_source? + end + + should "is_valid_source return false when the url contains an invalid youtube link" do + block = VideoBlock.new + block.url = "http://www.yt.com/?v=XXXXX" + assert !block.is_valid_source? + end + + #### Tests for Vimeo Videos + + should "is_valid_source return true when the url contains http://vimeo.com" do + block = VideoBlock.new + block.url = "http://vimeo.com/98979" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains https://vimeo.com" do + block = VideoBlock.new + block.url = "https://vimeo.com/989798" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains https://www.vimeo.com" do + block = VideoBlock.new + block.url = "https://www.vimeo.com/98987" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains www.vimeo.com" do + block = VideoBlock.new + block.url = "www.vimeo.com/989798" + assert block.is_valid_source? + end + + should "is_valid_source return true when the url contains vimeo.com" do + block = VideoBlock.new + block.url = "vimeo.com/09898" + assert block.is_valid_source? + end + + should "is_valid_source return false when the url not contains vimeo video ID" do + block = VideoBlock.new + block.url = "vimeo.com/home" + assert !block.is_valid_source? + end + + should "is_valid_source return false when the url contains empty vimeo video ID" do + block = VideoBlock.new + block.url = "vimeo.com/" + assert !block.is_valid_source? + end + + should "is_valid_source return false when the url contains an invalid vimeo link" do + block = VideoBlock.new + block.url = "http://www.vmsd.com/98979" + assert !block.is_valid_source? + end +end diff --git a/plugins/video/test/unit/video_plugin_test.rb b/plugins/video/test/unit/video_plugin_test.rb new file mode 100644 index 0000000..a805e4a --- /dev/null +++ b/plugins/video/test/unit/video_plugin_test.rb @@ -0,0 +1,9 @@ +require File.dirname(__FILE__) + '/../test_helper' +class VideoPluginTest < ActiveSupport::TestCase + + + should "return VideoBlock in extra_blocks class method" do + assert VideoPlugin.extra_blocks.keys.include?(VideoBlock) + end + +end diff --git a/plugins/video/views/box_organizer/_html5_video_block.rhtml b/plugins/video/views/box_organizer/_html5_video_block.rhtml new file mode 100644 index 0000000..e2cc3c2 --- /dev/null +++ b/plugins/video/views/box_organizer/_html5_video_block.rhtml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/plugins/video/views/box_organizer/_iframe_video_block.rhtml b/plugins/video/views/box_organizer/_iframe_video_block.rhtml new file mode 100644 index 0000000..f7eb14a --- /dev/null +++ b/plugins/video/views/box_organizer/_iframe_video_block.rhtml @@ -0,0 +1 @@ + diff --git a/plugins/video/views/box_organizer/_video_block.rhtml b/plugins/video/views/box_organizer/_video_block.rhtml new file mode 100644 index 0000000..1fd7a06 --- /dev/null +++ b/plugins/video/views/box_organizer/_video_block.rhtml @@ -0,0 +1,11 @@ + + +
+ <%= text_field_tag 'block[url]', @block.url, :class => 'video-url', :maxlength => 255 %> +
+
+ + <%= text_field_tag 'block[width]', @block.width, :size => 7, :class => 'video-width', :maxlength => 5 %> + + <%= text_field_tag 'block[height]', @block.height, :size => 7, :class => 'video-height', :maxlength => 5 %> +
diff --git a/plugins/video/views/environment_design b/plugins/video/views/environment_design new file mode 120000 index 0000000..a75d184 --- /dev/null +++ b/plugins/video/views/environment_design @@ -0,0 +1 @@ +box_organizer \ No newline at end of file diff --git a/plugins/video/views/profile_design b/plugins/video/views/profile_design new file mode 120000 index 0000000..a75d184 --- /dev/null +++ b/plugins/video/views/profile_design @@ -0,0 +1 @@ +box_organizer \ No newline at end of file diff --git a/plugins/video/views/video_block.rhtml b/plugins/video/views/video_block.rhtml new file mode 100644 index 0000000..7777174 --- /dev/null +++ b/plugins/video/views/video_block.rhtml @@ -0,0 +1,15 @@ +

+ <%=block.title%> +

+
+ <% if block.is_youtube? %> + <%= render :partial => 'iframe_video_block', :locals => { :url => block.format_embed_video_url_for_youtube, :width => block.width, :height => block.height }%> + <% elsif block.is_vimeo? %> + <%= render :partial => 'iframe_video_block', :locals => { :url => block.format_embed_video_url_for_vimeo, :width => block.width, :height => block.height }%> + <% elsif block.is_file? %> + <%= render :partial => 'html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> + <% else %> + <%= " Cadastre uma nova URL (Vimeo, Youtube)" %> + <% end %> + +
-- libgit2 0.21.2