Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
partials
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed May 18, 2011
1 parent edc2a1b commit 5a640dc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/copy/server.rb
Expand Up @@ -68,6 +68,12 @@ def copy(name, options = {}, &block)
# Append the output buffer.
@_out_buf << format_text(name, content, options)
end

def partial(template)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}.#{@_route.format}"
send(@_route.renderer, template.to_sym, :layout => false)
end
end

def self.config(&block)
Expand Down Expand Up @@ -105,11 +111,11 @@ def self.config(&block)
end

get '*' do
route = Copy::Router.new(params[:splat].first, settings.views)
if route.success?
@_route = Copy::Router.new(params[:splat].first, settings.views)
if @_route.success?
set_cache_control_header
content_type(route.format)
send(route.renderer, route.template, :layout => route.layout)
content_type(@_route.format)
send(@_route.renderer, @_route.template, :layout => @_route.layout)
else
not_found
end
Expand Down
6 changes: 6 additions & 0 deletions test/server_test.rb
Expand Up @@ -112,6 +112,12 @@ class ServerCopyHelperTest < Test::Unit::TestCase
assert last_response.ok?
assert_match %Q(<span class="_copy_editable" data-name="headline">Important!</span>), last_response.body
end

test "partial rendering" do
get 'renders_partials'
assert last_response.ok?, last_response.errors
assert_match "before\none\ntwo\nthree\nafter", last_response.body
end
end

class ServerAdminTest < Test::Unit::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_app/views/_one.html.erb
@@ -0,0 +1 @@
one
1 change: 1 addition & 0 deletions test/test_app/views/_three.html.erb
@@ -0,0 +1 @@
three
2 changes: 2 additions & 0 deletions test/test_app/views/about/_two.html.erb
@@ -0,0 +1,2 @@
two
<%= partial :three %>
4 changes: 4 additions & 0 deletions test/test_app/views/renders_partials.html.erb
@@ -0,0 +1,4 @@
before
<%= partial 'one' %>
<%= partial 'about/two' %>
after

0 comments on commit 5a640dc

Please sign in to comment.