-
Notifications
You must be signed in to change notification settings - Fork 1
Framework Internals
- Request is catched by webserver. It handles static resources.
- If not processed, request is passed to web server interface (currently there is only
s_platform_inets
for inets server. This interface extracts GET and POST parameters and executess_dispatcher:dispatch()
-
s_dispatcher
routes request (usings_route.parse_request
)- If requested controller doesn’t exists, 404 page rendered
- Requested controller is executed
- If controller fails, error page rendered
- View requested by controller is rendered
- 404 page is rendered if view not found
- Error page is rendered if rendering fails
- Response is converted to web server specific form and is rendered.
Routing file is a set of records, that describes routes. Following routes are supported:
{Path, [Params]} % Page route {Method, Path, [Params]} % RESTful page route
- Difference between {Path, [Params]}
is the same as {any, Path, [Params]}
.
- Path can be atom ‘root
’. In this case it matches root route.
- Path in routes may have wildcard components:For example route
“test/:id
” will match to “test/123
” path (and request will be routed
with parameter id
equal to “123
”)
app \controllers \views bin config lib logs public tmp
- app/controllers directory contains controllers. Currently controllers have no namespaces
- app/views directory contains views. Template engine is identified by view extension.
- app/ebin used internally for compiled controllers/views
- bin directory contains useful scripts (currently only for start up server)
-
config directory contains:
- application.conf is main configuration file.
- routes.conf is file with routing configuration.
- lib directory with Erlang OTP applications (such steroids framework, erlydtl templating engine, etc)
- logs directory contains application logs
- public directory contains static files (images, stylesheets, etc)
- tmp directory contains temporary stuff like uploaded files
This subsystem is used to reload different kind of files:
- Controllers
- Views
It automatically tracks if file was changed and executes compile
function when reload required. It utilizes callback module with following interface:
compile_and_load(RealPath, TargetModule) get_real_path(Path) get_module_name(Path)
-
get_module_name
returns module name, for specific (virtual) path. F.e. it generates module name for path to template. -
get_real_path
returns file system path to specified virtual path. F.e. real file path for template. -
compile_and_load
compiles file on specified real path toModule
.
You can easily integrate your template engine:
You should create adapter with following interface:
compile(Path, Module)
-
compile
function compiles template with absolute pathPath
toModule
Also you should add your template to config file:
config/application.conf {template_engines, [ {s_erlydtl_adapter, ["dtl"]} ]}.
It’s list of pairs: template engine module name with list of extensions for this template engine.