Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 163 lines (139 sloc) 7.72 kb
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
1 %%%-------------------------------------------------------------------
8bad98d @rsaccon server bugfixes
rsaccon authored
2 %%% File: erlydtl.erl
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
3 %%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
873b0ef @rsaccon monster commit: integrated Evan's changes (much improved everything)
rsaccon authored
4 %%% @author Evan Miller <emmiller@gmail.com>
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
5 %%% @author Andreas Stenius <kaos@astekk.se>
873b0ef @rsaccon monster commit: integrated Evan's changes (much improved everything)
rsaccon authored
6 %%% @copyright 2008 Roberto Saccon, Evan Miller
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
7 %%% @copyright 2014 Andreas Stenius
c484084 @kaos Fix indentation according to erlang-mode.
kaos authored
8 %%% @doc
7a2813e @evanmiller * Run functional tests from "make test"
evanmiller authored
9 %%% Public interface for ErlyDTL
c484084 @kaos Fix indentation according to erlang-mode.
kaos authored
10 %%% @end
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
11 %%%
12 %%% The MIT License
13 %%%
873b0ef @rsaccon monster commit: integrated Evan's changes (much improved everything)
rsaccon authored
14 %%% Copyright (c) 2008 Roberto Saccon, Evan Miller
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
15 %%% Copyright (c) 2014 Andreas Stenius
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
16 %%%
17 %%% Permission is hereby granted, free of charge, to any person obtaining a copy
18 %%% of this software and associated documentation files (the "Software"), to deal
19 %%% in the Software without restriction, including without limitation the rights
20 %%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 %%% copies of the Software, and to permit persons to whom the Software is
22 %%% furnished to do so, subject to the following conditions:
23 %%%
24 %%% The above copyright notice and this permission notice shall be included in
25 %%% all copies or substantial portions of the Software.
26 %%%
27 %%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 %%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 %%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 %%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 %%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 %%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 %%% THE SOFTWARE.
34 %%%
873b0ef @rsaccon monster commit: integrated Evan's changes (much improved everything)
rsaccon authored
35 %%% @since 2007-11-11 by Roberto Saccon, Evan Miller
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
36 %%% @since 2014 by Andreas Stenius
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
37 %%%-------------------------------------------------------------------
afbb1cd @rsaccon bug-fixes (now blocks can contain variables as well)
rsaccon authored
38 -module(erlydtl).
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
39 -author('rsaccon@gmail.com').
873b0ef @rsaccon monster commit: integrated Evan's changes (much improved everything)
rsaccon authored
40 -author('emmiller@gmail.com').
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
41 -author('Andreas Stenius <kaos@astekk.se>').
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
42
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
43
44 %% --------------------------------------------------------------------
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
45 %% API
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
46 %% --------------------------------------------------------------------
47
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
48 -export([compile_file/2, compile_file/3]).
49 -export([compile_template/2, compile_template/3]).
7a2813e @evanmiller * Run functional tests from "make test"
evanmiller authored
50 -export([compile/2, compile/3]).
6b746f2 @evanmiller Add compile_dir functions to erlydtl module
evanmiller authored
51 -export([compile_dir/2, compile_dir/3]).
756ac25 @rsaccon housekeeping (for currently broken)
rsaccon authored
52
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
53 -type position() :: non_neg_integer().
54 -type location() :: none | position() | {Line::position(), Column::position()}.
26cb8fc @kaos Bring compile_dir up-to-date.
kaos authored
55 -type error_info() :: {File::list(),
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
56 [{location(),
26cb8fc @kaos Bring compile_dir up-to-date.
kaos authored
57 Module::atom(),
58 ErrorDesc::term()}]}.
59 -type errors() :: list(error_info()).
60 -type warnings() :: list(error_info()).
61 -type ok_ret() :: {ok, Module::atom()} | {ok, Module::atom(), warnings()}.
62 -type err_ret() :: error | {error, errors(), warnings()}.
63
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
64 -type filename() :: file:name_all().
65
66 -type compiler_options() :: compiler_option() | compile:option().
67 -type compiler_option() :: return | return_warnings | return_errors
68 | report | report_warnings | report_errors
69 | warnings_as_errors | debug_info | verbose.
70
71 -type compile_options() :: [compile_option() | {atom(), term()}].
72 -type compile_option() :: compiler_option()
73 | auto_escape | binary | binary_strings
74 | force_recompile | no_env | no_load
75 | {blocktrans_fun, Trans::fun((Block::iodata(), Locale::string()) ->
76 iodata() | default)}
77 | {blocktrans_locales, [string()]}
78 | {compiler_options, [compiler_options()]}
79 | {custom_filters_modules, [Module::atom]}
80 | {custom_tags_dirs, [filename()]}
81 | {custom_tags_modules, [Module::atom]}
82 | {default_libraries, [Name::atom()]}
83 | {doc_root, filename()}
84 | {extension_module, Module::atom()}
85 | {libraries, [{Name::atom(), Module::atom()}]}
86 | {locale, string()}
87 | {out_dir, false | filename()}
88 | {reader, {Module::atom(), Function::atom}}
89 | {record_info, [{Name::atom(), [Field::atom()]}]}
90 | {scanner_module, Module::atom()}
91 | {vars, [{atom(), iodata()}]}.
92
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
93
94 %% --------------------------------------------------------------------
95 %% Compile file
96 %% --------------------------------------------------------------------
97
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
98 -spec compile_file(filename(), atom()) -> {ok, Module::atom()} | error.
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
99 compile_file(File, Module) ->
100 erlydtl_compiler:compile_file(File, Module, erlydtl_compiler:default_options()).
c5c019e @rsaccon refactoring (part 1 - not complete, code broken)
rsaccon authored
101
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
102 -spec compile_file(filename(), atom(), compile_options()) -> ok_ret() | err_ret().
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
103 compile_file(File, Module, Options) ->
104 erlydtl_compiler:compile_file(File, Module, Options).
105
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
106
107 %% --------------------------------------------------------------------
108 %% Compile template
109 %% --------------------------------------------------------------------
110
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
111 -spec compile_template(iodata(), atom()) -> {ok, Module::atom()} | error.
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
112 compile_template(Template, Module) ->
113 erlydtl_compiler:compile_template(Template, Module, erlydtl_compiler:default_options()).
114
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
115 -spec compile_template(iodata(), atom(), compile_options()) -> ok_ret() | err_ret().
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
116 compile_template(Template, Module, Options) ->
117 erlydtl_compiler:compile_template(Template, Module, Options).
6b746f2 @evanmiller Add compile_dir functions to erlydtl module
evanmiller authored
118
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
119
120 %% --------------------------------------------------------------------
121 %% Compile directory
122 %% --------------------------------------------------------------------
123
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
124 -spec compile_dir(filename(), atom()) -> {ok, Module::atom()} | error.
6b746f2 @evanmiller Add compile_dir functions to erlydtl module
evanmiller authored
125 compile_dir(DirectoryPath, Module) ->
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
126 erlydtl_compiler:compile_dir(DirectoryPath, Module, erlydtl_compiler:default_options()).
6b746f2 @evanmiller Add compile_dir functions to erlydtl module
evanmiller authored
127
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
128 -spec compile_dir(filename(), atom(), compile_options()) -> ok_ret() | err_ret().
6b746f2 @evanmiller Add compile_dir functions to erlydtl module
evanmiller authored
129 compile_dir(DirectoryPath, Module, Options) ->
130 erlydtl_compiler:compile_dir(DirectoryPath, Module, Options).
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
131
132
26b6a79 @kaos Restructure compiler code (close #136)
kaos authored
133 %% --------------------------------------------------------------------
134 %% Legacy API
135 %% --------------------------------------------------------------------
136
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
137 %% keep for backwards compatibility, with a tuple-twist to ease migration / offer alternative path..
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
138 -spec compile(FileOrBinary, atom()) -> {ok, Module::atom()} | error
139 when FileOrBinary :: string() | binary()
140 | {file, filename()}
141 | {template, iodata()}.
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
142 compile({file, File}, Module) ->
143 compile_file(File, Module);
144 compile({template, Template}, Module) ->
145 compile_template(Template, Module);
146 compile(FileOrBinary, Module) when is_binary(FileOrBinary) ->
147 compile_template(FileOrBinary, Module);
148 compile(FileOrBinary, Module) ->
149 compile_file(FileOrBinary, Module).
150
3e8ee1b @kaos Add spec's for compile options (fixes #133)
kaos authored
151 -spec compile(FileOrBinary, atom(), compile_options() ) -> ok_ret() | err_ret()
152 when FileOrBinary :: string() | binary()
153 | {file, filename()}
154 | {template, iodata()}.
aa23751 @kaos Update api to be explicit about what to compile (fixes #125)
kaos authored
155 compile({file, File}, Module, Options) ->
156 compile_file(File, Module, Options);
157 compile({template, Template}, Module, Options) ->
158 compile_template(Template, Module, Options);
159 compile(FileOrBinary, Module, Options) when is_binary(FileOrBinary) ->
160 compile_template(FileOrBinary, Module, Options);
161 compile(FileOrBinary, Module, Options) ->
162 compile_file(FileOrBinary, Module, Options).
Something went wrong with that request. Please try again.