Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

deprecate to_s in favor of to_html

  • Loading branch information...
commit ef86d0a9d660a237c2fb78b62cfc6ed0e507e824 1 parent add9a6f
@alexch alexch authored
Showing with 123 additions and 122 deletions.
  1. +3 −3 History.txt
  2. +1 −1  README.txt
  3. +2 −2 api-announce.txt
  4. +1 −1  examples/chunks-via-methods.rb
  5. +1 −1  examples/chunks-via-widget.rb
  6. +4 −4 examples/join-with-dummy-array.rb
  7. +4 −4 examples/join.rb
  8. +1 −1  examples/nesting-determines-meaning.rb
  9. +2 −2 examples/wrapping.rb
  10. +5 −9 lib/erector/convenience.rb
  11. +1 −1  lib/erector/erect/erect.rb
  12. +1 −1  lib/erector/externals.rb
  13. +3 −3 lib/erector/mixin.rb
  14. +1 −1  lib/erector/rails/extensions/rails_widget.rb
  15. +13 −8 lib/erector/widget.rb
  16. +1 −1  lib/erector/widgets/page.rb
  17. +1 −1  spec/erect/erected_spec.rb
  18. +11 −11 spec/erector/caching_spec.rb
  19. +5 −5 spec/erector/convenience_spec.rb
  20. +1 −1  spec/erector/externals_spec.rb
  21. +4 −4 spec/erector/indentation_spec.rb
  22. +8 −8 spec/erector/inline_spec.rb
  23. +1 −1  spec/erector/mixin_spec.rb
  24. +11 −11 spec/erector/widget_spec.rb
  25. +6 −6 spec/erector/widgets/field_table_spec.rb
  26. +3 −3 spec/erector/widgets/form_spec.rb
  27. +9 −9 spec/erector/widgets/page_spec.rb
  28. +4 −4 spec/erector/widgets/table_spec.rb
  29. +1 −1  web/index.html
  30. +14 −14 web/userguide.rb
View
6 History.txt
@@ -2,7 +2,7 @@
* barebones Sass support
* "depends_on" is the new way to include JS and CSS files (replacing "external"). More flexible calling structure.
-* :max_length parameter to to_s
+* :max_length parameter to to_html
* jquery method takes optional first parameter (:load or :ready)
== 0.7.3
@@ -71,7 +71,7 @@ Erector tool:
* attempting to 'needs' a variable that overlaps with an existing method raises error
== 0.6.4 / 2009-05-24
-* mixin: do "include Erector::Mixin" and now "erector { }" will instantiate and to_s a widget for you
+* mixin: do "include Erector::Mixin" and now "erector { }" will instantiate and to_html a widget for you
* "erector" command-line tool improved:
* if converting an HTML/ERB file under a "views" directory, uses "Erector::RailsWidget" as parent class
* no longer chokes on "if IE" directives
@@ -88,7 +88,7 @@ and there should be an upgrade guide up on the website soon.
* to render one widget from inside another, use the 'widget' method (not 'render_to'). This method
accepts either a widget instance, or a widget class and an assigns hash.
* 'needs' macro to declare the variables your widget accepts via the 'assigns' constructor parameter
-* Removed Widget#to_s caching, which fixed indentation issues.
+* Removed Widget#to_html caching, which fixed indentation issues.
* BUGFIX: Indentation level is now correctly propagated to nested widgets.
* Erector's Rails support strategy has changed. The released version of Erector only supports the latest stable
Rails version (currently 2.3.2). If you need support for earlier versions of Rails, there are separate
View
2  README.txt
@@ -34,7 +34,7 @@ No, seriously, we've got hella docs at http://erector.rubyforge.org
end
end
- Hello.new(:target => 'world').to_s
+ Hello.new(:target => 'world').to_html
=> "<html><head><title>Hello</title></head><body>Hello, <b class=\"big\">world</b>!</body></html>"
include Erector::Mixin
View
4 api-announce.txt
@@ -1,6 +1,6 @@
Inspired by GoGaRuCo, I just took a shot at rewriting the API. The basic concept is
to clarify the lifecycle of a widget, so "new" accepts permanent state (like "assigns"
-variables) and "to_s" accepts temporary, rendering state (output stream, helpers,
+variables) and "to_html" accepts temporary, rendering state (output stream, helpers,
prettyprinting). This lets you do things like make collections of widgets in once place
in your code and render them in another place, and basically establish a more coherent
API than the 8 different ways I've seen people doing nested widgets (or, more likely,
@@ -15,7 +15,7 @@ me to unify a few concepts and remove some code, especially around prettyprintin
When we're outside a widget, the pattern is:
w = DateWidget.new(:when => Time.now, :title => "Nap Time") # assigns
- puts w.to_s(:helpers => some_rails_view)
+ puts w.to_html(:helpers => some_rails_view)
When we're inside a widget we have a few more options. All of these ways inherit
the rendering state from the parent widget if possible (like output, helpers, and
View
2  examples/chunks-via-methods.rb
@@ -44,5 +44,5 @@ def content
end
-puts Overall.new().to_s
+puts Overall.new().to_html
View
2  examples/chunks-via-widget.rb
@@ -48,5 +48,5 @@ def username
end
-puts overall.to_s
+puts overall.to_html
View
8 examples/join-with-dummy-array.rb
@@ -36,8 +36,8 @@ def content
end
-puts Tabs.new(false, false).to_s
-puts Tabs.new(true, false).to_s
-puts Tabs.new(false, true).to_s
-puts Tabs.new(true, true).to_s
+puts Tabs.new(false, false).to_html
+puts Tabs.new(true, false).to_html
+puts Tabs.new(false, true).to_html
+puts Tabs.new(true, true).to_html
View
8 examples/join.rb
@@ -39,8 +39,8 @@ def content
end
-puts Tabs.new(false, false).to_s
-puts Tabs.new(true, false).to_s
-puts Tabs.new(false, true).to_s
-puts Tabs.new(true, true).to_s
+puts Tabs.new(false, false).to_html
+puts Tabs.new(true, false).to_html
+puts Tabs.new(false, true).to_html
+puts Tabs.new(true, true).to_html
View
2  examples/nesting-determines-meaning.rb
@@ -77,5 +77,5 @@ def chips(*args, &block)
end
-puts overall.to_s
+puts overall.to_html
View
4 examples/wrapping.rb
@@ -16,7 +16,7 @@
div x
end
-puts y.to_s
+puts y.to_html
z = Erector.inline do
div do
@@ -24,4 +24,4 @@
end
end
-puts z.to_s
+puts z.to_html
View
14 lib/erector/convenience.rb
@@ -1,25 +1,21 @@
module Erector
module Convenience
- # Render (like to_s) but adding newlines and indentation.
- # You may just want to call to_s(:prettyprint => true)
+ # Render (like to_html) but adding newlines and indentation.
+ # You may just want to call to_html(:prettyprint => true)
# so you can pass in other rendering options as well.
def to_pretty(options = {})
- to_s(options.merge(:prettyprint => true))
+ to_html(options.merge(:prettyprint => true))
end
- # Render (like to_s) but stripping all tags and inserting some
+ # Render (like to_html) but stripping all tags and inserting some
# appropriate formatting.
def to_text(options = {})
- html = to_s(options.merge(:prettyprint => false))
+ html = to_html(options.merge(:prettyprint => false))
html.gsub!(/(<(ul|ol)>)?<li>/, "\n* ")
html.gsub!(/<(\/?(ul|ol|p|br))( \/)?>/, "\n")
CGI.unescapeHTML(html.gsub(/<[^>]*>/, ''))
end
- def to_html(*args)
- to_s(*args)
- end
-
# Emits the result of joining the elements in array with the separator.
# The array elements and separator can be Erector::Widget objects,
# which are rendered, or strings, which are html-escaped and output.
View
2  lib/erector/erect/erect.rb
@@ -126,7 +126,7 @@ def to_html
FileUtils.mkdir_p(dir)
output_file = "#{dir}/#{filename}.html"
File.open(output_file, "w") do |f|
- f.puts widget.to_s
+ f.puts widget.to_html
end
say " --> #{output_file}\n"
else
View
2  lib/erector/externals.rb
@@ -81,7 +81,7 @@ def render_with_externals(options_to_external_renderer = {})
output = Erector::Output.new
self.to_a(:output => output)
nested_widgets = output.widgets.to_a
- externals = ExternalRenderer.new({:classes => nested_widgets}.merge(options_to_external_renderer)).to_s(:output => output)
+ externals = ExternalRenderer.new({:classes => nested_widgets}.merge(options_to_external_renderer)).to_html(:output => output)
output.to_a
end
View
6 lib/erector/mixin.rb
@@ -1,12 +1,12 @@
module Erector
module Mixin
# Executes the block as if it were the content body of a fresh Erector::Inline,
- # and returns the #to_s value. Since it executes inside the new widget it does not
+ # and returns the #to_html value. Since it executes inside the new widget it does not
# have access to instance variables of the caller, although it does
# have access to bound variables. Funnily enough, the options are passed in to both
- # to_s *and* to the widget itself, so they show up as instance variables.
+ # to_html *and* to the widget itself, so they show up as instance variables.
def erector(options = {}, &block)
- Erector.inline(options, &block).to_s(options)
+ Erector.inline(options, &block).to_html(options)
end
end
end
View
2  lib/erector/rails/extensions/rails_widget.rb
@@ -45,7 +45,7 @@ def self.render(widget, view, assigns = nil, options = {})
view.with_output_buffer do
# Set parent to the view and use Rails's output buffer.
- widget.to_s(options.merge(:parent => view,
+ widget.to_html(options.merge(:parent => view,
:output => Output.new { view.output_buffer }))
end
end
View
21 lib/erector/widget.rb
@@ -11,7 +11,7 @@ module Erector
# the userguide for important details about the scope of this block when run --
# http://erector.rubyforge.org/userguide.html#blocks
#
- # To render a widget from the outside, instantiate it and call its +to_s+
+ # To render a widget from the outside, instantiate it and call its +to_html+
# method.
#
# A widget's +new+ method optionally accepts an options hash. Entries in
@@ -25,7 +25,7 @@ module Erector
# To call one widget from another, inside the parent widget's +content+
# method, instantiate the child widget and call the +widget+ method. This
# assures that the same output stream is used, which gives better
- # performance than using +capture+ or +to_s+. It also preserves the
+ # performance than using +capture+ or +to_html+. It also preserves the
# indentation and helpers of the enclosing class.
#
# In this documentation we've tried to keep the distinction clear between
@@ -66,7 +66,7 @@ def #{attr}
def initialize(assigns = {}, &block)
unless assigns.is_a? Hash
- raise "Erector widgets are initialized with only a parameter hash. (Other parameters are passed to to_s, or the #widget method.)"
+ raise "Erector widgets are initialized with only a parameter hash. (Other parameters are passed to to_html, or the #widget method.)"
end
@_assigns = assigns
@@ -100,16 +100,21 @@ def initialize(assigns = {}, &block)
# Rails view object.
# content_method_name:: in case you want to call a method other than
# #content, pass its name in here.
- def to_s(options = {})
+ def to_html(options = {})
raise "Erector::Widget#to_s now takes an options hash, not a symbol. Try calling \"to_s(:content_method_name=> :#{options})\"" if options.is_a? Symbol
_render(options).to_s
end
-
- # Entry point for rendering a widget (and all its children). Same as #to_s
+
+ # alias for #to_html (deprecated)
+ def to_s(*args)
+ to_html(*args)
+ end
+
+ # Entry point for rendering a widget (and all its children). Same as #to_html
# only it returns an array, for theoretical performance improvements when using a
# Rack server (like Sinatra or Rails Metal).
#
- # # Options: see #to_s
+ # # Options: see #to_html
def to_a(options = {})
_render(options).to_a
end
@@ -149,7 +154,7 @@ def call_block
#
# This is the preferred way to call one widget from inside another. This
# method assures that the same output string is used, which gives better
- # performance than using +capture+ or +to_s+.
+ # performance than using +capture+ or +to_html+.
def widget(target, assigns = {}, options = {}, &block)
if target.is_a? Class
target.new(assigns, &block)._render_via(self, options)
View
2  lib/erector/widgets/page.rb
@@ -156,7 +156,7 @@ def included_head_content
# now that we've rendered the whole page, it's the right time
# to ask what all widgets were rendered to the output stream
included_widgets = [self.class] + output.widgets.to_a + extra_widgets
- ExternalRenderer.new(:classes => included_widgets).to_s
+ ExternalRenderer.new(:classes => included_widgets).to_html
end
def extra_widgets
View
2  spec/erect/erected_spec.rb
@@ -156,7 +156,7 @@ def content
# begin
# convert(".", "<", "")
# rescue => e
-# e.to_s.should include("Could not parse")
+# e.to_html.should include("Could not parse")
# end
# end
View
22 spec/erector/caching_spec.rb
@@ -186,32 +186,32 @@ def content
Family.cachable?.should be_true
end
- describe '#to_s' do
+ describe '#to_html' do
it "caches a rendered widget" do
- Cash.new(:name => "Johnny").to_s
+ Cash.new(:name => "Johnny").to_html
@cache[Cash, {:name => "Johnny"}].to_s.should == "<p>Johnny Cash</p>"
end
it "uses the cached value" do
@cache[Cash, {:name => "Johnny"}] = "CACHED"
- Cash.new(:name => "Johnny").to_s.should == "CACHED"
+ Cash.new(:name => "Johnny").to_html.should == "CACHED"
end
it "doesn't use the cached value for widgets not declared cachable" do
@cache[NotCachable] = "CACHED"
- NotCachable.new.to_s.should == "CONTENT"
+ NotCachable.new.to_html.should == "CONTENT"
end
it "doesn't cache widgets not declared cachable" do
- NotCachable.new.to_s
+ NotCachable.new.to_html
@cache[NotCachable].should be_nil
end
it "doesn't cache widgets initialized with a block (yet)" do
Cash.new(:name => "June") do
text "whatever"
- end.to_s
+ end.to_html
@cache[Cash, {:name => "June"}].should be_nil
end
@@ -228,24 +228,24 @@ def bar
end
end
- widget.new.to_s(:content_method_name => :foo).should == "foo"
- widget.new.to_s(:content_method_name => :bar).should == "bar"
+ widget.new.to_html(:content_method_name => :foo).should == "foo"
+ widget.new.to_html(:content_method_name => :bar).should == "bar"
end
- it "works when passing an existing output as a parameter to to_s"
+ it "works when passing an existing output as a parameter to to_html"
end
describe '#widget' do
it "caches rendered widgets" do
- Family.new.to_s
+ Family.new.to_html
@cache[Cash, {:name => "Johnny"}].to_s.should == "<p>Johnny Cash</p>"
@cache[Cash, {:name => "June"}].to_s.should == "<p>June Cash</p>"
end
it "uses the cached value" do
@cache[Cash, {:name => "Johnny"}] = "JOHNNY CACHED"
- Family.new.to_s.should == "JOHNNY CACHED<p>June Cash</p>"
+ Family.new.to_html.should == "JOHNNY CACHED<p>June Cash</p>"
end
class WidgetWithBlock < Erector::Widget
View
10 spec/erector/convenience_spec.rb
@@ -4,19 +4,19 @@
include Erector::Mixin
describe "#to_pretty" do
- it "calls to_s with :prettyprint => true" do
+ it "calls to_html with :prettyprint => true" do
widget = Erector.inline do
div "foo"
end
- mock(widget).to_s({:prettyprint => true})
+ mock(widget).to_html({:prettyprint => true})
widget.to_pretty
end
- it "passes extra options through to to_s" do
+ it "passes extra options through to to_html" do
widget = Erector.inline do
div "foo"
end
- mock(widget).to_s({:prettyprint => true, :extra => "yay"})
+ mock(widget).to_html({:prettyprint => true, :extra => "yay"})
widget.to_pretty(:extra => "yay")
end
end
@@ -216,7 +216,7 @@ def content
it "can be used as an HTML id" do
widget = DOMIDWidget.new
- widget.to_s.should == "<div id=\"#{widget.dom_id}\"></div>"
+ widget.to_html.should == "<div id=\"#{widget.dom_id}\"></div>"
end
describe 'for a namespaced widget class' do
View
2  spec/erector/externals_spec.rb
@@ -221,7 +221,7 @@ def content
it "#render_externals returns externals for all rendered sub-widgets to an output buffer" do
widget = Dinner.new
- widget.to_s
+ widget.to_html
widget.render_externals.to_s.should ==
"<link href=\"/dessert.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />" +
"<script src=\"/dinner.js\" type=\"text/javascript\"></script>" +
View
8 spec/erector/indentation_spec.rb
@@ -128,9 +128,9 @@
text "One"
p "Two"
end
- widget.to_s.should == "One<p>Two</p>"
+ widget.to_html.should == "One<p>Two</p>"
widget.to_pretty.should == "One\n<p>Two</p>\n"
- widget.to_s.should == "One<p>Two</p>"
+ widget.to_html.should == "One<p>Two</p>"
end
it "can turn on newlines via to_pretty" do
@@ -152,7 +152,7 @@
it "wraps after N characters" do
Erector.inline do
div "the quick brown fox jumps over the lazy dog"
- end.to_s(:max_length => 20).should ==
+ end.to_html(:max_length => 20).should ==
"<div>the quick brown\n" +
"fox jumps over the\n" +
"lazy dog</div>"
@@ -170,7 +170,7 @@
it "preserves raw strings" do
Erector.inline do
div raw("the quick <brown> fox <jumps> over the lazy dog")
- end.to_s(:max_length => 20).should ==
+ end.to_html(:max_length => 20).should ==
"<div>the quick\n" +
"<brown> fox <jumps>\n" +
"over the lazy dog\n" +
View
16 spec/erector/inline_spec.rb
@@ -3,18 +3,18 @@
describe Erector::Widget do
it "provides access to instance variables from the calling context" do
@var = "yay"
- Erector::Widget.new { @var.should == "yay"; @var = "yum" }.to_s
+ Erector::Widget.new { @var.should == "yay"; @var = "yum" }.to_html
@var.should == "yum"
end
it "provides access to bound variables from the calling context" do
var = "yay"
- Erector::Widget.new { var.should == "yay"; var = "yum" }.to_s
+ Erector::Widget.new { var.should == "yay"; var = "yum" }.to_html
var.should == "yum"
end
it "doesn't provide access to Erector methods" do
- Erector::Widget.new { lambda { text "yay" }.should raise_error(NoMethodError) }.to_s
+ Erector::Widget.new { lambda { text "yay" }.should raise_error(NoMethodError) }.to_html
end
describe ".inline" do
@@ -36,16 +36,16 @@
it "doesn't provide access to instance variables from the calling context" do
@var = "yay"
- Erector.inline { text @var }.to_s.should == ""
+ Erector.inline { text @var }.to_html.should == ""
end
it "provides access to bound variables from the calling context" do
var = "yay"
- Erector.inline { text var }.to_s.should == "yay"
+ Erector.inline { text var }.to_html.should == "yay"
end
it "provides access to explicit assigns" do
- Erector.inline(:var => "yay") { text @var }.to_s.should == "yay"
+ Erector.inline(:var => "yay") { text @var }.to_html.should == "yay"
end
it "provides access to methods from the calling context" do
@@ -53,7 +53,7 @@ def helper
"yay"
end
- Erector.inline { text helper }.to_s.should == "yay"
+ Erector.inline { text helper }.to_html.should == "yay"
end
describe "#call_block" do
@@ -64,7 +64,7 @@ def helper
end
# inside the block...
- x.to_s.should ==
+ x.to_html.should ==
"<arg>#{x.object_id}</arg>" + # the argument is the child
"<self>#{x.object_id}</self>" # and self is also the child
end
View
2  spec/erector/mixin_spec.rb
@@ -23,7 +23,7 @@ def name
Thing.new.name.should == "<span class=\"name\">Gabriel <i>Garcia</i> Marquez</span>"
end
- it "passes its parameters to to_s" do
+ it "passes its parameters to to_html" do
class Thing
include Erector::Mixin
def pretty_name
View
22 spec/erector/widget_spec.rb
@@ -5,13 +5,13 @@ module WidgetSpec
describe Erector::Widget do
include Erector::Mixin
- describe "#to_s" do
+ describe "#to_html" do
it "invokes #content and returns the string representation of the rendered widget" do
Class.new(Erector::Widget) do
def content
text "Hello"
end
- end.new.to_s.should == "Hello"
+ end.new.to_html.should == "Hello"
end
it "supports other content methods via :content_method_name" do
@@ -19,23 +19,23 @@ def content
def alternate
text "Alternate"
end
- end.new.to_s(:content_method_name => :alternate).should == "Alternate"
+ end.new.to_html(:content_method_name => :alternate).should == "Alternate"
end
it "returns an HTML-safe string" do
- Erector::Widget.new.to_s.should be_html_safe
+ Erector::Widget.new.to_html.should be_html_safe
end
it "accepts an existing string as an output buffer" do
s = "foo"
- Erector.inline { text "bar" }.to_s(:output => s)
+ Erector.inline { text "bar" }.to_html(:output => s)
s.should == "foobar"
end
it "accepts an existing Output as an output buffer" do
output = Erector::Output.new
output << "foo"
- Erector.inline { text "bar" }.to_s(:output => output)
+ Erector.inline { text "bar" }.to_html(:output => output)
output.to_s.should == "foobar"
end
end
@@ -74,7 +74,7 @@ def content
it "adds the widget to the parent's output widgets" do
inner = Class.new(Erector::Widget)
outer = Erector.inline { widget inner }
- outer.to_s
+ outer.to_html
outer.output.widgets.should include(inner)
end
@@ -102,7 +102,7 @@ def third
end
end
- Parent.new.to_s.should == '123'
+ Parent.new.to_html.should == '123'
end
context "when nested" do
@@ -139,7 +139,7 @@ def content
WhenNested::Grandchild.new(
:parent_widget => WhenNested::Parent,
:child_widget => WhenNested::Child
- ).to_s.should == '<div id="parent_widget"><div id="child_widget"><div id="grandchild"></div></div></div>'
+ ).to_html.should == '<div id="parent_widget"><div id="child_widget"><div id="grandchild"></div></div></div>'
end
it "renders the tag around the rest of the block with proper indentation" do
@@ -168,7 +168,7 @@ def content
end
end
- Parent2.new(:child_widget => child_widget).to_s.should == "<div><b>#{child_widget.dom_id}</b></div>"
+ Parent2.new(:child_widget => child_widget).to_html.should == "<div><b>#{child_widget.dom_id}</b></div>"
end
end
end
@@ -241,7 +241,7 @@ def content
p @foo
p @baz
end
- end.to_s
+ end.to_html
doc = Nokogiri::HTML(html)
doc.css("p").map {|p| p.inner_html}.should == ["bar", "quux"]
end
View
12 spec/erector/widgets/field_table_spec.rb
@@ -30,7 +30,7 @@ def content
end
it "renders the CreateUser form" do
- PasswordForm.new(:username => "bobdole").to_s.should ==
+ PasswordForm.new(:username => "bobdole").to_html.should ==
"<form action=\"/user\" method=\"post\">" +
"<fieldset class=\"field_table\">" +
"<legend>Sign Up</legend>" +
@@ -80,7 +80,7 @@ def content
it "renders a table with no fields and no buttons" do
table = FieldTable.new(:title => "Meals")
- doc = Nokogiri::HTML(table.to_s)
+ doc = Nokogiri::HTML(table.to_html)
doc.css("fieldset legend").text.should == "Meals"
doc.at("fieldset")["class"].should == "field_table"
doc.css("fieldset > table > tr").size.should == 0
@@ -90,7 +90,7 @@ def content
table = FieldTable.new(:title => "Meals") do |t|
t.button { t.input :type => "button", :value => "cancel" }
end
- doc = Nokogiri::HTML(table.to_s)
+ doc = Nokogiri::HTML(table.to_html)
doc.css("fieldset > table > tr").size.should == 1
doc.at("fieldset table tr")["class"].should == "field_table_buttons"
doc.at("td.field_table_button input")["value"].should == "cancel"
@@ -100,7 +100,7 @@ def content
table = FieldTable.new(:title => "Meals") do |t|
t.field("Breakfast") { t.text "scrambled eggs" }
end
- doc = Nokogiri::HTML(table.to_s)
+ doc = Nokogiri::HTML(table.to_html)
doc.css("fieldset > table > tr").size.should == 1
doc.at("fieldset table tr")["class"].should == "field_table_field"
doc.at("fieldset table tr th").text.should == "Breakfast:"
@@ -111,7 +111,7 @@ def content
table = FieldTable.new(:title => "Meals") do |t|
t.field { t.text "yum yum" }
end
- doc = Nokogiri::HTML(table.to_s)
+ doc = Nokogiri::HTML(table.to_html)
doc.css("fieldset > table > tr").size.should == 1
doc.at("fieldset table tr")["class"].should == "field_table_field"
doc.at("fieldset table tr th").text.should == ""
@@ -123,7 +123,7 @@ def content
t.field("Breakfast", "the most important meal of the day") { t.text "eggs" }
t.field("Lunch") { t.text "hot dogs" }
end
- doc = Nokogiri::HTML(table.to_s)
+ doc = Nokogiri::HTML(table.to_html)
doc.at("fieldset table tr").css("td[3]").text.should == "the most important meal of the day"
end
View
6 spec/erector/widgets/form_spec.rb
@@ -5,15 +5,15 @@
include Erector::Mixin
it "defaults to POST, with no magic hidden method param" do
- Form.new(:action => "/foo").to_s.should == "<form action=\"/foo\" method=\"post\"></form>"
+ Form.new(:action => "/foo").to_html.should == "<form action=\"/foo\" method=\"post\"></form>"
end
it "works plainly with GET too" do
- Form.new(:action => "/foo", :method => "get").to_s.should == "<form action=\"/foo\" method=\"get\"></form>"
+ Form.new(:action => "/foo", :method => "get").to_html.should == "<form action=\"/foo\" method=\"get\"></form>"
end
it "uses POST and adds a magic hidden field with a _method param for DELETE" do
- Form.new(:action => "/foo", :method => "delete").to_s.should ==
+ Form.new(:action => "/foo", :method => "delete").to_html.should ==
"<form action=\"/foo\" method=\"post\">"+
"<input name=\"_method\" type=\"hidden\" value=\"delete\" />"+
"</form>"
View
18 spec/erector/widgets/page_spec.rb
@@ -2,7 +2,7 @@
describe Erector::Widgets::Page do
it "works" do
- Erector::Widgets::Page.new.to_s
+ Erector::Widgets::Page.new.to_html
end
it "renders body_content" do
@@ -10,13 +10,13 @@
def body_content
text "body_content"
end
- end.new.to_s.should =~ /body_content/
+ end.new.to_html.should =~ /body_content/
end
it "renders a block passed to new" do
Erector::Widgets::Page.new do
text "nice bod"
- end.to_s.should =~ /nice bod/
+ end.to_html.should =~ /nice bod/
end
it "renders a block passed to content" do
@@ -26,7 +26,7 @@ def content
text "body_content"
end
end
- end.new.to_s.should =~ /body_content/
+ end.new.to_html.should =~ /body_content/
end
it "allows subclasses to provide a css class for the body" do
@@ -34,7 +34,7 @@ def content
def body_attributes
{:class => "funky"}
end
- end.new.to_s.should =~ /<body class=\"funky\">/
+ end.new.to_html.should =~ /<body class=\"funky\">/
end
it "allows subclasses to be called with a block" do
@@ -46,7 +46,7 @@ def body_content
end
fun_page_class.new do
text "soccer!"
- end.to_s.should include("<h3>what's fun?</h3>soccer!")
+ end.to_html.should include("<h3>what's fun?</h3>soccer!")
end
class NiceWidget < Erector::Widget
@@ -73,13 +73,13 @@ def body_content
end
it "only puts into dependencies those from widgets rendered on it" do
- s = NicePage.new.to_s
+ s = NicePage.new.to_html
s.should include("nice page")
s.should include("nice widget")
s.should include(".nice {}")
s.should_not include(".mean {}")
- MeanPage.new.to_s.should include(".mean {}")
- MeanPage.new.to_s.should_not include(".nice {}")
+ MeanPage.new.to_html.should include(".mean {}")
+ MeanPage.new.to_html.should_not include(".nice {}")
end
end
View
8 spec/erector/widgets/table_spec.rb
@@ -24,7 +24,7 @@ class CustomCellTable < Erector::Widgets::Table
attr_reader :html, :doc
before do
widget = CustomHeadingTable.new(:row_objects => [])
- @html = widget.to_s
+ @html = widget.to_html
@doc = Nokogiri::HTML(html)
end
@@ -46,7 +46,7 @@ class CustomCellTable < Erector::Widgets::Table
before do
@object1 = Struct.new(:first_name).new("Hello")
widget = CustomCellTable.new(:row_objects => [@object1])
- @html = widget.to_s
+ @html = widget.to_html
@doc = Nokogiri::HTML(html)
end
@@ -64,7 +64,7 @@ class CustomCellTable < Erector::Widgets::Table
@object2 = Struct.new(:first_name, :last_name, :email).new(4, 5, 6)
@object3 = Struct.new(:first_name, :last_name, :email).new(7, 8, 9)
widget = DefaultsTestTable.new(:row_objects => [@object1, @object2, @object3])
- @html = widget.to_s
+ @html = widget.to_html
@doc = Nokogiri::HTML(html)
@table = doc.at("table")
end
@@ -96,4 +96,4 @@ class CustomCellTable < Erector::Widgets::Table
end
end
end
-end
+end
View
2  web/index.html
@@ -69,7 +69,7 @@ <h1 class="title">Erector - Home</h1>
end
end
- Hello.new(:target =&gt; 'world').to_s
+ Hello.new(:target =&gt; 'world').to_html
=&gt; &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Hello&lt;/title&gt;&lt;/head&gt;&lt;body&gt;Hello, &lt;b class=\&quot;big\&quot;&gt;world&lt;/b&gt;!&lt;/body&gt;&lt;/html&gt;&quot;
include Erector::Mixin
View
28 web/userguide.rb
@@ -65,7 +65,7 @@ def content
p do
text "Once you have a widget class, you can instantiate it and then call its "
- code "to_s"
+ code "to_html"
text " method."
text " If you want to pass in 'locals' (aka 'assigns'), then do so in the constructor's default hash. This will make instance variables of the same name, with Ruby's '@' sign."
end
@@ -76,7 +76,7 @@ def content
end
end
->> Email.new(:address => "foo@example.com").to_s
+>> Email.new(:address => "foo@example.com").to_html
=> "<a href=\"mailto:foo@example.com\">foo@example.com</a>"
PRE
p do
@@ -95,13 +95,13 @@ def content
text " from anywhere in your code. It will make an "
a "inline widget", :href => "#inline"
text " for you, pass in the block, and call "
- code "to_s"
+ code "to_html"
text " on it. And if you pass any options to "
code "erector"
text ", like "
code ":prettyprint => true"
text ", it'll pass them along to "
- code "to_s"
+ code "to_html"
text "!"
end
h3 "Examples:"
@@ -227,19 +227,19 @@ def content
text "call "
code "to_pretty"
text " instead of "
- code "to_s"
+ code "to_html"
text " on your Erector::Widget"
end
li do
text "pass "
code ":prettyprint => true"
text " to "
- code "to_s"
+ code "to_html"
end
li do
text "call "
code "enable_prettyprint(true)"
- text " on your Erector::Widget. Then subsequent calls to to_s will prettyprint"
+ text " on your Erector::Widget. Then subsequent calls to to_html will prettyprint"
end
li do
text "call "
@@ -460,7 +460,7 @@ def content
pre <<DONE
widget = Views::Layouts::Application.new(self)
widget.content = content_for_layout
-self << widget.to_s
+self << widget.to_html
DONE
end
@@ -468,7 +468,7 @@ def content
text "Here the abstract layout widget is used in a concrete fashion by the template-based layout. Normally, the "
code "content"
text " method would be implemented by subclassing widgets, but the layout template sets it directly and then calls "
- code "to_s"
+ code "to_html"
text " on the layout widget. This allows the same layout to be shared in a backward compatible way."
end
end,
@@ -481,23 +481,23 @@ def content
code "content"
text " method, you can pass a block to "
code "Erector.inline"
- text " and get back a widget instance you can call to_s on. For example:"
+ text " and get back a widget instance you can call to_html on. For example:"
pre <<-DONE
html = Erector.inline do
p "Hello, world!"
end
-html.to_s #=> <p>Hello, world!</p>
+html.to_html #=> <p>Hello, world!</p>
DONE
text "This lets you define mini-widgets on the fly."
end
p do
- text "If you're in Rails, your inline block has access to Rails helpers if you pass a helpers object to to_s:"
+ text "If you're in Rails, your inline block has access to Rails helpers if you pass a helpers object to to_html:"
pre <<-DONE
html = Erector.inline do
image_tag("/foo")
end
-html.to_s(:helpers => controller) #=> <img alt="Foo" src="/foo" />
+html.to_html(:helpers => controller) #=> <img alt="Foo" src="/foo" />
DONE
end
@@ -771,7 +771,7 @@ def content
local_name = @name
Page.new do
div local_name
-end.to_s
+end.to_html
DONE
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.