Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rename render to emit

  • Loading branch information...
commit bcb3ea2dfc4d407a44b6da2d611b794e07d1d3c9 1 parent 56d4c8b
Alex Chaffee alexch authored
9 History.txt
View
@@ -4,10 +4,11 @@
* 'scss' external type [needs tests]
* dot-class and dot-id-bang syntax
* expanded widget hierarchy; now XMLWidget can be used as the base for a non-HTML widget (for XML formats that may not want the HTML tags and methods)
-* 'render' method as preferred synonym for to_html (since we now support non-HTML widgets)
+* 'emit' method as preferred synonym for to_html (since we now support non-HTML widgets)
* 'tag' macro to add your own tag types (esp. to XML widgets)
* :snake_case option to tag (if you want the method name to be nice for a CamelCase tag name)
* remove dependency on rake gem
+* rename 'render' method to 'emit' (to reduce confusion with Rails' "render" methods)
Deprecated or Removed:
@@ -15,7 +16,11 @@ Deprecated or Removed:
* element! -- removed
* empty_element -- removed
* all_tags -- removed (perhaps to be replaced)
-* to\_s -- use render or to\_html instead
+* to\_s -- use emit or to\_html instead
+
+== 0.8.3
+
+* Finally merged bigfix/rails3 branch - Erector now works with either Rails 2 or Rails 3 (or neither)
== 0.8.2 - 2011-02-16
26 lib/erector/abstract_widget.rb
View
@@ -85,12 +85,12 @@ def initialize(assigns = {}, &block)
# content_method_name:: in case you want to call a method other than
# #content, pass its name in here.
#
- def render(options = {})
- _render(options).to_s
+ def emit(options = {})
+ _emit(options).to_s
end
- # alias for #render
- # @deprecated Please use {#render} instead
+ # alias for #emit
+ # @deprecated Please use {#emit} instead
def to_s(*args)
unless defined? @@already_warned_to_s
$stderr.puts "Erector::Widget#to_s is deprecated. Please use #to_html instead. Called from #{caller.first}"
@@ -103,9 +103,9 @@ def to_s(*args)
# #render / #to_html only it returns an array, for theoretical performance
# improvements when using a Rack server (like Sinatra or Rails Metal).
#
- # # Options: see #render
+ # # Options: see #emit
def to_a(options = {})
- _render(options).to_a
+ _emit(options).to_a
end
# Template method which must be overridden by all widget subclasses.
@@ -142,7 +142,7 @@ def call_block
# the second argument is a hash used to populate its instance variables.
# If the first argument is an instance then the hash must be unspecified
# (or empty). If a block is passed to this method, then it gets set as the
- # rendered widget's block, and will be executed when that widget calls
+ # emited widget's block, and will be executed when that widget calls
# +call_block+ or calls +super+ from inside its +content+ method.
#
# This is the preferred way to call one widget from inside another. This
@@ -150,12 +150,12 @@ def call_block
# 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)
+ target.new(assigns, &block)._emit_via(self, options)
else
unless assigns.empty?
raise "Unexpected second parameter. Did you mean to pass in assigns when you instantiated the #{target.class.to_s}?"
end
- target._render_via(self, options, &block)
+ target._emit_via(self, options, &block)
end
end
@@ -175,7 +175,7 @@ def capture
protected
# executes this widget's #content method, which emits stuff onto the
# output stream
- def _render(options = {}, &block)
+ def _emit(options = {}, &block)
@_block = block if block
@_parent = options[:parent] || parent
@_helpers = options[:helpers] || parent
@@ -195,9 +195,9 @@ def _render(options = {}, &block)
output
end
- # same as _render, but using a parent widget's output stream and helpers
- def _render_via(parent, options = {}, &block)
- _render(options.merge(:parent => parent,
+ # same as _emit, but using a parent widget's output stream and helpers
+ def _emit_via(parent, options = {}, &block)
+ _emit(options.merge(:parent => parent,
:output => parent.output,
:helpers => parent.helpers), &block)
end
4 lib/erector/caching.rb
View
@@ -74,7 +74,7 @@ def should_cache?
end
protected
- def _render(options = {})
+ def _emit(options = {})
if should_cache?
cache[self.class, assigns, options[:content_method_name]] ||= super
else
@@ -82,7 +82,7 @@ def _render(options = {})
end
end
- def _render_via(parent, options = {})
+ def _emit_via(parent, options = {})
if should_cache?
parent.output << cache[self.class, assigns, options[:content_method_name]] ||= parent.capture { super }
parent.output.widgets << self.class # todo: test!!!
2  lib/erector/convenience.rb
View
@@ -4,7 +4,7 @@ module Convenience
# You may just want to call to_html(:prettyprint => true)
# so you can pass in other rendering options as well.
def to_pretty(options = {})
- render(options.merge(:prettyprint => true))
+ emit(options.merge(:prettyprint => true))
end
# Render (like to_html) but stripping all tags and inserting some
20 lib/erector/externals.rb
View
@@ -2,8 +2,8 @@ module Erector
# Externals are a mechanism by which a widget can declare page-level
# resources upon which it depends. They are not emitted during the widget's
- # normal rendering process. Rather, the Erector::Widget::Page keeps track of
- # all the widgets it renders, then goes back and inserts the proper tags for
+ # normal emiting process. Rather, the Erector::Widget::Page keeps track of
+ # all the widgets it emits, then goes back and inserts the proper tags for
# all the externals inside its HEAD element.
module Externals
def self.included(base)
@@ -83,21 +83,21 @@ def interpret_args(*args)
end
end
- def render_with_externals(options_to_external_renderer = {})
+ def render_with_externals(options_to_external_emiter = {})
output = Erector::Output.new
- self.to_a(:output => output) # render all the externals onto this new output buffer
+ self.to_a(:output => output) # emit all the externals onto this new output buffer
nested_widgets = output.widgets.to_a
- options_to_external_renderer = {:classes => nested_widgets}.merge(options_to_external_renderer)
- renderer = ExternalRenderer.new(options_to_external_renderer)
- externals = renderer.to_a(:output => output)
+ options_to_external_emiter = {:classes => nested_widgets}.merge(options_to_external_emiter)
+ emiter = ExternalRenderer.new(options_to_external_emiter)
+ externals = emiter.to_a(:output => output)
output.to_a
end
- def render_externals(options_to_external_renderer = {})
+ def render_externals(options_to_external_emiter = {})
output_for_externals = Erector::Output.new
nested_widgets = output.widgets
- externalizer = ExternalRenderer.new({:classes => nested_widgets}.merge(options_to_external_renderer))
- externalizer._render(:output => output_for_externals)
+ externalizer = ExternalRenderer.new({:classes => nested_widgets}.merge(options_to_external_emiter))
+ externalizer._emit(:output => output_for_externals)
output_for_externals.to_a
end
end
1  lib/erector/rails3.rb
View
@@ -111,6 +111,7 @@ def capture(&block)
end
end
+ # Wrap Rails' render method, to capture output from partials etc.
def render(*args, &block)
captured = helpers.capture do
helpers.concat(helpers.render(*args, &block))
2  lib/erector/widget.rb
View
@@ -77,7 +77,7 @@ class Widget < HTMLWidget
# alias for AbstractWidget#render
def to_html(options = {})
raise "Erector::Widget#to_html takes an options hash, not a symbol. Try calling \"to_html(:content_method_name=> :#{options})\"" if options.is_a? Symbol
- _render(options).to_s
+ _emit(options).to_s
end
# alias for #to_html
2  lib/erector/xml_widget.rb
View
@@ -108,7 +108,7 @@ def comment(text = '')
rawtext "-->\n"
end
- alias_method :to_xml, :render
+ alias_method :to_xml, :emit
protected
4 spec/erector/convenience_spec.rb
View
@@ -8,7 +8,7 @@
widget = Erector.inline do
div "foo"
end
- mock(widget).render({:prettyprint => true})
+ mock(widget).emit({:prettyprint => true})
widget.to_pretty
end
@@ -17,7 +17,7 @@
widget = Erector.inline do
div "foo"
end
- mock(widget).render({:prettyprint => true, :extra => "yay"})
+ mock(widget).emit({:prettyprint => true, :extra => "yay"})
widget.to_pretty(:extra => "yay")
end
end
2  spec/erector/xml_widget_spec.rb
View
@@ -48,7 +48,7 @@ def channel_content
describe Erector::XMLWidget do
it "can be overriden for a plain XML doc" do
- SampleChannel.new.render(:prettyprint => true).should == <<-XML
+ SampleChannel.new.emit(:prettyprint => true).should == <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
2  web/section.rb
View
@@ -1,4 +1,4 @@
-class Section < Erector::Widget
+class Section < Erector::InlineWidget
needs :name, :href => nil, :sections => []
attr_reader :name, :sections
Please sign in to comment.
Something went wrong with that request. Please try again.