test/unit/test_render.rb in spontaneous-0.2.0.alpha7 vs test/unit/test_render.rb in spontaneous-0.2.0.beta1
- old
+ new
@@ -3,14 +3,14 @@
require File.expand_path('../../test_helper', __FILE__)
require 'sinatra/base'
class RenderTest < MiniTest::Spec
- include Spontaneous
def setup
@site = setup_site
+ Content.delete
end
def teardown
teardown_site
Spontaneous::Output.cache_templates = false
@@ -20,19 +20,17 @@
@template_root ||= File.expand_path(File.join(File.dirname(__FILE__), "../fixtures/templates"))
end
context "Publish rendering step" do
setup do
- Content.delete
@site.paths.add(:templates, template_root)
- class ::Page < Spontaneous::Page
- field :title
- box :sections1
- box :sections2
- end
- class ::TemplateClass < Spontaneous::Piece
+ Page.field :title
+ Page.box :sections1
+ Page.box :sections2
+
+ class ::TemplateClass < ::Piece
field :title do
def to_epub
to_html
end
end
@@ -101,23 +99,23 @@
should "use a cache for navigation pages" do
a = b = c = nil
template = '%{ navigation do |section, active| }${section.object_id} %{ end }'
renderer = Spontaneous::Output::Template::PreviewRenderer.new
- a = renderer.render_string(template, S::Content[@section1.id].output(:html), {}).strip
- b = renderer.render_string(template, S::Content[@section1.id].output(:html), {}).strip
+ a = renderer.render_string(template, ::Content[@section1.id].output(:html), {}).strip
+ b = renderer.render_string(template, ::Content[@section1.id].output(:html), {}).strip
a.should_not == b
renderer = Spontaneous::Output::Template::PublishRenderer.new
template = '%{ navigation do |section, active| }${section.object_id} %{ end }'
- a = renderer.render_string(template, S::Content[@section1.id].output(:html), {}).strip
- b = renderer.render_string(template, S::Content[@section1.id].output(:html), {}).strip
+ a = renderer.render_string(template, ::Content[@section1.id].output(:html), {}).strip
+ b = renderer.render_string(template, ::Content[@section1.id].output(:html), {}).strip
a.should == b
renderer = Spontaneous::Output::Template::PublishRenderer.new
template = '%{ navigation do |section, active| }${section.object_id} %{ end }'
- c = renderer.render_string(template, S::Content[@section1.id].output(:html), {}).strip
+ c = renderer.render_string(template, ::Content[@section1.id].output(:html), {}).strip
a.should_not == c
end
should "be able to render themselves to HTML" do
@content.render.should == "<html><title>The Title</title><body>The Description</body></html>\n"
@@ -168,14 +166,32 @@
child.title = "Child2 Title"
child.description = "Child2 Description"
@content.bits << child
@content.bits.last.style = TemplateClass.get_style(:this_template)
@content.bits.last.hide!
- @content.render.should == "<complex>\nThe Title\n<piece><html><title>Child Title</title><body>Child Description</body></html>\n</piece>\n</complex>\n"
+
+ expected = "<complex>\nThe Title\n<piece><html><title>Child Title</title><body>Child Description</body></html>\n</piece>\n</complex>\n"
+ @content.render.should == expected
end
end
+ context "fields" do
+ should "render a joined list of field values" do
+ Page.field :description, :markdown
+ Page.field :image
+ ::Page.layout do
+ %(${ fields })
+ end
+ @page.title = "Title & Things"
+ @page.image = "/photo.jpg"
+ @page.description = "Description & Stuff"
+ lines = @page.render.split(/\n(?=<div)/)
+ @page.fields.each_with_index do |field, i|
+ lines[i].should =~ /<div.+?>#{field.render(:html)}<\/div>/
+ end
+ end
+ end
context "boxes" do
setup do
TemplateClass.style :slots_template, :default => true
TemplateClass.box :images
@page = ::Page.new
@@ -188,13 +204,28 @@
@child.description = "Child Description"
@content.images << @child
@content.images.first.style = TemplateClass.get_style(:this_template)
end
+ should "render box sets as a joined list of each box's output" do
+ ::Page.layout do
+ %(${ content })
+ end
+ @page.render.should == @page.boxes.map(&:render).join("\n")
+ end
+
+ should "render 'boxes' as a joined list of each box's output" do
+ ::Page.layout do
+ %(${ boxes })
+ end
+ @page.render.should == @page.boxes.map(&:render).join("\n")
+ end
+
should "render boxes" do
@content.render.should == "<boxes>\n <img><html><title>Child Title</title><body>Child Description</body></html>\n</img>\n</boxes>\n"
end
+
should "render boxes to alternate formats" do
::Page.add_output :pdf
@content.render(:pdf).should == "<boxes-pdf>\n <img><PDF><title>Child Title</title><body>{Child Description}</body></PDF>\n</img>\n</boxes-pdf>\n"
end
end
@@ -323,10 +354,10 @@
assert_correct_template(@parent, template_root / 'layouts/page_style')
@page.render.should == "<html></html>\n"
end
should "persist sub-page style settings" do
- @parent = Page[@parent.id]
+ @parent = Content[@parent.id]
@parent.contents.first.style.should == PageClass.default_style
end
should "render using the inline style" do
assert_correct_template(@parent.contents.first, template_root / 'page_class/inline_style')