Browse Source

removed the gen_server and supervisor stuff

Roberto Saccon 17 years ago
parent
commit
941d1e9b85

+ 21 - 5
src/demo/erlydtl_demo.erl

@@ -1,14 +1,15 @@
 %%%-------------------------------------------------------------------
 %%%-------------------------------------------------------------------
 %%% File:      erlydtl_demo.erl
 %%% File:      erlydtl_demo.erl
 %%% @author    Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
 %%% @author    Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
-%%% @copyright 2007 Roberto Saccon
+%%% @author    Evan Miller <emmiller@gmail.com>
+%%% @copyright 2008 Roberto Saccon, Evan Miller
 %%% @doc  
 %%% @doc  
-%%%
+%%% Demo application and tests
 %%% @end  
 %%% @end  
 %%%
 %%%
 %%% The MIT License
 %%% The MIT License
 %%%
 %%%
-%%% Copyright (c) 2007 Roberto Saccon
+%%% Copyright (c) 2007 Roberto Saccon, Evan Miller
 %%%
 %%%
 %%% Permission is hereby granted, free of charge, to any person obtaining a copy
 %%% Permission is hereby granted, free of charge, to any person obtaining a copy
 %%% of this software and associated documentation files (the "Software"), to deal
 %%% of this software and associated documentation files (the "Software"), to deal
@@ -28,18 +29,33 @@
 %%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 %%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 %%% THE SOFTWARE.
 %%% THE SOFTWARE.
 %%%
 %%%
-%%% @since 2007-11-17 by Roberto Saccon
+%%% @since 2007-11-17 by Roberto Saccon, Evan Miller
 %%%-------------------------------------------------------------------
 %%%-------------------------------------------------------------------
 -module(erlydtl_demo).
 -module(erlydtl_demo).
 -author('rsaccon@gmail.com').
 -author('rsaccon@gmail.com').
+-author('emmiller@gmail.com').
 
 
 %% API
 %% API
--export([compile_all/0, compile/1, compile/3, render_all/0, render/1, render/2]).
+-export([create_parser/0, compile_all/0, compile/1, compile/3, render_all/0, render/1, render/2]).
 
 
 %%====================================================================
 %%====================================================================
 %% API
 %% API
 %%====================================================================
 %%====================================================================
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
+%% @spec () -> ok | {error, Reason::string()}
+%% @doc creates the parser source code and compiles it 
+%% @end 
+%%--------------------------------------------------------------------
+create_parser() ->
+    case erlydtl:create_parser() of
+        ok ->
+            io:format("parser creation success ~n");
+        {error, Reason} ->
+            io:format("parser creation failure: ~p~n",[Reason])
+    end.
+            
+    
+%%--------------------------------------------------------------------
 %% @spec () -> any()
 %% @spec () -> any()
 %% @doc  compiles the templates to beam files
 %% @doc  compiles the templates to beam files
 %% @end 
 %% @end 

+ 15 - 48
src/erlydtl/erlydtl.erl

@@ -37,7 +37,7 @@
 -author('emmiller@gmail.com').
 -author('emmiller@gmail.com').
 
 
 %% API
 %% API
--export([start/0, stop/0, create_parser/0, reload/2, write_beam/3]).
+-export([create_parser/0]).
 
 
 %% --------------------------------------------------------------------
 %% --------------------------------------------------------------------
 %% Definitions
 %% Definitions
@@ -48,52 +48,16 @@
 -define(PRINT_ERR_WARNS, []). 
 -define(PRINT_ERR_WARNS, []). 
 -endif.
 -endif.
 
 
-
-%% @spec start() -> ok
-%% @doc Start the erlydtl server.
-start() ->
-    application:start(erlydtl).
-
-
-%% @spec stop() -> ok
-%% @doc Stop the erlydtl server.
-stop() ->
-    application:stop(erlydtl).
-    
     
     
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
-%% @spec 
-%% @doc
+%% @spec () -> any()
+%% @doc creates the yecc-based ErlyDTL parser
 %% @end 
 %% @end 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 create_parser() ->
 create_parser() ->
     create_parser("src/erlydtl/erlydtl_parser", "ebin").
     create_parser("src/erlydtl/erlydtl_parser", "ebin").
 
 
 
 
-%%--------------------------------------------------------------------
-%% @spec (ModuleName::string(), Bin,::binary()) -> Ok::atom() | Error::atom()
-%% @doc reloads byte code
-%% @end 
-%%--------------------------------------------------------------------
-reload(Module, Bin) ->
-    code:purge(Module),
-    SrcName = atom_to_list(Module) ++ ".erl",
-    case code:load_binary(Module, SrcName, Bin) of
-        {module, _} -> ok;
-        _ -> error
-    end.
-
-
-%%--------------------------------------------------------------------
-%% @spec (ModuleName::string(), Bin,::binary(), Dir::string()) -> any()
-%% @doc writes  byte code to beam file
-%% @end 
-%%--------------------------------------------------------------------    
-write_beam(ModuleName, Bin, Dir) ->
-    File = filename:join([Dir, atom_to_list(ModuleName) ++ ".beam"]),
-    file:write_file(File, Bin).
-
-
 %%====================================================================
 %%====================================================================
 %% Internal functions
 %% Internal functions
 %%====================================================================
 %%====================================================================
@@ -101,19 +65,22 @@ write_beam(ModuleName, Bin, Dir) ->
 create_parser(Path, Outdir) ->
 create_parser(Path, Outdir) ->
     case yecc:file(Path) of
     case yecc:file(Path) of
         {ok, _} ->
         {ok, _} ->
-            compile_reload_parser(Path, Outdir);
-        Err ->
-            io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, Path ++ ": yecc failed"]),
-            Err
+            compile_parser(Path, Outdir);
+        _ ->
+            {error, "yecc parser generation failed"}
     end.
     end.
 
 
 
 
-compile_reload_parser(Path, Outdir) ->
+compile_parser(Path, Outdir) ->
     case compile:file(Path, ?PRINT_ERR_WARNS ++ [{outdir, Outdir}]) of
     case compile:file(Path, ?PRINT_ERR_WARNS ++ [{outdir, Outdir}]) of
         {ok, Bin} ->
         {ok, Bin} ->
             code:purge(Bin),
             code:purge(Bin),
-            code:load_file(Bin);
-        Err ->
-            io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, Path ++ ": compilation failed"]),
-            Err
+            case code:load_file(Bin) of
+                {module, _} ->
+                    ok;
+                _ ->
+                    {error, "yecc parser reload failed"}
+            end;
+        _ ->
+            {error, "yecc parser compilation failed"}
     end.
     end.

+ 0 - 76
src/erlydtl/erlydtl_app.erl

@@ -1,76 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File:      erlydtl_app.erl
-%%% @author    Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
-%%% @author    Evan Miller <emmiller@gmail.com>
-%%% @copyright 2008 Roberto Saccon, Evan Miller
-%%% @doc  
-%%%
-%%% @end  
-%%%
-%%% The MIT License
-%%%
-%%% Copyright (c) 2007 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-12-15 by Roberto Saccon, Evan Miller
-%%%-------------------------------------------------------------------
--module(erlydtl_app).
--author('rsaccon@gmail.com').
--author('emmiller@gmail.com').
-
--behaviour(application).
-
-%% Application callbacks
--export([start/2, stop/1]).
-
-%%====================================================================
-%% Application callbacks
-%%====================================================================
-%%--------------------------------------------------------------------
-%% @spec start(Type, StartArgs) -> {ok, Pid} |
-%%                                 {ok, Pid, State} |
-%%                                 {error, Reason}
-%% @doc This function is called whenever an application 
-%% is started using application:start/1,2, and should start the processes
-%% of the application. If the application is structured according to the
-%% OTP design principles as a supervision tree, this means starting the
-%% top supervisor of the tree.
-%% @end 
-%%--------------------------------------------------------------------
-start(_Type, []) ->
-    erlydtl_sup:start_link();  
-start(_Type, StartArgs) ->
-    erlydtl_sup:start_link(StartArgs).
-        
-
-%%--------------------------------------------------------------------
-%% @spec stop(State) -> void()
-%% @doc This function is called whenever an application
-%% has stopped. It is intended to be the opposite of Module:start/2 and
-%% should do any necessary cleaning up. The return value is ignored. 
-%% @end 
-%%--------------------------------------------------------------------
-stop(_State) ->
-    ok.
-
-%%====================================================================
-%% Internal functions
-%%====================================================================
-

+ 0 - 185
src/erlydtl/erlydtl_server.erl

@@ -1,185 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File:      erlydtl_server.erl
-%%% @author    Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
-%%% @author    Evan Miller <emmiller@gmail.com>
-%%% @copyright 2008 Roberto Saccon, Evan Miller
-%%% @doc  
-%%% Server for compiling ErlyDTL templeates
-%%% @end  
-%%%
-%%% The MIT License
-%%%
-%%% Copyright (c) 2007 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-17 by Roberto Saccon, Evan Miller
-%%%-------------------------------------------------------------------
--module(erlydtl_server).
--author('rsaccon@gmail.com').
--author('emmiller@gmail.com').
-
--behaviour(gen_server).
-	
-%% API
--export([start_link/0, compile/1, compile/3, compile/4, compile/5]).
-
-%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
-         terminate/2, code_change/3]).
-
--record(state, {
-    reload = true}).
-
-
-%%====================================================================
-%% API
-%%====================================================================
-%%--------------------------------------------------------------------
-%% @spec start_link() -> {ok,Pid} | ignore | {error,Error}
-%% @doc Starts the server
-%% @end 
-%%--------------------------------------------------------------------
-start_link() ->
-    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-        
-        
-%%--------------------------------------------------------------------
-%% @spec (File::string()) -> 
-%%     {Ok::atom, Ast::tuple() | {Error::atom(), Msg::string()}
-%% @doc compiles a template to a beam file
-%% @end 
-%%--------------------------------------------------------------------
-compile(File) ->
-    compile(File, todo, todo).
-        
-%%--------------------------------------------------------------------
-%% @spec (File::string(), DocRoot::string(), Mod::string()) -> 
-%%     {Ok::atom, Ast::tuple() | {Error::atom(), Msg:string()}
-%% @doc compiles a template to a beam file
-%% @end 
-%%--------------------------------------------------------------------
-compile(File, DocRoot, Mod) ->
-    compile(File, DocRoot, Mod, "render").
-    
-
-%%--------------------------------------------------------------------
-%% @spec (File::string(), DocRoot::string(), Mod::string(), VarsCallback::tuple()) -> 
-%%     {Ok::atom, Ast::tuple() | {Error::atom(), Msg:string()}
-%% @doc compiles a template to a beam file
-%% @end 
-%%--------------------------------------------------------------------
-compile(File, DocRoot, Mod, {_, _} = VarsCallback) ->
-    compile(File, DocRoot, Mod, "render", VarsCallback);
-compile(File, DocRoot, Mod, Func) ->   
-    gen_server:call(?MODULE, {compile, File, DocRoot, Mod, Func, []}).
-        
-%%--------------------------------------------------------------------
-%% @spec (File::string(), DocRoot::string(), Mod::string(), Func::atom(),
-%%         {VarsCbMod::atom(), VarsCbFunc::atom()}) -> 
-%%     {Ok::atom, Ast::tuple() | {Error::atom(), Msg:string()}
-%% @doc compiles a template to a beam file
-%% @end 
-%%--------------------------------------------------------------------            
-compile(File, DocRoot, Mod, Func, {VarsCbMod, VarsCbFunc}) ->   
-    case catch VarsCbMod:VarsCbFunc(list_to_atom(Mod)) of
-        Vars when is_list(Vars) ->
-            gen_server:call(?MODULE, {compile, File, DocRoot, Mod, Func, Vars});
-        _ -> 
-            gen_server:call(?MODULE, {compile, File, DocRoot, Mod, Func, []})
-    end.
-    
-        
-%%====================================================================
-%% gen_server callbacks
-%%====================================================================
-
-%%--------------------------------------------------------------------
-%% @spec init(Args) -> {ok, State} |
-%%                         {ok, State, Timeout} |
-%%                         ignore               |
-%%                         {stop, Reason}
-%% @doc Initiates the server
-%% @end 
-%%--------------------------------------------------------------------
-init([]) ->
-    {ok, #state{}}.
-
-%%--------------------------------------------------------------------
-%% @spec 
-%% handle_call(Request, From, State) -> {reply, Reply, State} |
-%%                                      {reply, Reply, State, Timeout} |
-%%                                      {noreply, State} |
-%%                                      {noreply, State, Timeout} |
-%%                                      {stop, Reason, Reply, State} |
-%%                                      {stop, Reason, State}
-%% @doc Handling call messages
-%% @end 
-%%--------------------------------------------------------------------
-handle_call({compile, _File, _DocRoot, _Mod, _Func, _Vars}, _From, State) ->
-    Reply = not_implemented,
-    {reply, Reply, State};       
-
-handle_call(_Request, _From, State) ->
-    Reply = ok,
-    {reply, Reply, State}.
-
-%%--------------------------------------------------------------------
-%% @spec handle_cast(Msg, State) -> {noreply, State} |
-%%                                      {noreply, State, Timeout} |
-%%                                      {stop, Reason, State}
-%% @doc Handling cast messages
-%% @end 
-%%--------------------------------------------------------------------
-handle_cast(_Msg, State) ->
-    {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% @spec handle_info(Info, State) -> {noreply, State} |
-%%                                       {noreply, State, Timeout} |
-%%                                       {stop, Reason, State}
-%% @doc Handling all non call/cast messages
-%% @end 
-%%--------------------------------------------------------------------
-handle_info(_Info, State) ->
-    {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% @spec terminate(Reason, State) -> void()
-%% @doc This function is called by a gen_server when it is about to
-%% terminate. It should be the opposite of Module:init/1 and do any necessary
-%% cleaning up. When it returns, the gen_server terminates with Reason.
-%% The return value is ignored.
-%% @end 
-%%--------------------------------------------------------------------
-terminate(_Reason, _State) ->
-    ok.
-
-%%--------------------------------------------------------------------
-%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}
-%% @doc Convert process state when code is changed
-%% @end 
-%%--------------------------------------------------------------------
-code_change(_OldVsn, State, _Extra) ->
-    {ok, State}.	
-
-
-%%====================================================================
-%% Internal functions
-%%====================================================================

+ 0 - 121
src/erlydtl/erlydtl_sup.erl

@@ -1,121 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File:      erlydtl_sup.erl
-%%% @author    Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
-%%% @author    Evan Miller <emmiller@gmail.com>
-%%% @copyright 2008 Roberto Saccon, Evan Miller
-%%% @doc  
-%%% ErlyDtl supervisor
-%%% @end  
-%%%
-%%% The MIT License
-%%%
-%%% Copyright (c) 2007 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-12-15 by Roberto Saccon, Evan Miller
-%%%-------------------------------------------------------------------
--module(erlydtl_sup).
--author('rsaccon@gmail.com').
--author('emmiller@gmail.com').
-
--behaviour(supervisor).
-
-%% API
--export([start_link/0, start_link/1, upgrade/0]).
-
-%% Supervisor callbacks
--export([init/1]).
-
-
-%%====================================================================
-%% API functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% @spec start_link() -> {ok,Pid} | ignore | {error,Error}
-%% @doc Starts the supervisor
-%% @end 
-%%--------------------------------------------------------------------
-start_link() ->
-    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-%%--------------------------------------------------------------------
-%% @spec start_link(Args::list()) -> {ok,Pid} | ignore | {error,Error}
-%% @doc Starts the supervisor
-%% @end 
-%%--------------------------------------------------------------------    
-start_link(Args) ->
-    supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
-
-    
-%%--------------------------------------------------------------------
-%% @spec upgrade() -> ok
-%% @doc 
-%% Add processes if necessary.
-%% @end
-%%--------------------------------------------------------------------
-upgrade() ->
-    {ok, {_, Specs}} = init([]),
-
-    Old = sets:from_list(
-	    [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
-    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
-    Kill = sets:subtract(Old, New),
-
-    sets:fold(fun (Id, ok) ->
-		      supervisor:terminate_child(?MODULE, Id),
-		      supervisor:delete_child(?MODULE, Id),
-		      ok
-	      end, ok, Kill),
-
-    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
-    ok.
-
-
-%%====================================================================
-%% Supervisor callbacks
-%%====================================================================
-%%--------------------------------------------------------------------
-%% @spec init(Args) -> {ok,  {SupFlags,  [ChildSpec]}} |
-%%                     ignore                          |
-%%                     {error, Reason}
-%% @doc Whenever a supervisor is started using 
-%% supervisor:start_link/[2,3], this function is called by the new process 
-%% to find out about restart strategy, maximum restart frequency and child 
-%% specifications.
-%% @end 
-%%--------------------------------------------------------------------
-init([]) ->
-    RestartStrategy = one_for_one,
-    MaxRestarts = 10,
-    MaxTimeBetweenRestarts = 10,
-    SupFlags  = {RestartStrategy, MaxRestarts, MaxTimeBetweenRestarts},
-    ErlyDTL = {erlydtl_server, 
-	    {erlydtl_server, start_link, []},
-        permanent,
-        1000,
-        worker,
-        [erlydtl_server]},
-    Processes = [ErlyDTL],
-    {ok,{SupFlags, Processes}}.
-        
-    
-%%====================================================================
-%% Internal functions
-%%====================================================================