Просмотр исходного кода

Add binary option.

This concludes the fixes for compiler options.
Close #116.
Andreas Stenius 11 лет назад
Родитель
Сommit
601a6953ef
2 измененных файлов с 15 добавлено и 3 удалено
  1. 11 2
      README.markdown
  2. 4 1
      src/erlydtl_compiler.erl

+ 11 - 2
README.markdown

@@ -123,6 +123,12 @@ Options is a proplist possibly containing:
 
 * `no_load` - Do not load the compiled template.
 
+* `binary` - Include the compiled template binary code in the result
+  tuple (between the module name and any warning/error lists). Note,
+  this option is named the same as the for the Erlang compiler, with
+  similar use, except that this option does NOT affect whether or not
+  a .beam file is saved.
+
 *Erlang Compiler options*
 
 Options that gets passed to `compile:forms/2`:
@@ -140,8 +146,11 @@ Any other options to the compiler can be specified using the `compiler_options`
 
 _Notice_ that the return value from `erlydtl:compile` is affected by
 the options passed to the compiler. See
-[Erlang compiler documentation](http://www.erlang.org/doc/man/compile.html#forms-2) for
-details.
+[Erlang compiler documentation](http://www.erlang.org/doc/man/compile.html#forms-2)
+for details. _Exception_ to the rule is that we have reverted the
+`forms` statement that `binary` is treated as implicitly set. That is,
+you need to pass the `binary` option to erlydtl in order to get the
+code in the result tuple.
 
 Default compiler options are `[verbose, report_errors]`, which gives
 either a `{ok, Module}` or `error` as return value.

+ 4 - 1
src/erlydtl_compiler.erl

@@ -246,7 +246,10 @@ compile_forms(Forms, Context) ->
               [fun maybe_write_binary/3,
                fun maybe_load/3,
                fun (_, _, _) ->
-                       list_to_tuple([ok, Module|Info])
+                       case proplists:get_bool(binary, Context#dtl_context.all_options) of
+                           true -> Compiled;
+                           false -> list_to_tuple([ok, Module|Info])
+                       end
                end
               ]);
         Err when Err =:= error; element(1, Err) =:= error ->