Added vimeo macro

This commit is contained in:
Alexander Meindl 2015-10-20 19:32:32 +02:00
parent 7939fe9eaa
commit f6f1a9b6ea
7 changed files with 200 additions and 27 deletions

View File

@ -10,7 +10,9 @@
* Wiki project macros * Wiki project macros
* Wiki date macros * Wiki date macros
* Wiki Garfield marco * Wiki Garfield marco
* Wiki Gist marco
* Wiki Youtube marco * Wiki Youtube marco
* Wiki Vimeo marco
* option to remove "my page" from top menu * option to remove "my page" from top menu
* customize "Help" url in top menu * customize "Help" url in top menu
* customize top menu items * customize top menu items
@ -90,14 +92,22 @@ Macro to get current date, year, month, day
{{garfield}} := show Garfield strip of the current day {{garfield}} := show Garfield strip of the current day
{{garfield(2014,10,31)}} := show Garfield strip of 31/12/2014 {{garfield(2014,10,31)}} := show Garfield strip of 31/12/2014
### Gist macro
{{gist(6737338)}} := Show Github gist 6737338
{{gist(plentz/6737338)}} := Show Github gist 6737338
### Youtube macro ### Youtube macro
{youtube(wvsboPUjrGc)}} := youtube video with video wvsboPUjrGc (iframe) and default size 640x360 {{youtube(wvsboPUjrGc)}} := youtube video with video wvsboPUjrGc (iframe) and default size 640x360
{{youtube(wvsboPUjrGc,853,480)}} := youtube video with size 853x480 {{youtube(wvsboPUjrGc, width=853, height=480)}} := youtube video with size 853x480
{{youtube(wvsboPUjrGc,853,480,1)}} := youtube video with size 853x480 and autoplay {{youtube(wvsboPUjrGc, autoplay=1)}} := youtube video and autoplay
{{youtube(wvsboPUjrGc,,,1)}} := youtube video with size 853x480 and autoplay
### Vimeo macro
{{vimeo(142849533)}} := vimeo video with video 142849533 (iframe) and default size 640x360
{{vimeo(142849533, width=853, height=480)}} := vimeo video with size 853x480
{{vimeo(142849533, autoplay=1)}} := vimeo video and autoplay
### Custom help URL ### Custom help URL
@ -113,6 +123,7 @@ Note: Redmine must be restarted after changing "Custom Help URL"</tt> value befo
- system information uptime and uname have been added - system information uptime and uname have been added
- gist macro support - gist macro support
- vimeo macro support
### 0.5.5 ### 0.5.5

View File

@ -22,6 +22,7 @@ if ActiveRecord::Base.connection.table_exists?(:settings)
require 'redmine_tweaks/wiki_macros/user_macros' require 'redmine_tweaks/wiki_macros/user_macros'
require 'redmine_tweaks/wiki_macros/date_macros' require 'redmine_tweaks/wiki_macros/date_macros'
require 'redmine_tweaks/wiki_macros/garfield_macros' require 'redmine_tweaks/wiki_macros/garfield_macros'
require 'redmine_tweaks/wiki_macros/vimeo_macros'
require 'redmine_tweaks/wiki_macros/youtube_macros' require 'redmine_tweaks/wiki_macros/youtube_macros'
unless RedmineTweaks.settings[:remove_help] unless RedmineTweaks.settings[:remove_help]

View File

@ -28,7 +28,7 @@ module RedmineTweaks
view_roles = [] view_roles = []
@users_by_role.keys.sort.each do |role| @users_by_role.keys.sort.each do |role|
if !role.permissions.include?(:hide_in_memberbox) || if !role.permissions.include?(:hide_in_memberbox) ||
(role.permissions.include?(:hide_in_memberbox) && User.current.allowed_to?(:show_hidden_roles_in_memberbox, @project)) (role.permissions.include?(:hide_in_memberbox) && User.current.allowed_to?(:show_hidden_roles_in_memberbox, @project))
view_roles << role view_roles << role
end end
end end

View File

@ -0,0 +1,51 @@
# Redmine Tweaks plugin for Redmine
# Copyright (C) 2013-2015 AlphaNodes GmbH
# Vimeo wiki macros
module RedmineTweaks
module WikiMacros
Redmine::WikiFormatting::Macros.register do
desc <<-EOHELP
Vimeo macro to include vimeo video.
Syntax:
{{vimeo(<video key> [, width=640, height=360, autoplay=BOOL])}}
Examples:
{{vimeo(142849533)}} show video with default size 640x360
{{vimeo(142849533, width=853, height=480)}} show video with user defined size
{{vimeo(142849533, autoplay=true)}} autoplay video
EOHELP
# Register vimeo macro
macro :vimeo do |_obj, args|
args, options = extract_macro_options(args, :width, :height, :autoplay)
width = 640
height = 360
autoplay = false
width = options[:width] unless options[:width].blank?
height = options[:height] unless options[:height].blank?
autoplay = true if !options[:autoplay].nil? &&
(options[:autoplay] == 'true' || options[:autoplay] == '1')
if (options[:width].blank? && !options[:height].blank?) ||
(!options[:width].blank? && options[:height].blank?) ||
args.length < 1
fail 'The correct usage is {{vimeo(<video key>[, width=x, height=y])}}'
end
v = args[0]
if autoplay
src = '//player.vimeo.com/video/' + v + '?autoplay=1'
else
src = '//player.vimeo.com/video/' + v
end
content_tag(:iframe, '', width: width, height: height, src: src, frameborder: 0, allowfullscreen: 'true')
end
end
end
end

View File

@ -10,38 +10,41 @@ module RedmineTweaks
Syntax: Syntax:
{{youtube(<video key>,[<width>,<height>,<autoplay>])}} {{youtube(<video key> [, width=640, height=360, autoplay=BOOL])}}
Examples: Examples:
{{youtube(KMU0tzLwhbE)}} show video with default size 640x360 {{youtube(KMU0tzLwhbE)}} show video with default size 640x360
{{youtube(KMU0tzLwhbE,853,480)}} show video with user defined size {{youtube(KMU0tzLwhbE, width=853, height=480)}} show video with user defined size
{{youtube(KMU0tzLwhbE,853,480,1)}} show video with user defined size and autoplay video {{youtube(KMU0tzLwhbE, autoplay=true)}} autoplay video
EOHELP EOHELP
# Register youtube macro # Register youtube macro
macro :youtube do |_youtube_wiki_content, args| macro :youtube do |_obj, args|
h = 360 args, options = extract_macro_options(args, :width, :height, :autoplay)
w = 640
if args.length >= 1
v = args[0]
unless args[1].nil? || args[1].empty? || args[2].nil? || args[2].empty? width = 640
w = args[1] height = 360
h = args[2] autoplay = false
end
if args[3].nil? || args[3] == 1 width = options[:width] unless options[:width].blank?
src = '//www.youtube-nocookie.com/embed/' + v height = options[:height] unless options[:height].blank?
else autoplay = true if !options[:autoplay].nil? &&
src = '//www.youtube.com/embed/' + v + '?autoplay=1' (options[:autoplay] == 'true' || options[:autoplay] == '1')
end
content_tag(:iframe, '', width: w, height: h, src: src, frameborder: 0, allowfullscreen: 'true') if (options[:width].blank? && !options[:height].blank?) ||
else (!options[:width].blank? && options[:height].blank?) ||
'<pre>Error in youtube macro. The correct usage is {{youtube(&lt;video key&gt;,[&lt;width&gt;,&lt;height&gt;])}}.</pre>' args.length < 1
fail 'The correct usage is {{youtube(<video key>[, width=x, height=y])}}'
end end
v = args[0]
if autoplay
src = '//www.youtube.com/embed/' + v + '?autoplay=1'
else
src = '//www.youtube-nocookie.com/embed/' + v
end
content_tag(:iframe, '', width: width, height: height, src: src, frameborder: 0, allowfullscreen: 'true')
end end
end end
end end

View File

@ -0,0 +1,106 @@
# Redmine Tweaks plugin for Redmine
# Copyright (C) 2013-2015 AlphaNodes GmbH
require File.expand_path('../../test_helper', __FILE__)
# Redmine Tweaks functional tests
class WikiControllerTest < ActionController::TestCase
fixtures :projects,
:users, :email_addresses,
:roles,
:members,
:member_roles,
:trackers,
:projects_trackers,
:enabled_modules,
:issue_statuses,
:issues,
:enumerations,
:custom_fields,
:custom_values,
:custom_fields_trackers,
:wikis
def setup
RedmineTweaks::TestCase.prepare
EnabledModule.create(project_id: 1, name: 'wiki')
@project = Project.find(1)
@wiki = @project.wiki
@page_name = 'tweaks_macro_test'
@page = @wiki.find_or_new_page(@page_name)
@page.content = WikiContent.new
@page.content.text = 'test'
@page.save!
end
def test_show_with_youtube_macro
@request.session[:user_id] = 1
@page.content.text = '{{youtube(KMU0tzLwhbE)}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'iframe[src=?]', '//www.youtube-nocookie.com/embed/KMU0tzLwhbE'
end
def test_show_with_vimeo_macro
@request.session[:user_id] = 1
@page.content.text = '{{vimeo(142849533)}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'iframe[src=?]', '//player.vimeo.com/video/142849533'
end
def test_show_with_list_users_macro
@request.session[:user_id] = 1
@page.content.text = '{{list_users}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'div.wiki div.user'
end
def test_show_with_list_projects_macro
@request.session[:user_id] = 1
@page.content.text = '{{list_projects}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'div.wiki div.projects li.project'
end
def test_show_with_gist_macro
@request.session[:user_id] = 1
@page.content.text = '{{gist(plentz/6737338)}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'script[src=?]', 'https://gist.github.com/plentz/6737338.js'
end
def test_show_with_weeknumber_macro
@request.session[:user_id] = 1
@page.content.text = '{{current_weeknumber}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'div.wiki span.current-date', "#{Time.zone.today.cweek}"
end
def test_show_with_garfield_macro
@request.session[:user_id] = 1
@page.content.text = '{{garfield(2015,10,20)}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'div.wiki img.garfield'
assert_select 'img[src=?]', '/garfield/ga151020/gif'
end
end

View File

@ -1,4 +1,5 @@
# Load the Redmine helper # Redmine Tweaks plugin for Redmine
# Copyright (C) 2013-2015 AlphaNodes GmbH
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')