Adds child_pages macro for wiki pages (#528).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1699 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-07-26 12:54:54 +00:00
parent 60d066f943
commit ec7d135930
8 changed files with 28 additions and 6 deletions

View File

@ -165,7 +165,10 @@ class WikiController < ApplicationController
page = @wiki.find_page(params[:page]) page = @wiki.find_page(params[:page])
# page is nil when previewing a new page # page is nil when previewing a new page
return render_403 unless page.nil? || editable?(page) return render_403 unless page.nil? || editable?(page)
@attachements = page.attachments if page if page
@attachements = page.attachments
@previewed = page.content
end
@text = params[:content][:text] @text = params[:content][:text]
render :partial => 'common/preview' render :partial => 'common/preview'
end end

View File

@ -206,7 +206,7 @@ module ApplicationHelper
options = args.last.is_a?(Hash) ? args.pop : {} options = args.last.is_a?(Hash) ? args.pop : {}
case args.size case args.size
when 1 when 1
obj = nil obj = options[:object]
text = args.shift text = args.shift
when 2 when 2
obj = args.shift obj = args.shift

View File

@ -24,7 +24,7 @@ module WikiHelper
pages[node].each do |page| pages[node].each do |page|
content << "<li>" content << "<li>"
content << link_to(h(page.pretty_title), {:action => 'index', :page => page.title}, content << link_to(h(page.pretty_title), {:action => 'index', :page => page.title},
:title => l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on))) :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id] content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
content << "</li>\n" content << "</li>\n"
end end

View File

@ -1,3 +1,3 @@
<fieldset class="preview"><legend><%= l(:label_preview) %></legend> <fieldset class="preview"><legend><%= l(:label_preview) %></legend>
<%= textilizable @text, :attachments => @attachements %> <%= textilizable @text, :attachments => @attachements, :object => @previewed %>
</fieldset> </fieldset>

View File

@ -77,6 +77,12 @@ module Redmine
content_tag('dl', out) content_tag('dl', out)
end end
desc "Displays a list of child pages."
macro :child_pages do |obj, args|
raise 'This macro applies to wiki pages only.' unless obj.is_a?(WikiContent)
render_page_hierarchy(obj.page.descendants.group_by(&:parent_id), obj.page.id)
end
desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}" desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}"
macro :include do |obj, args| macro :include do |obj, args|
project = @project project = @project

View File

@ -2,7 +2,7 @@
wiki_contents_001: wiki_contents_001:
text: |- text: |-
h1. CookBook documentation h1. CookBook documentation
{{child_pages}}
Some updated [[documentation]] here with gzipped history Some updated [[documentation]] here with gzipped history
updated_on: 2007-03-07 00:10:51 +01:00 updated_on: 2007-03-07 00:10:51 +01:00
page_id: 1 page_id: 1

View File

@ -32,10 +32,16 @@ class WikiControllerTest < Test::Unit::TestCase
end end
def test_show_start_page def test_show_start_page
get :index, :id => 1 get :index, :id => 'ecookbook'
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_tag :tag => 'h1', :content => /CookBook documentation/ assert_tag :tag => 'h1', :content => /CookBook documentation/
# child_pages macro
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
:child => { :tag => 'li',
:child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
:content => 'Page with an inline image' } }
end end
def test_show_page_with_name def test_show_page_with_name

View File

@ -70,6 +70,13 @@ module ActiveRecord
nodes nodes
end end
# Returns list of descendants.
#
# root.descendants # => [child1, subchild1, subchild2]
def descendants
children + children.collect(&:children).flatten
end
# Returns the root node of the tree. # Returns the root node of the tree.
def root def root
node = self node = self