Skip to content

OpenEuphoria/euphoria-mvc

Repository files navigation

Euphoria MVC

Euphoria MVC is a model-view-controller application framework for Euphoria.

Project status

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.

Features

Stable modules

These modules are fairly mature and operational.

Work in progress

These modules function as-is but still need some improvements.

Experimental

These modules are not yet stablized and are subject to change.

Third-party

These modules are based on third-party libraries or services.

Getting Started

This example will use the built-in development server to quickly start your project.

Write your layout template

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>

Write your page template

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 %}

Write your application

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

Run your application

> eui index.esp

Open your web browser to your application URL at http://localhost:5000/

Installation

This example assumes you are running Apache 2.4 on Linux and that you've already got a basic working web server.

Download Euphoria

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/

Install Euphoria

cd /usr/local/bin/
sudo find /usr/local/euphoria-4.1.0-Linux-x64/bin/ -type f -executable -exec ln -vs {} \;

Install Euphoria MVC

sudo git clone https://github.com/OpenEuphoria/euphoria-mvc /opt/OpenEuphoria/euphoria-mvc
sudo chown -vR www-root:www-root /opt/OpenEuphoria/euphoria-mvc

Update your web root

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.

Add CGI handler

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.

Run your application

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.