Erlydtl compiler #44

Merged
merged 2 commits into from Oct 26, 2012

Conversation

Projects
None yet
2 participants
Contributor

saleyn commented Oct 19, 2012

Three bug fixes described in individual commits

Contributor

saleyn commented Oct 25, 2012

Also I removed the commit that exported render_tag/3.

@saleyn @saleyn saleyn Property handle compiler return code
* Bug fix: When compiler_option includes 'return', properly handle Error
and Warnings returned by the Erlang compiler, so that the user still gets
'ok' instead of {ok, Module, Bin, {Errors, Warnings}}, which rebar doesn't
property handle.

* Add `verbose` compiler option.
f74b94f
Contributor

saleyn commented Oct 26, 2012

Please see the changes in both commits that address your concerns. Promoted verbose to be 1st class ErlyDTL option, fixed the compiler to save custom tags argument key as atom as opposed to be a string.

Contributor

evanmiller commented Oct 26, 2012

Hmm. Don't you just want

erl_syntax:string(atom_to_list(Key)) ?

So the semantics of the BEAM are unchanged.

Contributor

saleyn commented Oct 26, 2012

I was unsure as to what you had in mind when you wrote in the implementation erl_syntax:string(Atom). Was it that you wanted the result to be represented as an atom or a string? With that the beam compiled fine, and I am unsure what the impact of that implementation would be at run-time. But an attempt to decompile the beam into the source code failed miserably, so I wanted to fix that. Just let me know if you want the named arguments to be stored as atoms or strings, and I'll patch it accordingly. For my own purpose it doesn't make a difference, so the decision is yours.

Contributor

evanmiller commented Oct 26, 2012

Please store them as strings as they are stored now.

@saleyn @saleyn saleyn Bug fix in saving template containing custom_tags_modules feature
* Bug fix: when compiling templates with custom tags with a given
custom_tags_modules option, the arguments are saved as atoms in the
AST as opposed to strings. This causes a failure when decompiling
the beam and printing its source by erl_prettypr.

In order to illustrate the issue compile the template test.dtl containing:

    {% tr xxx="ABC" %}

with options:

    [
        , {doc_root, "src"}
        , {out_dir,   "ebin"}
        , {compiler_options, [verbose, debug_info, report, return]}
        , {custom_tags_modules, [custom_tags]}
        , {force_recompile, true}
    ].

where custom_tags module is:

    -module(custom_tags).

    -export([tr/2]).

    tr(Vars, Context) ->
        io:format("Vars: ~p\n  Context: ~p\n", [Vars, Context]),
        [].

Observe the return code of erlydtl_compiler:compile/3, and also try to
decompile the emitted beam with:
[http://erlang.org/pipermail/erlang-questions/2006-January/018813.html]
15a46cd
Contributor

saleyn commented Oct 26, 2012

Ok, this last commit does it the way you recommended.

Contributor

evanmiller commented Oct 26, 2012

Thanks!

@evanmiller evanmiller added a commit that referenced this pull request Oct 26, 2012

@evanmiller evanmiller Merge pull request #44 from saleyn/erlydtl_compiler
Erlydtl compiler
2ef2f7d

@evanmiller evanmiller merged commit 2ef2f7d into erlydtl:master Oct 26, 2012

Contributor

saleyn commented Oct 26, 2012

Great! Thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment