Copyright © Yariv Sadan 2006-2007
Authors: Yariv Sadan (yarivsblog@gmail.com) [web site: http://yarivsblog.com].
ErlyWeb: The Erlang Twist on Web Framworks.
This module contains a few functions for creating and using ErlyWeb applications and components. It is also the module set as the YAWS appmod for ErlyWeb applications.| compile/1 | Compile all the files for an application. |
| compile/2 | Compile all the files for an application using the compilation options as described in the 'compile' module in the Erlang documentation (http://erlang.org). |
| create_app/2 | Create a new ErlyWeb application in the directory AppDir. |
| create_component/2 | Equivalent to create_component(Component, AppDir, [{magic, on}, {model, on}, {erltl, off}]). |
| create_component/3 | Create all files (model, view, and controller) for a component that implements basic CRUD features for a database table. |
| get_app_name/1 | Get the name for the application as specified in the opaque 'appname' field in the YAWS configuration. |
| get_app_root/1 | Get the relative URL for the application's root path. |
| get_ewc/1 | |
| get_initial_ewc/1 | Get the expanded 'ewc' tuple for the request. |
| out/1 | This is the out/1 function that Yaws calls when passing HTTP requests to the ErlyWeb appmod. |
| out/2 | This function is useful for embedding the result of a 'phased' ErlyWeb rendering in an ErlyWeb component from the same application, but using a different app controller. |
compile(AppDir::string()) -> ok | {error, Err}
Compile all the files for an application. Files with the '.et' extension are compiled with ErlTL.
This function returns{ok, Now}, where Now is
the result of calendar:local_time().
You can pass the second value in the options for the next call to
compile/2 to telling ErlyWeb to avoid recompiling files that haven't
changed (ErlyWeb does this automatically when the auto-compilation
is turned on).
compile(AppDir::string(), Options::[option()]) -> {ok, Now::datetime()} | {error, Err}
Compile all the files for an application using the compilation options as described in the 'compile' module in the Erlang documentation (http://erlang.org). ErlyWeb also lets you define the following options:
- {last_compile_time, LocalTime}: Tells ErlyWeb to not compile files
that haven't changed since LocalTime.
Since ErlyWeb 0.7, you can use 'auto' for LocalTime. This
instructs ErlyWeb to compile only the files that have changed since
the last compilation. This is the recommended option.
- {erlydb_driver, Name}: Tells ErlyWeb which ErlyDB driver to use
when calling erlydb:code_gen on models that are placed in src/components.
If you aren't using ErlyDB, i.e., you don't have any model files in
src/components, you can omit this option.
- {auto_compile, Val}, where Val is 'true', or 'false'.
This option tells ErlyWeb whether it should turn on auto-compilation.
Auto-compilation is helpful during development because it spares you
from having to call erlyweb:compile every time you make a code change
to your app. Just remember to turn this option off when you are in
production mode because it will slow your app down (to turn auto_compile
off, just call erlyweb:compile without the auto_compile option).
- {auto_compile_exclude, Val}, where Val is a folder in docroot (or a
URL path) which gets excluded from auto-compiling. This is useful when
erlyweb is mapped to '/' and there are a lots of static files in that
excluded folder. Example: {auto_compile_exclude, "/static"}
- suppress_warnings and suppress_errors tell ErlyWeb to not pass the
report_warnings and report_errors to compile:file/2.
create_app(AppName::string(), AppDir::string()) -> ok | {error, Err}
Create a new ErlyWeb application in the directory AppDir. This function creates the standard ErlyWeb directory structure as well as a few basic files for a rudimantary application.
Equivalent to create_component(Component, AppDir, [{magic, on}, {model, on}, {erltl, off}]).
create_component(Component::atom(), AppDir::string(), Options::[option()]) -> ok | {error, Err}
Create all files (model, view, and controller) for a component that implements basic CRUD features for a database table. 'Component' is the name of the component and 'AppDir' is the application's root directory.
This function also lets you define the following options:
- {magic, Val::on | off | atom() | string()}
If Val is 'on', the view and controller source files this function
creates will have the line "-erlyweb_magic(on)". This tells Erlyweb that
the module in which the line appears should extend the erlyweb_view
or erlyweb_controller modules, which provide basic CRUD
capabilities. You can override the default base module by replacing
'on' with the name of the module you want to extend. You can also
disable the built-in CRUD features by having 'Val' be 'off'.
- {model, Val::on | off}
This tells Erlyweb whether to create a model file or not.
{erltl, Val::on | off}
This tells Erlyweb whether the view file should be an ErlTL file, or
an Erlang source file.
get_app_name(A::arg()) -> AppName::string() | exit(Err)
Get the name for the application as specified in the opaque 'appname' field in the YAWS configuration.
get_app_root(A::arg()) -> string()
Get the relative URL for the application's root path.
get_initial_ewc(Ewc::{ewc, A::arg()}) -> {page, Path::string()} | {ewc, Controller::atom(), View::atom(), Function::atom(), Params::[string()]} | exit({no_such_function, Err}) | exit({illegal_request, Controller})
Get the expanded 'ewc' tuple for the request.
This function can be useful in the app controller in case the application requires special logic for handling client requests for different components.
If the request is for a component whose controller implements the function
private() -> true., this function calls
exit({illegal_request, Controller}).
If the request matches an existing component but no function in the
component's controller, and the controller exports catch_all/3,
this function returns
{ewc, Controller, View, catch_all, [A, Function, Params]}.
Otherwise, if the request matches a component but no function in the
component's controller, this function calls
exit({no_such_function, Err}).
If the request doesn't match any components, this function returns
{page, Path}, where Path is the arg's appmoddata field.
{ewc, A}, this function returns
the parameter unchanged without any extra processing.
See also: handle_request/1.
out(A::yaws_arg()) -> ret_val()
This is the out/1 function that Yaws calls when passing HTTP requests to the ErlyWeb appmod.
out(A::arg(), AppController::atom()) -> term()
This function is useful for embedding the result of a 'phased' ErlyWeb rendering in an ErlyWeb component from the same application, but using a different app controller.
This function was originally designed to simplify Facebook app development with ErlyWeb using Erlang2Facebook (http://code.google.com/p/erlang2facebook). In erlang2facebook, the fb_canvas component intercepts requests from Facebook and authenticates them. After authentication, it may be useful to start a new ErlyWeb "flow" using an alternative app controller and display the result in of this flow the output of fb_canvas.