Skip to content

Commit

Permalink
fixed specs for if_content
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Jun 25, 2008
1 parent 40f4bb5 commit 69c3aff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
18 changes: 11 additions & 7 deletions app/models/standard_tags.rb
Expand Up @@ -34,7 +34,7 @@ class TagError < StandardError; end

desc %{
Gives access to a page's children and will only show the contents if the
current page hase children.
current page has children.
*Usage:*
<pre><code><r:children>...</r:children></code></pre>
Expand Down Expand Up @@ -276,25 +276,29 @@ class TagError < StandardError; end
end

desc %{
Renders the containing elements only if the part exists on a page. By default the
@part@ attribute is set to @body@.
Renders the containing elements only if all of the listed parts exists on a page.
By default the @part@ attribute is set to @body@, but you may list more than one
part by seprating them by a comma.
*Usage:*
<pre><code><r:if_content [part="part_name"]>...</r:if_content></code></pre>
<pre><code><r:if_content [part="part_name, other_part"]>...</r:if_content></code></pre>
}
tag 'if_content' do |tag|
page = tag.locals.page
puts page.parts.to_json
part_name = tag_part_name(tag)
parts_arr = part_name.split(',')
all_parts_present = true
parts_arr.each do |name|
puts name
name.strip!
all_parts_present = false if page.part(name).nil?
puts page.part(name)
if page.part(name).nil?
all_parts_present = false
end
end
tag.expand if all_parts_present

# page = tag.locals.page
# part_name = tag_part_name(tag)
# unless page.part(part_name).nil?
# tag.expand
# end
Expand Down
30 changes: 15 additions & 15 deletions spec/models/standard_tags_spec.rb
Expand Up @@ -23,7 +23,7 @@
it '<r:parent> should change the local context to the parent page' do
page(:parent)
page.should render('<r:parent><r:title /></r:parent>').as(pages(:home).title)
page.should render('<r:parent><r:children:each by="title" order="asc"><r:title /></r:children:each></r:parent>').as(page_eachable_children(pages(:home)).collect(&:title).sort!.join(""))
page.should render('<r:parent><r:children:each by="title"><r:title /></r:children:each></r:parent>').as(page_eachable_children(pages(:home)).collect(&:title).join(""))
page.should render('<r:children:each><r:parent:title /></r:children:each>').as(@page.title * page.children.count)
end

Expand Down Expand Up @@ -55,8 +55,8 @@
describe "<r:children:each>" do
it "should iterate through the children of the current page" do
page(:parent)
page.should render('<r:children:each by="title"><r:title /> </r:children:each>').as('Child Child 2 Child 3 ')
page.should render('<r:children:each by="title"><r:page><r:slug />/<r:child:slug /> </r:page></r:children:each>').as('parent/child parent/child-2 parent/child-3 ')
page.should render('<r:children:each><r:title /> </r:children:each>').as('Child Child 2 Child 3 ')
page.should render('<r:children:each><r:page><r:slug />/<r:child:slug /> </r:page></r:children:each>').as('parent/child parent/child-2 parent/child-3 ')
page(:assorted).should render(page_children_each_tags).as('a b c d e f g h i j ')
end

Expand Down Expand Up @@ -101,7 +101,7 @@
end

it "should change the sort order when given an 'order' attribute" do
page.should render(page_children_each_tags(%{order="desc" by="slug"})).as('j i h g f e d c b a ')
page.should render(page_children_each_tags(%{order="desc"})).as('j i h g f e d c b a ')
end

it "should sort by the 'by' attribute" do
Expand All @@ -114,7 +114,7 @@

describe 'with "status" attribute' do
it "set to 'all' should list all children" do
page.should render(page_children_each_tags(%{status="all" by="slug"})).as("a b c d draft e f g h i j ")
page.should render(page_children_each_tags(%{status="all"})).as("a b c d e f g h i j draft ")
end

it "set to 'draft' should list only children with 'draft' status" do
Expand Down Expand Up @@ -171,7 +171,7 @@
page.should render(page_children_first_tags).as('a')
page.should render(page_children_first_tags(%{limit="5"})).as('a')
page.should render(page_children_first_tags(%{offset="3" limit="5"})).as('d')
page.should render(page_children_first_tags(%{order="desc" by="slug"})).as('j')
page.should render(page_children_first_tags(%{order="desc"})).as('j')
page.should render(page_children_first_tags(%{by="breadcrumb"})).as('f')
page.should render(page_children_first_tags(%{by="breadcrumb" order="desc"})).as('g')
end
Expand All @@ -183,14 +183,14 @@

describe "<r:children:last>" do
it 'should render its contents in the context of the last child page' do
page(:parent).should render('<r:children:last by="slug" order="asc"><r:title /></r:children:last>').as('Child 3')
page(:parent).should render('<r:children:last:title />').as('Child 3')
end

it 'should accept the same scoping attributes as <r:children:each>' do
page.should render(page_children_last_tags).as('j')
page.should render(page_children_last_tags(%{limit="5"})).as('e')
page.should render(page_children_last_tags(%{offset="3" limit="5"})).as('h')
page.should render(page_children_last_tags(%{order="desc" by="slug "})).as('a')
page.should render(page_children_last_tags(%{order="desc"})).as('a')
page.should render(page_children_last_tags(%{by="breadcrumb"})).as('g')
page.should render(page_children_last_tags(%{by="breadcrumb" order="desc"})).as('f')
end
Expand Down Expand Up @@ -248,7 +248,7 @@

it "should render parts with respect to the current contextual page" do
expected = "Child body. Child 2 body. Child 3 body. "
page(:parent).should render('<r:children:each by="title"><r:content /> </r:children:each>').as(expected)
page(:parent).should render('<r:children:each><r:content /> </r:children:each>').as(expected)
end
end
end
Expand All @@ -266,12 +266,12 @@
page.should render('<r:if_content part="asdf">true</r:if_content>').as('')
end

it "should render the contained block if all specified parts (as separated by comma) exist" do
page.should render('<r:if_content part="body, extended">true</r:if_content>').as('true')
it "should render the contained block only if all specified parts (as separated by comma) exist" do
page(:home).should render('<r:if_content part="body, extended">true</r:if_content>').as('true')
end

it "should not render the contained block if all specified parts (as separated by comma) exist" do
page.should render('<r:if_content part="body, madeup">true</r:if_content>').as('')
it "should not render the contained block if at least one of the specified parts (as separated by comma) does not exist" do
page(:home).should render('<r:if_content part="body, madeup">true</r:if_content>').as('')
end
end

Expand Down Expand Up @@ -362,7 +362,7 @@

it "should render a link for the current contextual page" do
expected = %{<a href="/parent/child/">Child</a> <a href="/parent/child-2/">Child 2</a> <a href="/parent/child-3/">Child 3</a> }
page(:parent).should render('<r:children:each by="slug"><r:link /> </r:children:each>' ).as(expected)
page(:parent).should render('<r:children:each><r:link /> </r:children:each>' ).as(expected)
end

it "should scope the link within the relative URL root" do
Expand Down Expand Up @@ -489,7 +489,7 @@
end

it "should scope contained tags to the found page" do
page.should render(%{<r:find url="/parent/"><r:children:each by="slug"><r:slug /> </r:children:each></r:find>}).as('child child-2 child-3 ')
page.should render(%{<r:find url="/parent/"><r:children:each><r:slug /> </r:children:each></r:find>}).as('child child-2 child-3 ')
end

it "should accept a path relative to the current page" do
Expand Down

0 comments on commit 69c3aff

Please sign in to comment.