Euphoria MVC is a model-view-controller application framework for Euphoria.
This project is still in the very early stages of development. Things can and will break or change until we reach a stable release. Documentation is not yet complete. Please see CONTRIBUTING for details on how to submit bug reports, feature requests, or if you'd like to contribute to the project directly.
These modules are fairly mature and operational.
- mvc/app.e -- application routing
- mvc/config.e -- configuration files
- mvc/headers.e -- send HTTP headers
- mvc/logger.e -- console and file logging
- mvc/mimetype.e -- MIME type database
- mvc/server.e -- development web server
- mvc/template.e -- document templates
- mvc/utils.e -- miscellaneous utilities
These modules function as-is but still need some improvements.
- mvc/cookie.e -- manage HTTP cookies
- mvc/creole.e -- Creole markup to HTML
- mvc/database.e -- database connections
- mvc/mapdbg.e -- debugging for std/map.e
- mvc/session.e -- manage HTTP sessions
- mvc/strbuf.e -- string buffer (for CURL)
These modules are not yet stablized and are subject to change.
- mvc/hooks.e -- hooks for mvc/app.e
- mvc/html.e -- HTML parser
- mvc/json.e -- JSON parser
- mvc/model.e -- database object mapping
These modules are based on third-party libraries or services.
- curl/curl.e -- wrapper for libcurl
- db/mysql.e -- wrapper for libmysqlclient or libmariadb
- db/replit.e -- wrapper for Repl.it Database
- db/sqlite3.e -- wrapper for libsqlite3
This example will use the built-in development server to quickly start your project.
Save this as templates/layout.html
.
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
{% block content %}
{# your content will end up here #}
{% end block %}
</body>
</html>
Save this as templates/index.html
.
{% extends "layout.html" %}
{% block content %}
{# this will replace the block with
same name in the layout template #}
<h1>{{ title }}</h1>
<p>{{ message }}</p>
{# these are just comments, btw #}
{% end block %}
Save this as index.esp
.
#!/usr/local/bin/eui
include mvc/app.e
include mvc/server.e
include mvc/template.e
include std/map.e
function index( object request )
object response = map:new()
map:put( response, "title", "My First App" )
map:put( response, "message", "Hello, world!" )
return render_template( "index.html", response )
end function
app:route( "/", "index" )
-- "/" is the URL path, "index" is the name of the route
-- route() will find the matching routine automatically
server:start()
-- the server runs on http://localhost:5000/ by default
> eui index.esp
Open your web browser to your application URL at http://localhost:5000/
This example assumes you are running Apache 2.4 on Linux and that you've already got a basic working web server.
cd ~/Downloads
wget "https://sourceforge.net/projects/rapideuphoria/files/Euphoria/4.1.0-beta2/euphoria-4.1.0-Linux-x64-57179171dbed.tar.gz/download" -O euphoria-4.1.0-Linux-x64-57179171dbed.tar.gz
sudo tar xzf euphoria-4.1.0-Linux-x64-57179171dbed.tar.gz -C /usr/local/
cd /usr/local/bin/
sudo find /usr/local/euphoria-4.1.0-Linux-x64/bin/ -type f -executable -exec ln -vs {} \;
sudo git clone https://github.com/OpenEuphoria/euphoria-mvc /opt/OpenEuphoria/euphoria-mvc
sudo chown -vR www-root:www-root /opt/OpenEuphoria/euphoria-mvc
cd /var/www/html
printf "[all]\n-i /opt/OpenEuphoria/euphoria-mvc/include\n" | sudo tee eu.cfg
Move your index.esp
and other project files to this directory.
Tell Apache you want it to execute Euphoria scripts and use index.esp as the index. This would generally go into a <Directory>
directive in the site's configuration file, or directly into the local .htaccess
file.
# Add CGI handler for index.esp
AddHandler cgi-script .esp
DirectoryIndex index.esp
Options +ExecCGI
# Send all non-existant paths to index.esp
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.esp/$1 [L,NS]
You can also add a block like this to keep snoopers out of certain files:
<Files ~ ".(cfg|err|edb)$">
Deny from all
</Files>
Although the ideal solution would be to store sensitive data outside of your web root.
Change the last line of your application from server:start()
to app:run()
.
Then open your web browser to your web server's IP address or host name.