Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rtemplate => mustache

  • Loading branch information...
commit f0857e5cf89591624475569b68e525f5e5b8a25e 1 parent 1d6dfee
@defunkt defunkt authored
View
22 README.md
@@ -1,10 +1,10 @@
-rtemplate
+Mustache
=========
Inspired by [ctemplate](http://code.google.com/p/google-ctemplate/)
and
[et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html),
-rtemplate is a framework-agnostic way to render logic-free viesw.
+Mustache is a framework-agnostic way to render logic-free viesw.
It's not a markup language because there is no language. There is no
logic.
@@ -13,7 +13,7 @@ logic.
Overview
--------
-Think of rtemplate as a replacement for your views. Instead of views
+Think of Mustache as a replacement for your views. Instead of views
consisting of ERB or HAML with random helpers and arbitrary logic,
your views are broken into two parts: a Ruby class and an HTML
template.
@@ -43,7 +43,7 @@ Usage
We've got an `examples` folder but here's the canonical one:
- class Simple < RTemplate
+ class Simple < Mustache
def name
"Chris"
end
@@ -164,7 +164,7 @@ Dict-Style Views
----------------
ctemplate and friends want you to hand a dictionary to the template
-processor. Naturally rtemplate supports a similar concept. Feel free
+processor. Naturally Mustache supports a similar concept. Feel free
to mix the class-based and this more procedural style at your leisure.
Given this template (dict.html):
@@ -201,10 +201,10 @@ follows the classic Ruby naming convention.
TemplatePartial => ./template_partial.html
-You can set the search path using `RTemplate.path`. It can be set on a
+You can set the search path using `Mustache.path`. It can be set on a
class by class basis:
- class Simple < RTemplate
+ class Simple < Mustache
self.path = File.dirname(__FILE__)
... etc ...
end
@@ -213,7 +213,7 @@ Now `Simple` will look for `simple.html` in the directory it resides
in, no matter the cwd.
If you want to just change what template is used you can set
-`RTemplate#template_file` directly:
+`Mustache#template_file` directly:
Simple.new.template_file = './blah.html'
@@ -249,7 +249,7 @@ This is just Ruby, after all.
Then just include it:
- class Simple < RTemplate
+ class Simple < Mustache
include ViewHelpers
def name
@@ -272,11 +272,11 @@ Then just include it:
Great, but what about that `@ssl` ivar in `gravatar_host`? There are
many ways we can go about setting it.
-Here's on example which illustrates a key feature of rtemplate: you
+Here's on example which illustrates a key feature of Mustache: you
are free to use the `initialize` method just as you would in any
normal class.
- class Simple < RTemplate
+ class Simple < Mustache
include ViewHelpers
def initialize(ssl = false)
View
1  Rakefile
@@ -2,7 +2,6 @@ require 'rake/testtask'
task :default => :test
-
Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
View
4 examples/comments.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class Comments < RTemplate
+class Comments < Mustache
self.path = File.dirname(__FILE__)
def title
View
4 examples/complex.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class Complex < RTemplate
+class Complex < Mustache
self.path = File.dirname(__FILE__)
def header
View
4 examples/escaped.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class Escaped < RTemplate
+class Escaped < Mustache
self.path = File.dirname(__FILE__)
def title
View
4 examples/simple.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class Simple < RTemplate
+class Simple < Mustache
self.path = File.dirname(__FILE__)
def name
View
4 examples/template_partial.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class TemplatePartial < RTemplate
+class TemplatePartial < Mustache
self.path = File.dirname(__FILE__)
def title
View
4 examples/unescaped.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class Unescaped < RTemplate
+class Unescaped < Mustache
self.path = File.dirname(__FILE__)
def title
View
4 examples/view_partial.rb
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
-require 'rtemplate'
+require 'mustache'
-class ViewPartial < RTemplate
+class ViewPartial < Mustache
self.path = File.dirname(__FILE__)
def greeting
View
4 lib/rtemplate.rb → lib/mustache.rb
@@ -2,13 +2,13 @@
# Blah blah blah?
# who knows.
-class RTemplate
+class Mustache
# Helper method for quickly instantiating and rendering a view.
def self.to_html
new.to_html
end
- # The path informs your RTemplate subclass where to look for its
+ # The path informs your Mustache subclass where to look for its
# corresponding template.
def self.path=(path)
@path = File.expand_path(path)
View
35 lib/mustache/sinatra.rb
@@ -0,0 +1,35 @@
+# Support for Mustache in your Sinatra app.
+#
+# require 'mustache/sinatra'
+#
+# class App < Sinatra::Base
+# include Mustache::Sinatra
+# end
+require 'mustache'
+
+class Mustache
+ module Sinatra
+ def mustache(template, options={}, locals={})
+ render :mustache, template, options, locals
+ end
+
+ def render_mustache(template, data, options, locals, &block)
+ name = Mustache.new.classify(template.to_s)
+
+ if defined?(Views) && Views.const_defined?(name)
+ instance = Views.const_get(name).new
+ else
+ instance = Mustache.new
+ end
+
+ locals.each do |local, value|
+ instance[local] = value
+ end
+
+ instance[:yield] = block.call if block
+
+ instance.template = data
+ instance.to_html
+ end
+ end
+end
View
35 lib/rtemplate/sinatra.rb
@@ -1,35 +0,0 @@
-# Support for RTemplate in your Sinatra app.
-#
-# require 'rtemplate/sinatra'
-#
-# class App < Sinatra::Base
-# include RTemplate::Sinatra
-# end
-require 'rtemplate'
-
-class RTemplate
- module Sinatra
- def rtemplate(template, options={}, locals={})
- render :rtemplate, template, options, locals
- end
-
- def render_rtemplate(template, data, options, locals, &block)
- name = RTemplate.new.classify(template.to_s)
-
- if defined?(Views) && Views.const_defined?(name)
- instance = Views.const_get(name).new
- else
- instance = RTemplate.new
- end
-
- locals.each do |local, value|
- instance[local] = value
- end
-
- instance[:yield] = block.call if block
-
- instance.template = data
- instance.to_html
- end
- end
-end
View
8 test/rtemplate_test.rb → test/mustache_test.rb
@@ -16,7 +16,7 @@
require 'unescaped'
require 'comments'
-class RTemplateTest < Test::Unit::TestCase
+class MustacheTest < Test::Unit::TestCase
def test_complex
assert_equal <<-end_complex, Complex.to_html
<h1>Colors</h1>
@@ -105,14 +105,14 @@ def test_unescaped
end
def test_classify
- assert_equal 'TemplatePartial', RTemplate.new.classify('template_partial')
+ assert_equal 'TemplatePartial', Mustache.new.classify('template_partial')
end
def test_underscore
- assert_equal 'template_partial', RTemplate.new.underscore('TemplatePartial')
+ assert_equal 'template_partial', Mustache.new.underscore('TemplatePartial')
end
def test_namespaced_underscore
- assert_equal 'stat_stuff', RTemplate.new.underscore('Views::StatStuff')
+ assert_equal 'stat_stuff', Mustache.new.underscore('Views::StatStuff')
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.