Permalink
Browse files

Add 'deps/erlydtl/' from commit 'b076a6e245ccff6e72f97ca81aef1f931633…

…520a'

git-subtree-dir: deps/erlydtl
git-subtree-mainline: 613a668
git-subtree-split: b076a6e
  • Loading branch information...
2 parents 613a668 + b076a6e commit 7d74b00271e1057a2cfa1bf8ea56ae4f276630dc Yurii Rashkovskii committed Apr 24, 2012
Showing with 7,292 additions and 0 deletions.
  1. +5 −0 deps/erlydtl/.gitignore
  2. +1 −0 deps/erlydtl/Emakefile
  3. +26 −0 deps/erlydtl/Makefile
  4. +188 −0 deps/erlydtl/README.markdown
  5. +47 −0 deps/erlydtl/README_I18N
  6. +25 −0 deps/erlydtl/bin/erlydtl_compile
  7. +21 −0 deps/erlydtl/priv/custom_tags/flashvideo
  8. BIN deps/erlydtl/rebar
  9. +1 −0 deps/erlydtl/rebar.config
  10. +9 −0 deps/erlydtl/src/erlydtl.app.src
  11. +47 −0 deps/erlydtl/src/erlydtl.erl
  12. +1,245 −0 deps/erlydtl/src/erlydtl_compiler.erl
  13. +60 −0 deps/erlydtl/src/erlydtl_deps.erl
  14. +1,209 −0 deps/erlydtl/src/erlydtl_filters.erl
  15. +17 −0 deps/erlydtl/src/erlydtl_i18n.erl
  16. +385 −0 deps/erlydtl/src/erlydtl_parser.yrl
  17. +262 −0 deps/erlydtl/src/erlydtl_runtime.erl
  18. +307 −0 deps/erlydtl/src/erlydtl_scanner.erl
  19. +195 −0 deps/erlydtl/src/erlydtl_unparser.erl
  20. +372 −0 deps/erlydtl/src/filter_lib/erlydtl_dateformat.erl
  21. +209 −0 deps/erlydtl/src/filter_lib/erlydtl_slice.erl
  22. +4 −0 deps/erlydtl/src/i18n/Makefile
  23. +48 −0 deps/erlydtl/src/i18n/blocktrans_extractor.erl
  24. +13 −0 deps/erlydtl/src/i18n/blocktrans_parser.erl
  25. +146 −0 deps/erlydtl/src/i18n/blocktrans_scanner.erl
  26. +128 −0 deps/erlydtl/src/i18n/i18n_manager.erl
  27. +57 −0 deps/erlydtl/src/i18n/po_generator.erl
  28. +91 −0 deps/erlydtl/src/i18n/po_scanner.erl
  29. +67 −0 deps/erlydtl/src/i18n/sources_parser.erl
  30. +8 −0 deps/erlydtl/tests/input/autoescape
  31. +11 −0 deps/erlydtl/tests/input/base
  32. +17 −0 deps/erlydtl/tests/input/comment
  33. +7 −0 deps/erlydtl/tests/input/custom_call
  34. +12 −0 deps/erlydtl/tests/input/custom_tag
  35. +9 −0 deps/erlydtl/tests/input/cycle
  36. +3 −0 deps/erlydtl/tests/input/extends
  37. +3 −0 deps/erlydtl/tests/input/extends_path
  38. +6 −0 deps/erlydtl/tests/input/extends_path2
  39. +45 −0 deps/erlydtl/tests/input/filters
  40. +9 −0 deps/erlydtl/tests/input/for
  41. +3 −0 deps/erlydtl/tests/input/for_list
  42. +3 −0 deps/erlydtl/tests/input/for_list_preset
  43. +9 −0 deps/erlydtl/tests/input/for_preset
  44. +9 −0 deps/erlydtl/tests/input/for_records
  45. +15 −0 deps/erlydtl/tests/input/for_records_preset
  46. +3 −0 deps/erlydtl/tests/input/for_tuple
  47. +4 −0 deps/erlydtl/tests/input/if
  48. +4 −0 deps/erlydtl/tests/input/if_preset
  49. +43 −0 deps/erlydtl/tests/input/ifequal
  50. +43 −0 deps/erlydtl/tests/input/ifequal_preset
  51. +43 −0 deps/erlydtl/tests/input/ifnotequal
  52. +43 −0 deps/erlydtl/tests/input/ifnotequal_preset
  53. +1 −0 deps/erlydtl/tests/input/include
  54. +1 −0 deps/erlydtl/tests/input/include.html
  55. +5 −0 deps/erlydtl/tests/input/include_path
  56. +3 −0 deps/erlydtl/tests/input/include_template
  57. +11 −0 deps/erlydtl/tests/input/now
  58. +6 −0 deps/erlydtl/tests/input/path1/base1
  59. +5 −0 deps/erlydtl/tests/input/path1/base2
  60. +1 −0 deps/erlydtl/tests/input/path1/include1
  61. +5 −0 deps/erlydtl/tests/input/path1/template1
  62. +14 −0 deps/erlydtl/tests/input/path2/base2
  63. +2 −0 deps/erlydtl/tests/input/path2/template2
  64. +1 −0 deps/erlydtl/tests/input/ssi
  65. +1 −0 deps/erlydtl/tests/input/ssi_include.html
  66. +1 −0 deps/erlydtl/tests/input/trans
  67. +5 −0 deps/erlydtl/tests/input/var
  68. +9 −0 deps/erlydtl/tests/input/var_preset
  69. +49 −0 deps/erlydtl/tests/py/erlydtl_python_test.py
  70. BIN deps/erlydtl/tests/py/erlydtl_python_test.pyc
  71. +29 −0 deps/erlydtl/tests/py/python_dtl_setup.txt
  72. +15 −0 deps/erlydtl/tests/py/run_erl_node.sh
  73. +187 −0 deps/erlydtl/tests/src/erlydtl_dateformat_tests.erl
  74. +5 −0 deps/erlydtl/tests/src/erlydtl_example_variable_storage.erl
  75. +280 −0 deps/erlydtl/tests/src/erlydtl_functional_tests.erl
  76. +1,069 −0 deps/erlydtl/tests/src/erlydtl_unittests.erl
  77. +10 −0 deps/erlydtl/tests/src/gettext.erl
  78. +40 −0 deps/erlydtl/tests/src/sources_parser_unittests.erl
View
@@ -0,0 +1,5 @@
+ebin
+*.swp
+erl_crash.dump
+examples/rendered_output
+src/erlydtl_parser.erl
View
@@ -0,0 +1 @@
+{"tests/src/*", [debug_info, {outdir, "ebintest"}]}.
View
@@ -0,0 +1,26 @@
+ERL=erl
+REBAR=./rebar
+
+
+all: compile
+
+compile:
+ @$(REBAR) compile
+
+compile_test:
+ -mkdir -p ebintest
+ $(ERL) -make
+
+test: compile compile_test
+ $(ERL) -noshell -pa ebin -pa ebintest \
+ -s erlydtl_functional_tests run_tests \
+ -s erlydtl_dateformat_tests run_tests \
+ -s erlydtl_unittests run_tests \
+ -s sources_parser_unittests run_tests \
+ -s init stop
+
+clean:
+ @$(REBAR) clean
+ rm -fv ebintest/*
+ rm -fv erl_crash.dump
+ rm -fv tests/output/*
@@ -0,0 +1,188 @@
+ErlyDTL
+=======
+
+ErlyDTL compiles Django Template Language to Erlang bytecode.
+
+*Supported tags*: autoescape, block, blocktrans, comment, cycle, extends, filter, firstof, for, if, ifchanged, ifequal, ifnotequal, include, now, regroup, spaceless, ssi, templatetag, trans, widthratio, with
+
+_Unsupported tags_: csrf_token, url
+
+*Supported filters*: add, addslashes, capfirst, center, cut, date, default, default_if_none, dictsort, dictsortreversed, divisibleby, escape, escapejs, filesizeformat, first, fix_ampersands, floatformat, force_escape, format_integer, format_number, get_digit, iriencode, join, last, length, length_is, linebreaks, linebreaksbr, linenumbers, ljust, lower, make_list, phonenumeric, pluralize, pprint, random, random_num, random_range, removetags, rjust, safe, safeseq, slice, slugify, stringformat, striptags, time, timesince, timeuntil, title, truncatechars, truncatewords, truncatewords_html, unordered_list, upper, urlencode, urlize, urlizetrunc, wordcount, wordwrap, yesno
+
+_Unsupported filters_: _none_
+
+Project homepage: <http://code.google.com/p/erlydtl/>
+
+Language reference: <http://docs.djangoproject.com/en/dev/ref/templates/builtins/>
+
+
+Compilation
+-----------
+
+To compile ErlyDTL, run
+
+ make
+
+in this directory.
+
+
+Template compilation
+--------------------
+
+Four ways:
+
+ erlydtl:compile("/path/to/template.dtl", my_module_name)
+
+ erlydtl:compile("/path/to/template.dtl", my_module_name, Options)
+
+ erlydtl:compile(<<"<html>{{ foo }}</html>">>, my_module_name)
+
+ erlydtl:compile(<<"<html>{{ foo }}</html>">>, my_module_name, Options)
+
+Options is a proplist possibly containing:
+
+* `out_dir` - Directory to store generated .beam files. If not specified, no
+.beam files will be created.
+
+* `doc_root` - Included template paths will be relative to this directory;
+defaults to the compiled template's directory.
+
+* `custom_tags_dir` - Directory of DTL files (no extension) includable as tags.
+E.g. if $custom_tags_dir/foo contains `<b>{{ bar }}</b>`, then `{% foo bar=100 %}`
+will evaluate to `<b>100</b>`. Get it?
+
+* `custom_tags_modules` - A list of modules to be used for handling custom
+tags. The modules will be searched in order and take precedence over
+`custom_tags_dir`. Each custom tag should correspond to an exported function,
+e.g.:
+
+ some_tag(Variables, Context) -> iolist()
+
+The `Context` is specified at render-time with the `custom_tags_context` option.
+
+* `custom_filters_modules` - A list of modules to be used for handling custom
+filters. The modules will be searched in order and take precedence over the
+built-in filters. Each custom filter should correspond to an exported filter,
+e.g.
+
+ some_filter(Value) -> iolist()
+
+If the filter takes an argument (e.g. "foo:2"), the argument will be also be
+passed in:
+
+ some_filter(Value, Arg) -> iolist()
+
+* `vars` - Variables (and their values) to evaluate at compile-time rather than
+render-time.
+
+* `reader` - {module, function} tuple that takes a path to a template and returns
+a binary with the file contents. Defaults to `{file, read_file}`. Useful
+for reading templates from a network resource.
+
+* `compiler_options` - Proplist passed directly to `compiler:forms/2`
+
+* `force_recompile` - Recompile the module even if the source's checksum has not
+changed. Useful for debugging.
+
+* `locale` - The locale used for template compile. Requires erlang_gettext. It
+will ask gettext_server for the string value on the provided locale.
+For example, adding {locale, "en_US"} will call {key2str, Key, "en_US"}
+for all string marked as trans (`{% trans "StringValue" %}` on templates).
+See README_I18N.
+
+* `blocktrans_fun` - A two-argument fun to use for translating `blocktrans`
+blocks. This will be called once for each pair of `blocktrans` block and locale
+specified in `blocktrans_locales`. The fun should take the form:
+
+ Fun(Block::string(), Locale::string()) -> <<"ErlyDTL code">> | default
+
+* `blocktrans_locales` - A list of locales to be passed to `blocktrans_fun`.
+Defaults to [].
+
+* `binary_strings` - Whether to compile strings as binary terms (rather than
+lists). Defaults to `true`.
+
+
+Helper compilation
+------------------
+
+Helpers provide additional templating functionality and can be used in
+conjunction with the `custom_tags_module` option above. They can be created
+from a directory of templates thusly:
+
+ erlydtl:compile_dir("/path/to/dir", my_helper_module_name)
+
+ erlydtl:compile_dir("/path/to/dir", my_helper_module_name, Options)
+
+The resulting module will export a function for each template appearing
+in the specified directory. Options is the same as for compile/3.
+
+Compiling a helper module can be more efficient than using `custom_tags_dir`
+because the helper functions will be compiled only once (rather than once
+per template).
+
+
+Usage (of a compiled template)
+------------------------------
+
+ my_compiled_template:render(Variables) -> {ok, IOList} | {error, Err}
+
+Variables is a proplist, dict, gb_tree, or a parameterized module
+(whose method names correspond to variable names). The variable
+values can be atoms, strings, binaries, or (nested) variables.
+
+IOList is the rendered template.
+
+ my_compiled_template:render(Variables, Options) ->
+ {ok, IOList} | {error, Err}
+
+Same as `render/1`, but with the following options:
+
+* `translation_fun` - A fun/1 that will be used to translate strings appearing
+inside `{% trans %}` tags. The simplest TranslationFun would be `fun(Val) ->
+Val end`
+
+* `locale` - A string specifying the current locale, for use with the
+`blocktrans_fun` compile-time option.
+
+* `custom_tags_context` - A value that will be passed to custom tags.
+
+ my_compiled_template:translatable_strings() -> [String]
+
+List of strings appearing in `{% trans %}` tags that can be overridden with
+a dictionary passed to `render/2`.
+
+ my_compiled_template:translated_blocks() -> [String]
+
+List of strings appearing in `{% blocktrans %}...{% endblocktrans %}` blocks;
+the translations (which can contain ErlyDTL code) are hard-coded into the
+module and appear at render-time. To get a list of translatable blocks before
+compile-time, use the provided `blocktrans_extractor` module.
+
+ my_compiled_template:source() -> {FileName, CheckSum}
+
+Name and checksum of the original template file.
+
+ my_compiled_template:dependencies() -> [{FileName, CheckSum}]
+
+List of names/checksums of templates included by the original template
+file. Useful for frameworks that recompile a template only when the
+template's dependencies change.
+
+
+Differences from standard Django Template Language
+--------------------------------------------------
+
+The "regroup" tag must have an ending "endregroup" tag.
+
+The "ifchanged" tag cannot take arguments.
+
+
+Tests
+-----
+
+From a Unix shell, run:
+
+ make test
+
+Note that the tests will create some output in tests/output.
View
@@ -0,0 +1,47 @@
+Generate gettext infrastructure
+-------------------------------
+
+Erlydtl allows templates to use i18n features based on gettext. Standard po
+files can be used to generate i18ized templates. A template parser/po generator
+is also provided.
+
+ 1. In order to enable i18n you first, you'll need gettext library to be
+ available on your lib_path.
+
+ Library can be downloaded from http://github.com/noss/erlang-gettext
+
+ 2. Then you'll need to add a parse target on your makefile (or the script
+ used to trigger template reparsing) trans:
+
+ erl -pa ./ebin ./deps/*/ebin -noshell -s reloader -run i18n_manager \
+ generate_pos "en,es" "./views/*/*.html,./views/*.html"
+ rm -rf $(GETTEXT_DIR)/lang/default-old
+ mv $(GETTEXT_DIR)/lang/default $(GETTEXT_DIR)/lang/default-old
+ cp -rf $(GETTEXT_DIR)/lang/$(GETTEXT_TMP_NAME) $(GETTEXT_DIR)/lang/default
+ rm -rf $(GETTEXT_DIR)/lang/$(GETTEXT_TMP_NAME)/*
+
+ Mind that GETTEXT_DIR and GETTEXT_TMP_NAME must be bound to existing
+ directories. Args passed to i18n_manager:generate_pos are locales that
+ will be supported (generating dir structure and po files) and
+ directories where generator will search for template files including
+ trans tags.
+
+ 3. Before template parsing gettext server must be running and it must be
+ populated with the content of the po files. Consider adding this
+ snipplet to the code before template parsing
+
+ gettext_server:start(),
+ LoadPo =
+ fun(Lang)->
+ {_, Bin} = file:read_file("./lang/default/"++ Lang ++"/gettext.po"),
+ gettext:store_pofile(Lang, Bin)
+ end,
+ lists:map(LoadPo, ["es","en"]).
+
+ Here locales are the codes are provided to gettext. Those codes must be
+ a subset of the locales provided to po generation process.
+
+ 4. Update strings. Edit po files on $(GETTEXT_DIR)/lang/default/$(LOCALE)/gettext.po
+ translating msgstr to the translated version of their corresponding msgstr.
+
+ 5. Generate localized templates providing locale compile option.
@@ -0,0 +1,25 @@
+#!/usr/bin/env escript
+%% -*- mode: erlang -*-
+-export([main/1]).
+
+%% External API
+
+main([Prefix, File]) ->
+ ensure(),
+ Basename = filename:basename(File, ".dtl"),
+ ModuleName = list_to_atom(string:to_lower(lists:flatten([Prefix, "_", Basename]))),
+ erlydtl_compiler:compile(File, ModuleName, [{out_dir, filename:dirname(File)}]);
+main(_) ->
+ usage().
+
+ensure() ->
+ code:add_patha("ebin"),
+ code:add_patha("lib/erlydtl/ebin"),
+ [D1,D2|_] = code:get_path(),
+ io:format("Code Path: ~p~n", [[D1,D2]]).
+
+
+usage() ->
+ io:format("usage: ~s name [destdir]~n",
+ [filename:basename(escript:script_name())]),
+ halt(1).
@@ -0,0 +1,21 @@
+<object id="{{ dom_id }}" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{{ width }}" height="{{ height }}">
+ <param name="movie" value="{{ static }}/mediaplayer.swf">
+ <param name="allowfullscreen" value="true">
+ <param name="menu" value="false">
+ <param name="flashvars" value="file={{ path_to_video }}&image={{ path_to_preview_image }}">
+ <!--[if !IE]>-->
+ <object type="application/x-shockwave-flash" data="{{ static }}/mediaplayer.swf" width="800" height="620">
+ <param name="allowfullscreen" value="true">
+ <param name="menu" value="false">
+ <param name="flashvars" value="file={{ path_to_video }}&image={{ path_to_preview_image }}">
+ <!--<![endif]-->
+ <h2>To view the Video:</h2>
+ <p>
+ <a href="http://www.adobe.com/go/getflashplayer">
+ <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="{{ alt }}">
+ </a>
+ </p>
+ <!--[if !IE]>-->
+ </object>
+ <!--<![endif]-->
+</object>
View
Binary file not shown.
@@ -0,0 +1 @@
+{erl_opts, [debug_info]}.
@@ -0,0 +1,9 @@
+%% -*- mode: erlang -*-
+{application, erlydtl,
+ [{description, "ErlyDTL compiles the Django Template Language to Erlang bytecode"},
+ {vsn, "0.7.0"},
+ {modules, [
+ ]},
+ {applications, [kernel, stdlib, compiler, syntax_tools]},
+ {registered, []}
+ ]}.
@@ -0,0 +1,47 @@
+%%%-------------------------------------------------------------------
+%%% File: erlydtl.erl
+%%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
+%%% @author Evan Miller <emmiller@gmail.com>
+%%% @copyright 2008 Roberto Saccon, Evan Miller
+%%% @doc
+%%% Public interface for ErlyDTL
+%%% @end
+%%%
+%%% The MIT License
+%%%
+%%% Copyright (c) 2008 Roberto Saccon, Evan Miller
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in
+%%% all copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+%%% THE SOFTWARE.
+%%%
+%%% @since 2007-11-11 by Roberto Saccon, Evan Miller
+%%%-------------------------------------------------------------------
+-module(erlydtl).
+-author('rsaccon@gmail.com').
+-author('emmiller@gmail.com').
+
+%% API
+-export([compile/2, compile/3]).
+
+%% @spec compile( FileOrBinary, Module::atom() ) -> ok | {error, Reason}
+compile(FileOrBinary, Module) ->
+ erlydtl_compiler:compile(FileOrBinary, Module).
+
+%% @spec compile( FileOrBinary, Module::atom(), Options ) -> ok | {error, Reason}
+compile(FileOrBinary, Module, Options) ->
+ erlydtl_compiler:compile(FileOrBinary, Module, Options).
Oops, something went wrong.

0 comments on commit 7d74b00

Please sign in to comment.