Permalink
Browse files

merged changes for release 0.7.1

  • Loading branch information...
1 parent a039017 commit ee4416704d31e5b8c4b5f744470e2787c67cca92 @filippo committed Jan 20, 2008
Showing with 146 additions and 101 deletions.
  1. +1 −1 Makefile
  2. +1 −1 _build.cfg
  3. +1 −1 conf/configure.ac
  4. +135 −0 doc/overview.edoc
  5. +1 −1 ebin/sgte.app
  6. +1 −1 sgte.pub
  7. +5 −95 src/sgte.erl
  8. +1 −1 src/sgte_dict.erl
View
@@ -35,7 +35,7 @@ test: conf compile
docs: $(SRC_FILES)
erl -noshell -run edoc_run files \
- ["'src/sgte.erl', 'src/sgte_parse.erl', 'src/sgte_render.erl', 'src/sgte_gettext.erl'"] \
+ ["'src/sgte.erl', 'src/sgte_parse.erl', 'src/sgte_render.erl', 'src/sgte_gettext.erl', 'src/sgte_dict.erl'"] \
'[{dir,"$(DOCDIR)"}]' -s init stop
tags: src/*.erl
cd src/ && $(TAG_CMD) $(TAG_FLAGS) $(TAG_FILES)
View
@@ -1,6 +1,6 @@
project : {
name : sgte
- vsn : "0.7.0"
+ vsn : "0.7.1"
},
repositories : ["http://repo.erlware.org/pub"]
View
@@ -1,6 +1,6 @@
AC_INIT(sgte, 0.7, pacini@sgconsulting.it, sgte)
AC_PREREQ(2.59c)
-AC_COPYRIGHT(Copyright (C) 2006-2007 S.G. Consulting)
+AC_COPYRIGHT(Copyright (C) 2006-2008 S.G. Consulting)
EBLOG_DIR=$(dirname `pwd`)
AC_SUBST(EBLOG_DIR)
View
@@ -0,0 +1,135 @@
+@title sgte - A simple Erlang Template Engine
+
+@doc
+<p><em>sgte</em> is a library implementing a Template Engine.
+The template system is inspired on <a href="http://www.stringtemplate.org">String Template</a>
+</p><p>
+The template source can be a string or binary or a filename.
+The use of the engine is as simple as (from the command line):
+<pre>
+> {ok, Compiled} = sgte:compile(TmplStr),
+> sgte:render(Compiled, Data).
+
+or:
+
+> {ok, Compiled} = sgte:compile_file(FileName),
+> sgte:render(Compiled, Data).
+</pre>
+
+When compile/1 or compile_file/1 are called, the template is "compiled"
+to an internal representation made of mixed binaries and erlang terms.
+
+Then one of the render functions (render, render_str, or render_bin)
+can be called passing the Data to be rendered in the template.
+<ul>
+ <li>render/2 and render/3 returns a deep iolist() suitable e.g. to use in yaws</li>
+ <li>render_str/2 and render_str/3 returns a string()</li>
+ <li>render_bin/2 and render_bin/3 returns a list of binaries()</li>
+</ul>
+
+In the rest of the overview the template features will be described using render_str since
+the produced is easier to read.
+</p>
+<p>
+Data can be a Dict or a proplist (e.g. [{attr1, Val1}, {attr2, Val2}])
+Values can be a simple value or a function/1. In this case the function is
+called with Data as an argument.
+</p>
+
+<h3>Template Features</h3>
+<h4>Attribute reference</h4>
+Attribute reference is written as:
+<pre>
+$name$
+</pre> Here is an example:
+<pre>
+> {ok, C} = sgte:compile("Hello $name$!").
+> sgte:render_str(C, [{name, "Filippo").
+"Hello Filippo!"
+</pre>
+You can also use attribute references to access nested structures. Eg.:
+<pre>
+> {ok, C} = sgte:compile("$foo.bar.baz$").
+> sgte:render_str(C, [{foo, [{bar, [{baz, "a string"}]}]}]).
+"a string"
+</pre>
+
+<h4>Template reference</h4>
+<pre>
+$include tmpl$
+</pre> Includes an external compiled template. Eg.:
+<pre>
+> {ok, C1} = sgte:compile("foo").
+> {ok, C2} = sgte:compile("$include t1$ bar").
+> sgte:render_str(C2, [{t1, C1}]).
+"foo bar"
+</pre>
+
+<h4>Application of an attribute to another</h4>
+<pre>
+$apply myFun aVar$
+</pre> When the first attribute is callable you get the
+result of myFun(aVar). Otherwhise the result is the value of
+myFun.
+
+<h4>Conditional evaluation</h4>
+ <pre>
+ $if title$
+ &lt;h1&gt;$title$&lt;/h1&gt;
+ $else$
+ &lt;h1&gt;default title&lt;/h1&gt;
+ $end if$
+ </pre>
+
+<h4>Template application to a list of elements</h4>
+if names is a list [{username, "foo"}, {username, "bar"}]
+<pre>
+$map li names$
+</pre>
+map li template to names. Each element in names is passed to the template with name attr.
+If li is the template:
+<pre>
+&lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;</pre>
+We get the result:
+<pre>
+&lt;li&gt;&lt;b&gt;foo&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;bar&lt;/b&gt;&lt;/li&gt;
+</pre>
+
+In the shell we write something like:
+<pre>
+> {ok, LI} = sgte:compile("&lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;").
+> {ok, NamesC} = sgte:compile("$map li names$").
+> sgte:render_str(NamesC, [{li, LI}, {names, [{username, "foo"}, {username, "bar"}]}]).
+&lt;li&gt;&lt;b&gt;foo&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;bar&lt;/b&gt;&lt;/li&gt;
+</pre>
+
+Another way to express the same template inline all in one step is:
+<pre>
+$map:{&lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;} names$
+</pre>
+<h4>Join of items using a separator</h4>
+<pre>
+> {ok, SEL} = sgte:compile("SELECT $join:{,} columns$ FROM $table$;").
+> sgte:render_str(SEL, [{table, "myTable"}, {columns, ["col1", "col2", "col3"]}]).
+"SELECT col1,col2,col3 FROM myTable;"
+</pre>
+
+<h4>Internationalization support using gettext</h4>
+Gettext is a package that can be found in <a href="http://jungerl.sourceforge.net/">jungerl</a>. It
+supports internationalization using the <a href="http://www.gnu.org/software/gettext/">GNU Gettext format</a>.
+<pre>
+$txt:{Hello World}$
+</pre>
+Here's an example supposing you already have started gettext and you have the .po files containing
+translated strings:
+<pre>
+> {ok, C} = sgte:compile("$txt:{Hello World}$"),
+> sgte:render(C, [{options, [{gettext_lc, "en"}]}]).
+"Hello World"
+> sgte:render(C, [{options, [{gettext_lc, "it"}]}]).
+"Ciao Mondo"
+</pre>
+
+@end
+@author Filippo Pacini <filippo.pacini@gmail.com>
+@copyright 2006 - 2008 S.G. Consulting
View
@@ -1,6 +1,6 @@
{application, sgte,
[{description, "sgte - a simple Erlang template engine"},
- {vsn, "0.7.0"},
+ {vsn, "0.7.1"},
{modules, [sgte,
sgte_parse,
sgte_render,
View
@@ -2,7 +2,7 @@
{packager, {"Filippo Pacini", "pacini@sgconsulting.it"}}.
{category, ["text","web"]}.
{name, "sgte"}.
-{vsn, "0.7.0"}.
+{vsn, "0.7.1"}.
{depends, ["kernel","stdlib"]}.
{keywords, ["template engine","web","template","code generation",
"xml", "dynamic content"]}.
View
@@ -1,4 +1,4 @@
-
+%%%-------------------------------------------------------------------
%%% File : sgte.erl
%%% Author : filippo pacini <pacini@sgconsulting.it>
%%%
@@ -16,97 +16,6 @@
%%% srl. Portions created by S.G. Consulting s.r.l. are Copyright (C)
%%% 2006 S.G. Consulting srl. All Rights Reserved.
%%%
-%%% @doc
-%%% <p>The <em>SGTE</em> module is a library implementing a Template Engine
-%%% The template system is inspired on <a href="http://www.stringtemplate.org">String Template</a>
-%%% </p><p>
-%%% The use of the Engine is as simple as (from the command line):
-%%% <pre>
-%%% > {ok, Compiled} = sgte:compile(TmplStr),
-%%% > sgte:render(Compiled, Data).
-%%% or:
-%%% > {ok, Compiled} = sgte:compile_file(FileName),
-%%% > sgte:render(Compiled, Data).
-%%% </pre>
-%%% Data can be a Dict or a list of tuple (e.g. [{attr1, Val1}, {attr2, Val2}])
-%%% Values can be a simple value or a function/1. In this case the function is
-%%% called with Data as an argument.
-%%% </p>
-%%% <h3>Template Features</h3>
-%%% Below some of the template features.
-%%% <h4>Attribute reference</h4>
-%%% Attribute reference is written as:
-%%% <pre>
-%%% $name$
-%%% </pre> Here is an example:
-%%% <pre>
-%%% > {ok, C} = sgte:compile("Hello $name$!"),
-%%% > sgte:render(C, [{name, "Filippo").
-%%% "Hello Filippo!"
-%%% </pre>
-%%% You can also use attribute references to access nested structures. Eg.:
-%%% <pre>
-%%% > {ok, C} = sgte:compile("$foo.bar.baz$"),
-%%% > sgte:render(C, [{foo, [{bar, [{baz, "a string"}]}]}]),
-%%% "a string"
-%%% </pre>
-%%% <h4>Template reference</h4>
-%%% <pre>
-%%% $include tmpl$
-%%% </pre> Includes an external template.
-%%% <h4>Application of an attribute to another</h4>
-%%% <pre>
-%%% $apply myFun aVar$
-%%% </pre> When the first attribute is callable you get the
-%%% result of myFun(aVar). Otherwhise the result is the value of
-%%% myFun.
-%%% <h4>Conditional evaluation</h4>
-%%% <pre>
-%%% $if title$
-%%% &lt;h1&gt;$title$&lt;/h1&gt;
-%%% $else$
-%%% &lt;h1&gt;default title&lt;/h1&gt;
-%%% $end if$
-%%% </pre>
-%%% <h4>Template application to a list of elements</h4>
-%%% if names is a list [{username, name1}, {username, name2}]
-%%% <pre>
-%%% $map li names$
-%%% </pre>
-%%% map li template to names. Each element in names is passed to the template with name attr.
-%%% If li is the template:
-%%% <pre>
-%%% &lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;</pre>
-%%% We get the result:
-%%% <pre>
-%%% &lt;li&gt;&lt;b&gt;name1&lt;/b&gt;&lt;/li&gt;
-%%% &lt;li&gt;&lt;b&gt;name2&lt;/b&gt;&lt;/li&gt;
-%%% </pre>
-%%% Another way to express the same template inline is:
-%%% <pre>
-%%% $map:{&lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;} names$
-%%% </pre>
-%%% <h4>Join of items using a separator</h4>
-%%% <pre>
-%%% SELECT $join:{,} columns$ FROM $table$;
-%%% </pre>
-%%% <h4>Internationalization support using gettext</h4>
-%%% Gettext is a package that can be found in jungerl. It
-%%% supports internationalization using the GNU Gettext format.
-%%% <pre>
-%%% $txt:{Hello World}$
-%%% </pre>
-%%% Here's an example supposing you already have .po files containing
-%%% translated strings:
-%%% <pre>
-%%% > {ok, C} = sgte:compile("$txt:{Hello World}$"),
-%%% > sgte:render(C, [{options, [{gettext_lc, "en"}]}]).
-%%% "Hello World"
-%%% > sgte:render(C, [{options, [{gettext_lc, "it"}]}]).
-%%% "Ciao Mondo"
-%%% </pre>
-%%%
-%%% @end
%%% Created : 13 Sep 2006 by filippo pacini <pacini@sgconsulting.it>
%%%-------------------------------------------------------------------
-module(sgte).
@@ -184,7 +93,7 @@ render(Compiled, Data, Options) ->
sgte_render:render(Compiled, Data, Options).
%%--------------------------------------------------------------------
-%% @spec render(C::compiled(), Data::data()) -> string()
+%% @spec render(Compiled::compiled(), Data::data()) -> string()
%%
%% @doc Renders the compiled template.
%% @end
@@ -193,8 +102,9 @@ render(Compiled, Data) ->
sgte_render:render(Compiled, Data).
%%--------------------------------------------------------------------
-%% @spec render_str(compiled(), data(), options()) -> string()
-%% @doc Calls render/3 and converts the result to string.
+%% @spec render_str(Compiled::compiled(), Data::data(), Options::options()) -> string()
+%%
+%% @doc Renders the template converting the result to string.
%% @end
%%--------------------------------------------------------------------
render_str(Compiled, Data, Options) ->
View
@@ -16,7 +16,7 @@
%%% 2007 S.G. Consulting srl. All Rights Reserved.
%%%
%%% @doc
-%%% <p>Implements a dictionaryand a record like data structure.
+%%% <p>Implements a dictionary and a record like data structure.
%%% Uses the dict module and extends it to support nested dicts.</p>
%%%
%%% <p>This module is the interface used to access data in the

0 comments on commit ee44167

Please sign in to comment.