Feature #38501 » recent_pages.patch
lib/redmine/wiki_formatting/macros.rb | ||
---|---|---|
213 | 213 |
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id) |
214 | 214 |
end |
215 | 215 | |
216 |
desc "Displays a list of recently updated Wiki pages. With no argument, it displays pages that have been updated within the past 7 days. Examples:\n\n" + |
|
217 |
"{{recent_pages}} -- displays pages updated within the past 7 days\n" + |
|
218 |
"{{recent_pages(days=3)}} -- displays pages updated within the past 3 days\n" + |
|
219 |
"{{recent_pages(limit=5)}} -- limits the maximum number of pages to display to 5\n" + |
|
220 |
"{{recent_pages(time=true)}} -- displays pages updated within the past 5 days with updated time" |
|
221 | ||
222 |
macro :recent_pages do |obj, args| |
|
223 |
return '' if @project.nil? |
|
224 |
return '' unless User.current.allowed_to?(:view_wiki_pages, @project) |
|
225 | ||
226 |
args, options = extract_macro_options(args, :days, :limit, :time) |
|
227 |
days_to_list = (options[:days].presence || 7).to_i |
|
228 |
limit = options[:limit].to_i if options[:limit].present? |
|
229 |
is_show_time = options[:time].to_s == 'true' |
|
230 | ||
231 |
pages = WikiPage. |
|
232 |
joins(:content, :wiki). |
|
233 |
where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", @project.id, days_to_list.days.ago]). |
|
234 |
order("#{WikiContent.table_name}.updated_on desc, id"). |
|
235 |
limit(limit) |
|
236 | ||
237 |
tag.ul do |
|
238 |
pages.each do |page| |
|
239 |
concat( |
|
240 |
tag.li do |
|
241 |
html = link_to(h(page.pretty_title), project_wiki_page_path(@project, page.title)) |
|
242 |
html << " (#{time_ago_in_words(page.content.updated_on)})" if is_show_time |
|
243 |
html |
|
244 |
end |
|
245 |
) |
|
246 |
end |
|
247 |
end |
|
248 |
end |
|
249 | ||
216 | 250 |
desc "Includes a wiki page. Examples:\n\n" + |
217 | 251 |
"{{include(Foo)}}\n" + |
218 | 252 |
"{{include(projectname:Foo)}} -- to include a page of a specific project wiki" |
test/unit/lib/redmine/wiki_formatting/macros_test.rb | ||
---|---|---|
502 | 502 |
) |
503 | 503 |
end |
504 | 504 |
end |
505 | ||
506 |
def test_recent_pages_macro |
|
507 |
@project = Project.find(1) |
|
508 |
freeze_time do |
|
509 |
WikiContent.update_all(updated_on: Time.current) |
|
510 |
@project.wiki.pages.each_with_index do |page, i| |
|
511 |
page.content.update_attribute(:updated_on, (i + 1).days.ago) |
|
512 |
end |
|
513 | ||
514 |
with_settings :text_formatting => 'textile' do |
|
515 |
result = textilizable('{{recent_pages}}') |
|
516 |
assert_select_in result, 'ul>li', :count => 7 |
|
517 |
assert_select_in result, 'ul>li:first-of-type', :text => 'Another page' |
|
518 |
assert_select_in result, 'ul>li:last-of-type', :text => 'Page with sections' |
|
519 |
end |
|
520 |
end |
|
521 |
end |
|
522 | ||
523 |
def test_recent_pages_macro_with_limit_option |
|
524 |
@project = Project.find(1) |
|
525 |
freeze_time do |
|
526 |
WikiContent.update_all(updated_on: Time.current) |
|
527 |
@project.wiki.pages.each_with_index do |page, i| |
|
528 |
page.content.update_attribute(:updated_on, (i + 1).days.ago) |
|
529 |
end |
|
530 | ||
531 |
with_settings :text_formatting => 'textile' do |
|
532 |
result = textilizable('{{recent_pages(limit=5)}}') |
|
533 |
assert_select_in result, 'ul>li', :count => 5 |
|
534 |
assert_select_in result, 'ul>li:first-of-type', :text => 'Another page' |
|
535 |
assert_select_in result, 'ul>li:last-of-type', :text => 'CookBook documentation' |
|
536 |
end |
|
537 |
end |
|
538 |
end |
|
539 | ||
540 |
def test_recent_pages_macro_with_time_option |
|
541 |
@project = Project.find(1) |
|
542 |
WikiContent.update_all(updated_on: Time.current) |
|
543 |
freeze_time do |
|
544 |
@project.wiki.pages.each_with_index do |page, i| |
|
545 |
page.content.update_attribute(:updated_on, (i + 1).days.ago) |
|
546 |
end |
|
547 | ||
548 |
with_settings :text_formatting => 'textile' do |
|
549 |
result = textilizable('{{recent_pages(time=true)}}') |
|
550 |
assert_select_in result, 'ul>li:first-of-type', :text => 'Another page (1 day)' |
|
551 |
assert_select_in result, 'ul>li:last-of-type', :text => 'Page with sections (7 days)' |
|
552 |
end |
|
553 |
end |
|
554 |
end |
|
555 | ||
556 |
def test_recent_pages_macro_with_days_option |
|
557 |
@project = Project.find(1) |
|
558 |
freeze_time do |
|
559 |
WikiContent.update_all(updated_on: Time.current) |
|
560 |
@project.wiki.pages.each_with_index do |page, i| |
|
561 |
page.content.update_attribute(:updated_on, (i + 1).days.ago) |
|
562 |
end |
|
563 | ||
564 |
with_settings :text_formatting => 'textile' do |
|
565 |
result = textilizable('{{recent_pages(time=true, days=3)}}') |
|
566 |
assert_select_in result, 'ul>li', :count => 3 |
|
567 |
assert_select_in result, 'ul>li:first-of-type', :text => 'Another page (1 day)' |
|
568 |
assert_select_in result, 'ul>li:last-of-type', :text => 'Child 1 1 (3 days)' |
|
569 |
end |
|
570 |
end |
|
571 |
end |
|
505 | 572 |
end |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »