Skip to content

Commit

Permalink
minor whitespace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbmerritt committed May 6, 2012
1 parent 623742a commit d6ebbc6
Show file tree
Hide file tree
Showing 22 changed files with 671 additions and 671 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG
@@ -1,8 +1,8 @@
0.7

- changed format of compiled templates from string to binaries
- API changes:
render now returns a deeplist with mixed strings and binaries.
- API changes:
render now returns a deeplist with mixed strings and binaries.
Works without problems in yaws
added render_str to return a string like render worked previously
added render_bin: returns a list of binaries
Expand All @@ -12,11 +12,11 @@

- added nested attribute references for all tokens (eg. foo.bar.baz)
- added sgte_dict module. Wraps the erlang dict module.
- API: added rec_to_name_kv/2 Converts a record to a proplist
to be used in the rendering phase. The result is
- API: added rec_to_name_kv/2 Converts a record to a proplist
to be used in the rendering phase. The result is
{rec_name, [{field1, val1}, {field2, val2}, ...]}
- API: added rec_to_kv/2 Converts a record to a proplist
to be used in the rendering phase. The result is
- API: added rec_to_kv/2 Converts a record to a proplist
to be used in the rendering phase. The result is
[{field1, val1}, {field2, val2}, ...]
- switch unit test to eunit

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -8,7 +8,7 @@ SHELL = /bin/sh

#tags command and options
TAG_CMD = etags
TAG_FLAGS =
TAG_FLAGS =

LIB_FILES = /usr/local/lib/erlang/lib/sg*/*.erl /usr/local/lib/erlang/lib/sg*/src/*.erl

Expand Down
2 changes: 1 addition & 1 deletion conf/configure.ac
Expand Up @@ -44,7 +44,7 @@ AC_SUBST(LD_SHARED)


define(OUTPUT_FILES,
include.mk)
include.mk)

AC_OUTPUT(OUTPUT_FILES,
[
Expand Down
2 changes: 1 addition & 1 deletion conf/include.mk.in
Expand Up @@ -41,7 +41,7 @@ APPSCRIPT = '$$vsn=shift; $$mods=""; while(@ARGV){ $$_=shift; s/^([A-Z].*)$$/\'\
../ebin/%.app: %.app.src ../vsn.mk Makefile
perl -e $(APPSCRIPT) "$(VSN)" $(MODULES) < $< > $@

../ebin/%.appup: %.appup
../ebin/%.appup: %.appup
cp $< $@

../ebin/%.$(EMULATOR): %.erl $(wildcard $(YAWSDIR)/lib/*/*/*.hrl)
Expand Down
20 changes: 10 additions & 10 deletions doc/overview.edoc
@@ -1,10 +1,10 @@
@title sgte - A simple Erlang Template Engine

@doc
<p><em>sgte</em> is a library implementing a 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 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),
Expand All @@ -16,10 +16,10 @@ or:
> sgte:render(Compiled, Data).
</pre>

When compile/1 or compile_file/1 are called, the template is "compiled"
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)
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>
Expand All @@ -32,13 +32,13 @@ 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
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:
Attribute reference is written as:
<pre>
$name$
</pre> Here is an example:
Expand Down Expand Up @@ -72,7 +72,7 @@ $apply myFun aVar$
result of myFun(aVar). Otherwhise the result is the value of
myFun.

<h4>Conditional evaluation</h4>
<h4>Conditional evaluation</h4>
<pre>
$if title$
&lt;h1&gt;$title$&lt;/h1&gt;
Expand All @@ -87,7 +87,7 @@ if names is a list [{username, "foo"}, {username, "bar"}]
$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:
If li is the template:
<pre>
&lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;</pre>
We get the result:
Expand Down Expand Up @@ -115,7 +115,7 @@ $map:{&lt;li&gt;&lt;b&gt;$username$&lt;/b&gt;&lt;/li&gt;} names$
</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
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}$
Expand Down
22 changes: 11 additions & 11 deletions ebin/sgte.app
@@ -1,11 +1,11 @@
{application, sgte,
[{description, "sgte - a simple Erlang template engine"},
{vsn, "0.7.1"},
{modules, [sgte,
sgte_parse,
sgte_render,
sgte_gettext,
sgte_dict]},
{registered, []},
{applications, [kernel, stdlib]}
]}.
{application, sgte,
[{description, "sgte - a simple Erlang template engine"},
{vsn, "0.7.1"},
{modules, [sgte,
sgte_parse,
sgte_render,
sgte_gettext,
sgte_dict]},
{registered, []},
{applications, [kernel, stdlib]}
]}.
96 changes: 48 additions & 48 deletions src/sgte.erl
Expand Up @@ -25,12 +25,12 @@
-endif.

%% API
-export([compile/1,
-export([compile/1,
compile/2,
compile_file/1,
compile_file/2,
render/2,
render/3,
compile_file/1,
compile_file/2,
render/2,
render/3,
render_str/2,
render_str/3,
render_bin/2,
Expand All @@ -57,7 +57,7 @@
%% @type compiled() = [char()|token()]
%% token() = tupe().
%%
%% @doc Compiles the template string T and returns the compiled
%% @doc Compiles the template string T and returns the compiled
%% template or an error.
%% @end
%%--------------------------------------------------------------------
Expand All @@ -73,7 +73,7 @@ compile(T) when is_list(T) ->
%% option() = {encoding, encoding()},
%% encoding() = latin1 | utf8 | {utf16,little} | {utf16,big} | {utf32,little} | {utf32,big}
%%
%% @doc Compiles the template string T and returns the compiled
%% @doc Compiles the template string T and returns the compiled
%% template or an error.
%% @end
%%--------------------------------------------------------------------
Expand All @@ -85,35 +85,35 @@ compile(T, [{encoding, InEncoding}]) when is_list(T) ->
%%--------------------------------------------------------------------
%% @spec compile_file(FileName) -> {ok, C::compiled()} | {error,Reason}
%%
%% @doc Compiles the template file FileName and returns the compiled
%% @doc Compiles the template file FileName and returns the compiled
%% template or an error.
%% @end
%%--------------------------------------------------------------------
compile_file(FileName) ->
case file:read_file(FileName) of
{ok, Bin} ->
compile(Bin);
Err ->
Err
{ok, Bin} ->
compile(Bin);
Err ->
Err
end.
%%--------------------------------------------------------------------
%% @spec compile_file(FileName, Options::options()) -> {ok, C::compiled()} | {error,Reason}
%%
%% @doc Compiles the template file FileName and returns the compiled
%% @doc Compiles the template file FileName and returns the compiled
%% template or an error.
%% @end
%%--------------------------------------------------------------------
compile_file(FileName, Options) ->
case file:read_file(FileName) of
{ok, Bin} ->
compile(Bin, Options);
Err ->
Err
{ok, Bin} ->
compile(Bin, Options);
Err ->
Err
end.

%%--------------------------------------------------------------------
%% @spec render(C::compiled(),
%% Data::data(),
%% @spec render(C::compiled(),
%% Data::data(),
%% Options::options()) -> string()
%%
%% @type data() = [tuple()]|dict()
Expand Down Expand Up @@ -173,7 +173,7 @@ render_bin(Compiled, Data) ->
%%
%% @type gettext_tuple() = {Key, LineNo}
%%
%% @doc Extracts from template T the list of gettext keys
%% @doc Extracts from template T the list of gettext keys
%% with associated line numbers.
%% This is a utility function to use in cojunction with gettext
%% to create initial .po files.
Expand All @@ -183,16 +183,16 @@ gettext_strings(Template) when is_binary(Template) ->
sgte_parse:gettext_strings(unicode:characters_to_list(Template));
gettext_strings(FileName) ->
case file:read_file(FileName) of
{ok, Bin} ->
gettext_strings(Bin);
Err ->
Err
{ok, Bin} ->
gettext_strings(Bin);
Err ->
Err
end.

%%--------------------------------------------------------------------
%% @spec gettext_strings(T::template(), {encoding, Enc::encoding}) -> [gettext_tuple()]
%%
%% @doc Extracts from template T the list of gettext keys
%% @doc Extracts from template T the list of gettext keys
%% with associated line numbers.
%% This is a utility function to use in cojunction with gettext
%% to create initial .po files.
Expand All @@ -202,10 +202,10 @@ gettext_strings(Template, Enc) when is_binary(Template) ->
sgte_parse:gettext_strings(unicode:characters_to_list(Template, Enc));
gettext_strings(FileName, Enc) ->
case file:read_file(FileName) of
{ok, Bin} ->
gettext_strings(Bin, Enc);
Err ->
Err
{ok, Bin} ->
gettext_strings(Bin, Enc);
Err ->
Err
end.

%%--------------------------------------------------------------------
Expand All @@ -214,9 +214,9 @@ gettext_strings(FileName, Enc) ->
%%
%% @type src_files() = [string()]. Source files to parse for gettext strings.
%%
%% @doc Creates the gettext template file (.pot).
%% SrcFiles is the list of files to be parsed for gettext strings.
%% Each gettext string found will be written to the .pot file.
%% @doc Creates the gettext template file (.pot).
%% SrcFiles is the list of files to be parsed for gettext strings.
%% Each gettext string found will be written to the .pot file.
%% The default name of the generated file will be messages.pot.
%% @end
%%--------------------------------------------------------------------
Expand All @@ -225,37 +225,37 @@ gettext_init(SrcFiles) ->
sgte_gettext:gettext_init(TargetDir, SrcFiles, "messages.pot").

%%--------------------------------------------------------------------
%% @spec gettext_init(TargetDir::target_dir(),
%% SrcFiles::src_files()) ->
%% @spec gettext_init(TargetDir::target_dir(),
%% SrcFiles::src_files()) ->
%% ok | {error, Reason}
%%
%% @type target_dir() = string(). Dir where the .pot file will be written
%%
%% @doc Creates the gettext template file (.pot).
%% TargetDir is the directory where the file will be created.
%% If TargetDir doesn't exists it will be created.
%% SrcFiles is the list of files to be parsed for gettext strings.
%% Each gettext string found will be written to the .pot file.
%% @doc Creates the gettext template file (.pot).
%% TargetDir is the directory where the file will be created.
%% If TargetDir doesn't exists it will be created.
%% SrcFiles is the list of files to be parsed for gettext strings.
%% Each gettext string found will be written to the .pot file.
%% The file name of the generated file will be messages.pot.
%% @end
%%--------------------------------------------------------------------
gettext_init(TargetDir, SrcFiles) ->
sgte_gettext:gettext_init(TargetDir, SrcFiles, "messages.pot").

%%--------------------------------------------------------------------
%% @spec gettext_init(TargetDir::target_dir(),
%% SrcFiles::src_files(),
%% Domain::domain()) ->
%% @spec gettext_init(TargetDir::target_dir(),
%% SrcFiles::src_files(),
%% Domain::domain()) ->
%% ok | {error, Reason}
%%
%% @type domain() = string(). The name of the .po file to write.
%%
%% @doc Creates the gettext template file (.pot).
%% TargetDir is the directory where the file will be created.
%% If TargetDir doesn't exists it will be created.
%% SrcFiles is the list of files to be parsed for gettext strings.
%% Each gettext string found will be written to the .pot file.
%% Domain (when present) is the name of the file to generate.
%% @doc Creates the gettext template file (.pot).
%% TargetDir is the directory where the file will be created.
%% If TargetDir doesn't exists it will be created.
%% SrcFiles is the list of files to be parsed for gettext strings.
%% Each gettext string found will be written to the .pot file.
%% Domain (when present) is the name of the file to generate.
%% If no Domain is defined the default name will be messages.pot.
%% @end
%%--------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions src/sgte_dict.erl
Expand Up @@ -15,11 +15,11 @@
%%% srl. Portions created by S.G. Consulting s.r.l. are Copyright (C)
%%% 2007 S.G. Consulting srl. All Rights Reserved.
%%%
%%% @doc
%%% <p>Implements a dictionary and a record like data structure.
%%% @doc
%%% <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
%%% <p>This module is the interface used to access data in the
%%% render phase.</p>
%%% @end
%%%
Expand All @@ -37,10 +37,10 @@
rfoldl/2,
rfoldr/2,
rappend/3,
find/2,
store/3,
merge/3,
from_list/1,
find/2,
store/3,
merge/3,
from_list/1,
rec_to_name_kv/2,
rec_to_kv/2]).

Expand Down Expand Up @@ -149,7 +149,7 @@ rec_to_name_kv(RecordTuple, Keys) ->
{error, too_much_keys}
end
end.

rec_to_kv(RecordTuple, Keys) ->
[_Name|Values] = tuple_to_list(RecordTuple),
case length(Values) =:= length(Keys) of
Expand Down

0 comments on commit d6ebbc6

Please sign in to comment.