| 1 |
%w{ erubis redcloth bluecloth markaby haml }.each do |engine| |
|---|
| 2 |
begin |
|---|
| 3 |
require engine |
|---|
| 4 |
rescue LoadError |
|---|
| 5 |
next |
|---|
| 6 |
end |
|---|
| 7 |
end |
|---|
| 8 |
|
|---|
| 9 |
module Vintage |
|---|
| 10 |
# Core rendering class. |
|---|
| 11 |
class Renderer |
|---|
| 12 |
# Render an ERb template. Uses Erubis if available |
|---|
| 13 |
# and if not, falls back to standard ERb. |
|---|
| 14 |
def self.erb(template, request) |
|---|
| 15 |
if Erubis |
|---|
| 16 |
Erubis::Eruby.new(template).evaluate(request) |
|---|
| 17 |
else |
|---|
| 18 |
ERB.new(template).result(request.send(:binding)) |
|---|
| 19 |
end |
|---|
| 20 |
end |
|---|
| 21 |
|
|---|
| 22 |
# Render a HAML template. |
|---|
| 23 |
def self.haml(template, request) |
|---|
| 24 |
if Haml |
|---|
| 25 |
Haml::Engine.new(template).render(request) |
|---|
| 26 |
else |
|---|
| 27 |
raise "You don't have Haml installed!" |
|---|
| 28 |
end |
|---|
| 29 |
end |
|---|
| 30 |
|
|---|
| 31 |
# Render a Textile template using RedCloth. |
|---|
| 32 |
def self.textile(template, request) |
|---|
| 33 |
if RedCloth |
|---|
| 34 |
RedCloth.new(template).to_html |
|---|
| 35 |
else |
|---|
| 36 |
raise "You don't have RedCloth installed!" |
|---|
| 37 |
end |
|---|
| 38 |
end |
|---|
| 39 |
|
|---|
| 40 |
# Render a Markdown template using BlueCloth, or |
|---|
| 41 |
# if that isn't available, using RedCloth. |
|---|
| 42 |
def self.markdown(template, request) |
|---|
| 43 |
if BlueCloth |
|---|
| 44 |
BlueCloth.new(template).to_html |
|---|
| 45 |
elsif RedCloth |
|---|
| 46 |
RedCloth.new(template).to_html |
|---|
| 47 |
else |
|---|
| 48 |
raise "You don't have BlueCloth or RedCloth installed!" |
|---|
| 49 |
end |
|---|
| 50 |
end |
|---|
| 51 |
|
|---|
| 52 |
# Render a Markaby template. |
|---|
| 53 |
def self.mab(template, request) |
|---|
| 54 |
if Markaby |
|---|
| 55 |
Markaby::Builder.new.instance_eval(template).to_s |
|---|
| 56 |
else |
|---|
| 57 |
raise "You don't have Markaby installed!" |
|---|
| 58 |
end |
|---|
| 59 |
end |
|---|
| 60 |
|
|---|
| 61 |
end |
|---|
| 62 |
end |
|---|