Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/mgutz/ramaze into erector

* 'master' of git://github.com/mgutz/ramaze:
  Added strict_xhtml Erector method
  Updated Erector dependencies
  added erector specs
  adding erector engine convenience methods
  adding Erector view engine
  • Loading branch information...
commit 10517edbaccf1354605034baeca00ac368814916 2 parents 98e41a6 + d7d368b
@manveru manveru authored
View
2  .gitignore
@@ -1,3 +1,5 @@
pkg
.yardoc
ydoc
+*~
+*.swp
View
22 lib/ramaze/helper/erector.rb
@@ -0,0 +1,22 @@
+# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
+# All files in this distribution are subject to the terms of the Ruby license.
+
+require 'erector'
+
+module Ramaze
+
+ # Allows you to use some shortcuts for Erector in your Controller.
+
+ # use this inside your controller to directly build Erector
+ # Refer to the Erector-documentation and testsuite for more examples.
+ # Usage:
+ # erector { h1 "Apples & Oranges" } #=> "<h1>Apples &amp; Oranges</h1>"
+ # erector { h1(:class => 'fruits&floots'){ text 'Apples' } } #=> "<h1 class=\"fruits&amp;floots\">Apples</h1>"
+
+ module Helper
+ module Erector
+ include ::Erector::Mixin
+ end
+ end
+end
+
View
1  lib/ramaze/view.rb
@@ -22,6 +22,7 @@ def self.auto_register(name, *exts)
# Engines provided by Innate are:
# ERB, Etanni, None
+ auto_register :Erector, :erector
auto_register :Erubis, :erubis, :rhtml
auto_register :Ezamar, :zmr
auto_register :Gestalt, :ges
View
36 lib/ramaze/view/erector.rb
@@ -0,0 +1,36 @@
+require 'erector'
+
+module Ramaze
+ module View
+ module Erector
+ class ::Erector::Widget
+ alias :raw! :rawtext
+
+ def strict_xhtml(*args, &block)
+ raw! '<?xml version="1.0" encoding="UTF-8"?>'
+ raw! '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">'
+ html(:xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => "en", :lang => "en", &block)
+ end
+
+ def inspect(elem)
+ text elem.inspect
+ end
+ end
+
+ def self.call(action, string)
+ return string, 'text/html' unless action.view
+
+ html = ::Erector.inline do
+ # copy instance variables into Erector context
+ action.instance.instance_variables.each do |v|
+ instance_variable_set(v, action.instance.instance_variable_get(v))
+ end
+
+ eval(string)
+ end.to_s
+
+ return html, 'text/html'
+ end
+ end
+ end
+end
View
3  ramaze.gemspec
@@ -33,6 +33,7 @@ You can now do create a new project:
s.add_runtime_dependency(%q<innate>, ["= 2009.07"])
s.add_development_dependency(%q<Remarkably>, ["~> 0.5.2"])
s.add_development_dependency(%q<bacon>, [">= 1.1.0"])
+ s.add_development_dependency(%q<erector>, [">= 0.7.0"])
s.add_development_dependency(%q<erubis>, [">= 2.6.4"])
s.add_development_dependency(%q<ezamar>, [">= 2009.06"])
s.add_development_dependency(%q<haml>, ["~> 2.2.1"])
@@ -51,6 +52,7 @@ You can now do create a new project:
s.add_dependency(%q<innate>, ["= 2009.07"])
s.add_dependency(%q<Remarkably>, ["~> 0.5.2"])
s.add_dependency(%q<bacon>, [">= 1.1.0"])
+ s.add_dependency(%q<erector>, [">= 0.7.0"])
s.add_dependency(%q<erubis>, [">= 2.6.4"])
s.add_dependency(%q<ezamar>, [">= 2009.06"])
s.add_dependency(%q<haml>, ["~> 2.2.1"])
@@ -70,6 +72,7 @@ You can now do create a new project:
s.add_dependency(%q<innate>, ["= 2009.07"])
s.add_dependency(%q<Remarkably>, ["~> 0.5.2"])
s.add_dependency(%q<bacon>, [">= 1.1.0"])
+ s.add_dependency(%q<erector>, [">= 0.7.0"])
s.add_dependency(%q<erubis>, [">= 2.6.4"])
s.add_dependency(%q<ezamar>, [">= 2009.06"])
s.add_dependency(%q<haml>, ["~> 2.2.1"])
View
60 spec/ramaze/view/erector.rb
@@ -0,0 +1,60 @@
+# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
+# All files in this distribution are subject to the terms of the Ruby license.
+
+require File.expand_path('../../../../spec/helper', __FILE__)
+spec_require 'erector'
+
+Ramaze::App.options.views = 'erector'
+Ramaze::App.options.layouts = 'erector'
+
+class SpecErector < Ramaze::Controller
+ map '/'
+ engine :Erector
+ helper :erector
+ layout :layout
+
+ def index
+ erector { h1 "Erector Index" }
+ end
+
+ def links
+ erector {
+ ul {
+ li { a(:href => r(:index)) { text "Index page" } }
+ li { a(:href => r(:internal)){ text "Internal template" } }
+ li { a(:href => r(:external)){ text "External template" } }
+ }
+ }
+ end
+
+ def strict_xhtml
+ end
+
+ def sum(num1, num2)
+ @num1, @num2 = num1.to_i, num2.to_i
+ end
+end
+
+describe Ramaze::View::Erector do
+ behaves_like :rack_test
+
+ should 'use erector methods' do
+ get('/').body.should == '<div><h1>Erector Index</h1></div>'
+ end
+
+ should 'use other helper methods' do
+ get('/links').body.should == '<div><ul><li><a href="/index">Index page</a></li><li><a href="/internal">Internal template</a></li><li><a href="/external">External template</a></li></ul></div>'
+ end
+
+ should 'render external template' do
+ get('/external').body.should == "<div><h1>External Erector View Template</h1></div>"
+ end
+
+ should 'render external template with instance variables' do
+ get('/sum/1/2').body.should == '<div><p>3</p></div>'
+ end
+
+ should 'render external strict xhtml template' do
+ get('/strict_xhtml').body.should == "<div><?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\"><html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><p>STRICT!</p></html></div>"
+ end
+end
View
1  spec/ramaze/view/erector/external.erector
@@ -0,0 +1 @@
+h1 "External Erector View Template"
View
4 spec/ramaze/view/erector/layout.erector
@@ -0,0 +1,4 @@
+div {
+ # can also use raw! @content
+ raw! @content
+}
View
3  spec/ramaze/view/erector/strict_xhtml.erector
@@ -0,0 +1,3 @@
+strict_xhtml {
+ p "STRICT!"
+}
View
1  spec/ramaze/view/erector/sum.erector
@@ -0,0 +1 @@
+p @num1 + @num2
Please sign in to comment.
Something went wrong with that request. Please try again.