Thursday, November 02, 2006

ErlyWeb 0.2

I made some improvements to the first release of ErlyWeb, some based on user feedback, and some based on my own whims :) This is what I did:

- Chaged the LastCompileTime parameter in erlyweb:compile into an option value in the form of {last_compile_time, Time}.

- Added the following options to erlyweb:compile/2:

{auto_compile, true} : this option, useful during development, tells ErlyWeb to compile all files that have changed since the last request when a new request arrives. This frees you from having to call erlyweb:compile every time you make a code change in your app. Just don't forget to turn auto-compilation off by calling erlyweb:compile without the {auto_compile, true} option when you are switching from development to production mode, because auto-compilation slows things down.

Update (12/6/06): The pre_compile_hook and post_compile_hook have changed in ErlyWeb v0.3. Read this announcement for more details.

{pre_compile_hook, {Module, FuncName}} and {post_compile_hook, {Module, FuncName}}: these option tell ErlyWeb to call the predefined functions before/after (auto)compilation. This allows you to extend the compilation process in an arbitrary way, e.g. by compiling additional files that are outside of the application's src directory. Both functions take a single parameter which is the time of the last compilation (or 'undefined' if the time is not available). For example, let's say you have the following file called 'compile_hooks.erl' in the 'src' directory:


-module(compile_hooks).
-compile(export_all).

pre_compile(LastCompileTime) ->
io:format("pre-compile (last: ~p) ~n", [LastCompileTime]).

post_compile(LastCompileTime) ->
io:format("post-compile (last: ~p) ~n", [LastCompileTime]).


You could use the new compilation options as follows:


erlyweb:compile("/path/to/app",
[{erlydb_driver, mysql},
{auto_compile, true},
{pre_compile_hook, {compile_hooks, pre_compile}},
{post_compile_hook, {compile_hooks, post_compile}}]).


From now on, every time ErlyWeb does an auto-compilation, it will call those hooks, passing into them the time of the last compilation (or 'undefined' on the first compilation).

- Changed the include directive in yaws_arg.erl from '-include("yaws/include/yaws_api.hrl").' to '-include("yaws_api.hrl").' (this removes assumptions about your Yaws path structure).

- Changed the docroot directive in yaws from pointing at the application's base directory to [base]/www. E.g., if your previous docroot line was

docroot = /apps/music

it should now be

docroot = /apps/music/www

(there's no change in behavior -- it just makes the configuration more explicit).

That's it :)

Note: a few people have asked me whether ErlyWeb requires a MySQL database. The answer is 'no.' You can use ErlyWeb without any database backend. Just don't keep the source files for any models in src/components, and then you'll never even have to call erlydb:start().

In a minute, I'll put the new zip file on erlyweb.org so you can download it all in one shot.

4 comments:

Yariv said...

It's already here! :) And I'll look at the Yaws 1.64 issue tomorrow.

Amr said...

This is over my head a little bit, but I'll try the new version and see if it fixes the error 1.64 yaws was giving me. I'm amazed by your productivity, I guess a google group is not far behind at this rate (because many people will start using it I think)

-A

Yariv said...

Amr, check out my latest posting. It should help you with Yaws 1.64.

Tiago Bastos said...

ErlyWeb support sessions and postgres? Nice project!