Skip to content

Commit

Permalink
fixes for :text style printing and embedding raw content
Browse files Browse the repository at this point in the history
  • Loading branch information
baccigalupi committed Apr 18, 2011
1 parent ba954b8 commit 76aa858
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
20 changes: 11 additions & 9 deletions lib/renderers/text.rb
Expand Up @@ -19,18 +19,20 @@ def render
str
end

def line_end
[:pretty, :text].include?(style) ? "\n" : ''
def escaped_content
if escape
str = ERB::Util.h(content)
if style == :pretty
str = str.wrap(Garterbelt.wrap_length, :indent => indent)
end
str
else
content
end
end

def template
str = escape ? ERB::Util.h(content) : content

if style == :pretty
"#{str.wrap(Garterbelt.wrap_length, :indent => indent)}#{line_end}"
else
"#{str}#{line_end}"
end
"#{escaped_content}#{line_end}"
end
end
end
@@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
alert("foo");
alert("bar");
var foo = 'foo';
</script>
<style type="text/css">
body { background-color: blue;}
p { background-color: white;}
</style>
</head>
<body>
<p>
Style me up!
</p>
</body>
</html>
5 changes: 3 additions & 2 deletions spec/integration/expectations/unescaping_view.html
@@ -1,2 +1,3 @@
You should check out my rad new site:<br> <a class="user_generated_link"
href="http://foo.com">http://foo.com</a><br> It will blow your mind!
You should check out my rad new site:<br>
<a class="user_generated_link" href="http://foo.com">http://foo.com</a><br>
It will blow your mind!
4 changes: 4 additions & 0 deletions spec/integration/integration_spec.rb
Expand Up @@ -74,5 +74,9 @@ def file(name)
it 'does text only' do
ViewWithContentTags.new.render(:style => :text).should == file("render_styles/text")
end

it 'styles do not screw up text line breaks, especially with raw text embeds' do
PrettyWithEmbeds.new.render.should == file('render_styles/pretty_with_embeds')
end
end
end
25 changes: 25 additions & 0 deletions spec/integration/templates/pretty_with_embeds.rb
@@ -0,0 +1,25 @@
class PrettyWithEmbeds < Garterbelt::Page
def head
script 'type' => 'text/javascript' do
[
'alert("foo");',
"alert(\"bar\");\nvar foo = 'foo';"
].each do |js|
raw_text js
end
end

style 'type' => 'text/css' do
[
"body { background-color: blue;}",
"p { background-color: white;}"
].each do |css|
raw_text css
end
end
end

def body
p "Style me up!"
end
end

0 comments on commit 76aa858

Please sign in to comment.