Allow custom date with date macro
This commit is contained in:
parent
0882d7c028
commit
f440afd0c6
@ -1,6 +1,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
2.0.17-dev
|
||||
++++++++++
|
||||
|
||||
- add possibility to use custom date with date macro
|
||||
|
||||
|
||||
2.0.16
|
||||
++++++
|
||||
|
||||
|
@ -14,6 +14,7 @@ Date
|
||||
current_minute current minute
|
||||
current_weekday current weekday
|
||||
current_weeknumber current week number (1 - 52) The week starts with Monday
|
||||
YYYY-MM-DD e.g. 2018-12-24, which will formated with Redmine date format
|
||||
|
||||
Scope
|
||||
+++++
|
||||
@ -49,3 +50,9 @@ Show current week number
|
||||
.. code-block:: smarty
|
||||
|
||||
{{date(current_weeknumber)}}
|
||||
|
||||
Show date 2018-12-24 in right format, which is specified in Redmine Settings, which shows e.g. 24.12.2018
|
||||
|
||||
.. code-block:: smarty
|
||||
|
||||
{{date(2018-12-24)}}
|
||||
|
2
init.rb
2
init.rb
@ -4,7 +4,7 @@ Redmine::Plugin.register :additionals do
|
||||
name 'Additionals'
|
||||
author 'AlphaNodes GmbH'
|
||||
description 'Customizing Redmine, providing wiki macros and act as a library/function provider for other Redmine plugins'
|
||||
version '2.0.16'
|
||||
version '2.0.17-dev'
|
||||
author_url 'https://alphanodes.com/'
|
||||
url 'https://github.com/alphanodes/additionals'
|
||||
|
||||
|
@ -18,6 +18,7 @@ module Additionals
|
||||
- current_minute current minute
|
||||
- current_weekday current weekday
|
||||
- current_weeknumber current week number (1 - 52) The week starts with Monday
|
||||
- YYYY-MM-DD e.g. 2018-12-24, which will formated with Redmine date format
|
||||
|
||||
Examples:
|
||||
|
||||
@ -32,18 +33,12 @@ module Additionals
|
||||
DESCRIPTION
|
||||
|
||||
macro :date do |_obj, args|
|
||||
valid_types = %w[current_date current_date_with_time current_year
|
||||
current_month current_day current_hour current_minute
|
||||
current_weekday current_weeknumber]
|
||||
|
||||
type = if args.present?
|
||||
args[0]
|
||||
else
|
||||
'current_date'
|
||||
end
|
||||
|
||||
return if valid_types.exclude?(type)
|
||||
|
||||
d = Additionals.now_with_user_time_zone
|
||||
date_result = case type
|
||||
when 'current_date'
|
||||
@ -64,6 +59,8 @@ module Additionals
|
||||
day_name(d.wday)
|
||||
when 'current_weeknumber'
|
||||
User.current.today.cweek
|
||||
else
|
||||
format_date(type.to_date)
|
||||
end
|
||||
|
||||
content_tag(:span, date_result, class: 'current-date')
|
||||
|
@ -324,6 +324,7 @@ class WikiControllerTest < Additionals::ControllerTest
|
||||
assert_select 'div.wiki', html: /{{date/, count: 0
|
||||
assert_select 'div.wiki span.current-date', count: valid_types.count
|
||||
assert_select 'div.wiki span.current-date', User.current.today.cweek.to_s
|
||||
assert_select 'div.flash.error', html: /Error executing/, count: 0
|
||||
end
|
||||
|
||||
def test_show_with_date_macro_and_invalid_type
|
||||
@ -336,7 +337,33 @@ class WikiControllerTest < Additionals::ControllerTest
|
||||
params: { project_id: 1, id: @page_name }
|
||||
|
||||
assert_response :success
|
||||
assert_select 'div.wiki', html: /{{date/
|
||||
assert_select 'div.flash.error', html: /Error executing/
|
||||
end
|
||||
|
||||
def test_show_with_date_macro_custom_date
|
||||
@request.session[:user_id] = WIKI_MACRO_USER_ID
|
||||
|
||||
@page.content.text = '{{date(2017-02-25)}}'
|
||||
@page.content.save!
|
||||
|
||||
get :show,
|
||||
params: { project_id: 1, id: @page_name }
|
||||
|
||||
assert_response :success
|
||||
assert_select 'div.flash.error', html: /Error executing/, count: 0
|
||||
end
|
||||
|
||||
def test_show_with_date_macro_invalid_custom_date
|
||||
@request.session[:user_id] = WIKI_MACRO_USER_ID
|
||||
|
||||
@page.content.text = '{{date(2017-02-30)}}'
|
||||
@page.content.save!
|
||||
|
||||
get :show,
|
||||
params: { project_id: 1, id: @page_name }
|
||||
|
||||
assert_response :success
|
||||
assert_select 'div.flash.error', html: /Error executing/
|
||||
end
|
||||
|
||||
def test_show_issue
|
||||
|
Loading…
Reference in New Issue
Block a user