<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,7 @@
 %% @author Yariv Sadan &lt;yarivsblog@gmail.com&gt; [http://yarivsblog.com]
 %% @copyright Yariv Sadan 2006-2007
 %% @doc ErlyDB: The Erlang Twist on Database Abstraction.
-%%
+%%                                 
 %% == Contents ==
 %%
 %% {@section Introduction}&lt;br/&gt;
@@ -95,7 +95,8 @@
     start/2,
     code_gen/2,
     code_gen/3,
-    code_gen/4]).
+    code_gen/4,
+    code_gen/5]).
 
 -import(erlyweb_util, [log/5]).
 -define(Debug(Msg, Params), log(?MODULE, ?LINE, debug, Msg, Params)).
@@ -149,6 +150,10 @@ code_gen(Modules, Drivers) -&gt;
 code_gen(Modules, Drivers, Options) -&gt;
     code_gen(Modules, Drivers, Options, []).
 
+%% @equiv code_gen(Modules, Drivers, Options, IncludePaths, [])
+code_gen(Modules, Drivers, Options, IncludePaths) -&gt;
+    code_gen(Modules, Drivers, Options, IncludePaths, []).
+
 %% @doc Generate code for the list of modules using the provided drivers.
 %%
 %% If you're using ErlyWeb, you shouldn't need to call this function directly.
@@ -214,6 +219,11 @@ code_gen(Modules, Drivers, Options) -&gt;
 %% Additional include paths that will be used to search for header files
 %% when compiling the modules.
 %%
+%% ==== Macros ====
+%% 
+%% Macro definitions that will be used for conditional compilation.  These are
+%% represented in the same way as 'PredefMacros' in epp:parse_file/2. 
+%%
 %% === Examples ===
 %%
 %% Generate code for &quot;musician.erl&quot; using the MySQL driver. Only the default
@@ -276,17 +286,17 @@ code_gen(Modules, Drivers, Options) -&gt;
 %% a 'driver' option or only a 'pool_id' option.
 %%
 %% @spec code_gen([Module::atom() | string()], [driver()] | driver(),
-%%   Options::[term()], [IncludePath::string()]) -&gt; 
+%%   Options::[term()], [IncludePath::string()], [Macro::{atom(), term()}]) -&gt; 
 %%    ok | {error, Err}
 %% @type driver() = Driver::atom() |
 %%    {Driver::atom(),  DriverOptions::proplist()} |
 %%   {Driver::atom(), DriverOptions::proplist(), [pool()]}
 %% @type pool() = PoolId::atom() | {default, PoolId::atom()}
-code_gen(_Modules, [], _Options, _IncludePaths) -&gt;
+code_gen(_Modules, [], _Options, _IncludePaths, _Macros) -&gt;
     exit(no_drivers_specified);
-code_gen(Modules, Driver, Options, IncludePaths) when not is_list(Driver) -&gt;
-    code_gen(Modules, [Driver], Options, IncludePaths);
-code_gen(Modules, Drivers, Options, IncludePaths) -&gt;
+code_gen(Modules, Driver, Options, IncludePaths, Macros) when not is_list(Driver) -&gt;
+    code_gen(Modules, [Driver], Options, IncludePaths, Macros);
+code_gen(Modules, Drivers, Options, IncludePaths, Macros) -&gt;
 
     %% Normalize the driver tuples.
     DriverTuples =
@@ -360,12 +370,12 @@ code_gen(Modules, Drivers, Options, IncludePaths) -&gt;
       fun(Module) -&gt;
 	      DefaultDriverMod = element(1, hd(DriverTuples)),
 	      gen_module_code(Module, DefaultDriverMod, DriversData,
-				  Options, IncludePaths)
+				  Options, IncludePaths, Macros)
       end, Modules).
 
 gen_module_code(ModulePath, DefaultDriverMod,
-	       DriversData, Options, IncludePaths) -&gt;   
-    case smerl:for_module(ModulePath, IncludePaths) of
+	       DriversData, Options, IncludePaths, Macros) -&gt;   
+    case smerl:for_module(ModulePath, IncludePaths, Macros) of
 	{ok, C1} -&gt;
 	    C2 = preprocess_and_compile(C1),
 	    Module = smerl:get_module(C2),</diff>
      <filename>src/erlydb/erlydb.erl</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@
 
 %% For license information see LICENSE.txt
 -module(erlyweb_compile).
--export([compile/2, get_app_data_module/1, compile_file/5]).
+-export([compile/2, get_app_data_module/1, compile_file/5, compile_file/6]).
 
 -include_lib(&quot;kernel/include/file.hrl&quot;).
 
@@ -24,6 +24,13 @@ compile(AppDir, Options) -&gt;
 		  Other -&gt; lists:reverse([$/ | Other])
 	      end,
 
+    Macros = 
+	lists:foldl(
+	  fun({d, M}, Acc) -&gt; [{M, true} | Acc];
+	     ({d, M, V}, Acc) -&gt; [{M, V} | Acc];
+	     (_, Acc) -&gt; Acc
+	  end, [], Options),
+
     IncludePaths =
 	lists:foldl(
 	  fun({i, [$/ | _] = Path}, Acc) -&gt;
@@ -82,7 +89,7 @@ compile(AppDir, Options) -&gt;
     AppControllerFilePath = AppDir1 ++ &quot;src/&quot; ++ AppControllerFile,
     case compile_file(AppControllerFilePath,
 		      AppControllerStr, &quot;.erl&quot;, undefined,
-		      LastCompileTimeInSeconds, Options3, IncludePaths) of
+		      LastCompileTimeInSeconds, Options3, IncludePaths, Macros) of
 	{ok, _} -&gt; ok;
 	{ok, _, _, _} -&gt; ok;
 	ok -&gt; ok;
@@ -101,7 +108,7 @@ compile(AppDir, Options) -&gt;
 		  if FileName =/= AppControllerFilePath -&gt;
 			  compile_component_file(
 			    ComponentsDir, http_util:to_lower(FileName),
-			    LastCompileTimeInSeconds, Options3, IncludePaths,
+			    LastCompileTimeInSeconds, Options3, IncludePaths, Macros,
 			    Acc);
 		     true -&gt;
 			  Acc
@@ -119,7 +126,7 @@ compile(AppDir, Options) -&gt;
 		     {value, {erlydb_driver, Drivers}} -&gt;
 			 erlydb:code_gen(lists:reverse(Models),
 					 Drivers,
-					 Options3, IncludePaths);
+					 Options3, IncludePaths, Macros);
 		     false -&gt; {error, missing_erlydb_driver_option}
 		 end
 	end,
@@ -315,7 +322,7 @@ addFinalClauses(Clauses, ComponentStr, Exports) -&gt;
 
 
 compile_component_file(ComponentsDir, FileName, LastCompileTimeInSeconds,
-		       Options, IncludePaths, {ComponentTree, Models} = Acc) -&gt;
+		       Options, IncludePaths, Macros, {ComponentTree, Models} = Acc) -&gt;
     BaseName = filename:rootname(filename:basename(FileName)),
     Extension = filename:extension(FileName),
     BaseNameTokens = string:tokens(BaseName, &quot;_&quot;),
@@ -332,7 +339,7 @@ compile_component_file(ComponentsDir, FileName, LastCompileTimeInSeconds,
 		   other
 	   end,
     case {compile_file(FileName, BaseName, Extension, Type,
-		       LastCompileTimeInSeconds, Options, IncludePaths),
+		       LastCompileTimeInSeconds, Options, IncludePaths, Macros),
 	  Type} of
 	{{ok, Module}, controller} -&gt;
 	    [{exports, Exports} | _] =
@@ -362,11 +369,11 @@ compile_component_file(ComponentsDir, FileName, LastCompileTimeInSeconds,
     end.
 
 compile_file(_FileName, [$. | _] = BaseName, _Extension, _Type, 
-_LastCompileTimeInSeconds, _Options, _IncludePaths) -&gt;
+_LastCompileTimeInSeconds, _Options, _IncludePaths, _Macros) -&gt;
     ?Debug(&quot;Ignoring file ~p&quot;, [BaseName]),
     {ok, ignore};
 compile_file(FileName, BaseName, Extension, Type,
-	     LastCompileTimeInSeconds, Options, IncludePaths) -&gt;
+	     LastCompileTimeInSeconds, Options, IncludePaths, Macros) -&gt;
     case should_compile(FileName,BaseName,LastCompileTimeInSeconds) of
         true -&gt;
             case Extension of
@@ -378,7 +385,7 @@ compile_file(FileName, BaseName, Extension, Type,
                 &quot;.erl&quot; -&gt;
                     ?Debug(&quot;Compiling Erlang file ~p&quot;, [BaseName]),
                     compile_file(FileName, BaseName, Type, Options,
-                                 IncludePaths)
+                                 IncludePaths, Macros)
             end;
         false -&gt;
             ok;
@@ -387,7 +394,10 @@ compile_file(FileName, BaseName, Extension, Type,
     end.
 
 compile_file(FileName, BaseName, Type, Options, IncludePaths) -&gt;
-    case smerl:for_file(FileName, IncludePaths) of
+    compile_file(FileName, BaseName, Type, Options, IncludePaths, []).
+
+compile_file(FileName, BaseName, Type, Options, IncludePaths, Macros) -&gt;
+    case smerl:for_file(FileName, IncludePaths, Macros) of
 	{ok, M1} -&gt;
 	    M2 = add_forms(Type, BaseName, M1),
 	    case smerl:compile(M2, Options) of</diff>
      <filename>src/erlyweb/erlyweb_compile.erl</filename>
    </modified>
    <modified>
      <diff>@@ -69,8 +69,10 @@
 -export([new/1,
 	 for_module/1,
 	 for_module/2,
+	 for_module/3,
 	 for_file/1,
-	 for_file/2,
+	 for_file/2, 
+	 for_file/3,
          get_module/1,
 	 set_module/2,
          get_forms/1,
@@ -136,6 +138,10 @@ new(ModuleName) when is_atom(ModuleName) -&gt;
 for_module(ModuleName) -&gt;
     for_module(ModuleName, []).
 
+%% @equiv for_module(ModuleName, IncludePaths, [])
+for_module(ModuleName, IncludePaths) -&gt;
+    for_module(ModuleName, IncludePaths, []).
+
 %% @doc Create a meta_mod tuple for an existing module. If ModuleName is a
 %% string, it is interpreted as a file name (this is the same as calling
 %% @{link smerl:for_file}). If ModuleName is an atom, Smerl attempts to
@@ -146,15 +152,16 @@ for_module(ModuleName) -&gt;
 %%
 %% The IncludePaths parameter is used when 'ModuleName' is a file name.
 %%
-%% @spec for_module(ModuleName::atom() | string(), IncludePaths::[string()]) -&gt;
+%% @spec for_module(ModuleName::atom() | string(), IncludePaths::[string()], 
+%%    Macros::[{atom(), term()}]) -&gt;
 %%   {ok, meta_mod()} | {error, Error}
-for_module(ModuleName, IncludePaths) when is_list(ModuleName) -&gt;
-    for_file(ModuleName, IncludePaths);
-for_module(ModuleName, IncludePaths) when is_atom(ModuleName) -&gt;
+for_module(ModuleName, IncludePaths, Macros) when is_list(ModuleName) -&gt;
+    for_file(ModuleName, IncludePaths, Macros);
+for_module(ModuleName, IncludePaths, Macros) when is_atom(ModuleName) -&gt;
     [_Exports, _Imports, _Attributes,
      {compile, [_Options, _Version, _Time, {source, Path}]}] =
 	ModuleName:module_info(),
-    case for_file(Path, IncludePaths) of
+    case for_file(Path, IncludePaths, Macros) of
 	{ok, _Mod} = Res-&gt;
 	    Res;
 	_Err -&gt;
@@ -175,13 +182,18 @@ for_module(ModuleName, IncludePaths) when is_atom(ModuleName) -&gt;
 for_file(SrcFilePath) -&gt;
     for_file(SrcFilePath, []).
 
+%% @equiv for_file(SrcFilePath, IncludePaths, [])
+for_file(SrcFilePath, IncludePaths) -&gt;
+    for_file(SrcFilePath, IncludePaths, []).
+
 %% @doc Create a meta_mod for a module from its source file.
 %%
-%% @spec for_file(SrcFilePath::string(), IncludePaths::[string()]) -&gt;
+%% @spec for_file(SrcFilePath::string(), IncludePaths::[string()],
+%%   Macros::[{atom(), term()}]) -&gt;
 %%  {ok, meta_mod()} | {error, invalid_module}
-for_file(SrcFilePath, IncludePaths) -&gt;
+for_file(SrcFilePath, IncludePaths, Macros) -&gt;
     case epp:parse_file(SrcFilePath, [filename:dirname(SrcFilePath) |
-				      IncludePaths], []) of
+				      IncludePaths], Macros) of
 	{ok, Forms} -&gt;
 	    mod_for_forms(Forms);
 	_err -&gt;</diff>
      <filename>src/smerl/smerl.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>093a8f5830992865be751cd06b08f2002c3b26e6</id>
    </parent>
  </parents>
  <author>
    <name>yarivvv</name>
    <email>yarivvv</email>
  </author>
  <url>http://github.com/yariv/erlyweb/commit/486879d493169f242e552c762860b5c759703b43</url>
  <id>486879d493169f242e552c762860b5c759703b43</id>
  <committed-date>2008-10-04T15:46:20-07:00</committed-date>
  <authored-date>2008-10-04T15:46:20-07:00</authored-date>
  <message>applied patches for macro defs support</message>
  <tree>7d86f1cb5a371c23af396b0bde13732be64e11b6</tree>
  <committer>
    <name>yarivvv</name>
    <email>yarivvv</email>
  </committer>
</commit>
