Ruby's flexible and minimal syntax makes it well-suited to writing libraries for various tasks
Erector applies that to HTML (or XML) rendering
(start up erector in script/console and go through the following examples)
class Foo < Erector::Widget
def render
html
end
end
Foo.new().to_s
Erector::Widget.new() do
html
end.to_s
Erector::Widget.new() do
p "foo"
end.to_s
Erector::Widget.new() do
text "hello"
end.to_s
Erector::Widget.new() do
p do
text "hello"
b "world"
end
end.to_s
Erector::Widget.new() do
a :href => "a.html" do
text "world"
end
end.to_s
Erector::Widget.new() do
a "world", :href => "a.html" do
end.to_s
Erector::Widget.new() do
text '<>&'
end.to_s
Hooking erector to rails:
class WelcomeController <
ApplicationController
def index
render :text =>
Views::Welcome::Show.new().to_s
end
end
Structuring views with the usual Ruby techniques: especially inheritance and methods
Responsibilities of a view mechanism:
- quote output
- balance start/end tags
Comparison with ERB and Markaby, quoting:
ERB: no, must call h
Markaby: for strings, not blocks
Erector: yes*
* except when you call raw
Comparison with ERB and Markaby, tag balancing:
ERB: no
Markaby: yes
Erector: yes*
* except when you call raw
Comparison with ERB and Markaby, subpages:
ERB: partials, helpers
Markaby: partials, helpers
Erector: inheritance, methods
Similar libraries in other languages:
- Java: webiyo.sf.net
If there is time:
- Calling helpers from erector
- Writing helpers in erector
2 comments:
Alas, mentioning Webiyo might not be doing your audience much of a favor. There's little point in getting people hooked on abandonware.
Sorry, Brian, but even if you have abandoned webiyo I haven't (although I'll admit I haven't had a need for it lately). Although if there's another similar library in Java (or other languages), I'd be glad to link to those instead.
Post a Comment