[ANN] cs/Template 0.1.2

S

Sean O'Dell

cs/Template 0.1.2
====================

cs/Template is a fast, generic text templating engine for Ruby, written in C.
Merge native Ruby data structures with text templates to produce final
documents. Data structures may be any combination of Hashes, Arrays and
Objects (works great with YAML input). Produces any type of text document.
Place variables or eval statements anywhere in templates with path-like
addressing, control block execution with if/then/else and generate looping
blocks of text.

project homepage: http://rubyforge.org/projects/cstemplate/
download url: http://rubyforge.org/frs/?group_id=276&release_id=549

Example code
====================

require "celsoft.com/template"
require "yaml"

template = Template::Document.new

template.data = YAML::load <<-END
---
author:
name : Dallas Diegler
email: (e-mail address removed)
title : Interesting things I've done
type : leaflet
END

template.load <<-END
${var title}
A ${var type} by ${var author/name}
email: ${var author/email}
END

print(template.output)



Sean O'Dell
 
D

daz

Sean said:
author:
name : [...]

name : Sean O'Dell

Just a small nit-pick but many people know enough to be
able to spot that mistake.

I thought to avoid using alternatives that came to mind.


daz
 
E

eckelmann

Hi,

very nice template library! I like it because the syntax is xml agnostic
(one thing that turns off of Amrita). I like because it is fast!

Having the ${eval ...} macro is a fine thing, but how can I access the
template data from the eval'd ruby code? Can I even change the data in
an eval block?

Cheers,

Carsten.
 
S

Sean O'Dell

Hi,

very nice template library! I like it because the syntax is xml agnostic
(one thing that turns off of Amrita). I like because it is fast!

Having the ${eval ...} macro is a fine thing, but how can I access the
template data from the eval'd ruby code? Can I even change the data in
an eval block?

You can make the template object a class @@variable, instance @variable or a
global $variable and then you have access to it, and the template#data
method, or you can call template#resolve to use paths to get at your data.

Perhaps I can figure out how to call the eval in the context of the template
itself so ${eval} always has access to @data.

Sean O'Dell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] Ron 0.1.2 Released 1
ANN main-4.4.0 0
[ANN] wxRuby 2.0.0 9
[ANN] xx-2.1.0 2
[ANN] Rassmalog 1.0.0 0
[ANN] tagz-1.0.0 0
[ANN] Futures and JRuby: The Omnibus Concurrency Library 0.2.1 3
[ANN] main-3.0.1 0

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top