Browse Source

* Change: No .beam file will be generated unless out_dir is specified.
* Document out_dir in README
* If there is a compilation error, print name of offending file.

Thanks to Liu Yubao for the patches.



git-svn-id: http://erlydtl.googlecode.com/svn/trunk@149 a5195066-8e3e-0410-a82a-05b01b1b9875

emmiller 16 years ago
parent
commit
bd26c620c0
2 changed files with 19 additions and 7 deletions
  1. 3 0
      README
  2. 16 7
      src/erlydtl/erlydtl_compiler.erl

+ 3 - 0
README

@@ -27,6 +27,9 @@ Four ways:
 
 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.
 

+ 16 - 7
src/erlydtl/erlydtl_compiler.erl

@@ -93,13 +93,17 @@ compile(File, Module, Options) ->
         {ok, DjangoParseTree, CheckSum} ->
             case compile_to_binary(File, DjangoParseTree, Context, CheckSum) of
                 {ok, Module1, Bin} ->
-                    OutDir = proplists:get_value(out_dir, Options, "ebin"),       
-                    BeamFile = filename:join([OutDir, atom_to_list(Module1) ++ ".beam"]),
-                    case file:write_file(BeamFile, Bin) of
-                        ok ->
+                    case proplists:get_value(out_dir, Options) of
+                        undefined ->
                             ok;
-                        {error, Reason} ->
-                            {error, lists:concat(["beam generation failed (", Reason, "): ", BeamFile])}
+                        OutDir ->
+                            BeamFile = filename:join([OutDir, atom_to_list(Module1) ++ ".beam"]),
+                            case file:write_file(BeamFile, Bin) of
+                                ok ->
+                                    ok;
+                                {error, Reason} ->
+                                    {error, lists:concat(["beam generation failed (", Reason, "): ", BeamFile])}
+                            end
                     end;
                 Err ->
                     Err
@@ -188,7 +192,12 @@ parse(File, Context) ->
     case catch M:F(File) of
         {ok, Data} ->
             CheckSum = binary_to_list(crypto:sha(Data)),
-            parse(CheckSum, Data, Context);
+            case parse(CheckSum, Data, Context) of
+                {error, Msg} when is_list(Msg) ->
+                    {error, File ++ ": " ++ Msg};
+                Result ->
+                    Result
+            end;
         _ ->
             {error, "reading " ++ File ++ " failed "}
     end.