Commit ec7d1359 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Adds child_pages macro for wiki pages (#528).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1699 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 60d066f9
......@@ -165,7 +165,10 @@ class WikiController < ApplicationController
page = @wiki.find_page(params[:page])
# page is nil when previewing a new 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]
render :partial => 'common/preview'
end
......
......@@ -206,7 +206,7 @@ module ApplicationHelper
options = args.last.is_a?(Hash) ? args.pop : {}
case args.size
when 1
obj = nil
obj = options[:object]
text = args.shift
when 2
obj = args.shift
......
......@@ -24,7 +24,7 @@ module WikiHelper
pages[node].each do |page|
content << "<li>"
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 << "</li>\n"
end
......
<fieldset class="preview"><legend><%= l(:label_preview) %></legend>
<%= textilizable @text, :attachments => @attachements %>
<%= textilizable @text, :attachments => @attachements, :object => @previewed %>
</fieldset>
......@@ -77,6 +77,12 @@ module Redmine
content_tag('dl', out)
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)}}"
macro :include do |obj, args|
project = @project
......
......@@ -2,7 +2,7 @@
wiki_contents_001:
text: |-
h1. CookBook documentation
{{child_pages}}
Some updated [[documentation]] here with gzipped history
updated_on: 2007-03-07 00:10:51 +01:00
page_id: 1
......
......@@ -32,10 +32,16 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_show_start_page
get :index, :id => 1
get :index, :id => 'ecookbook'
assert_response :success
assert_template 'show'
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
def test_show_page_with_name
......
......@@ -70,6 +70,13 @@ module ActiveRecord
nodes
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.
def root
node = self
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment