Skip to content
Permalink
Browse files

* Initial commit.

  • Loading branch information
ghaberek committed Sep 23, 2018
0 parents commit f1161ea94d8acfe63ac5640e0306933bc11a462f
Showing with 866 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +100 −0 README.md
  3. +107 −0 docs/TEMPLATE.md
  4. +2 −0 eu.cfg
  5. +2 −0 examples/eu.cfg
  6. +21 −0 examples/example1.ex
  7. +607 −0 include/mvc/template.e
  8. +15 −0 templates/example1.html
  9. +11 −0 templates/layout.html
@@ -0,0 +1 @@
ex.err
100 README.md
@@ -0,0 +1,100 @@
# Euphoria MVC

**Euphoria MVC** is a model-view-controller framework for [Euphoria](https://githubc.com/OpenEuphoria/Euphoria). Currently only the template parser is completed.

## Features

### Database

Execute queries on any (well, most) database systems from one codebase.

### Models

Easily store and fetch Euphoria data via object-relation mapping (ORM).

### Templates

Build you views in simple HTML and then easily render your models to the page.

### Routing

Automatically route paths to functions.

## Getting Started

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

### Download Euphoria

wget "http://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 -s {} \;

### Get Euphoria MVC

Check out euphoria-mvc into your project directory

git clone https://github.com/openeuphoria/euphoria-mvc

Or if you're already using git, check out as a submodule.

git add submodule https://github.com/openeuphoria/euphoria-mvc

### Configure Euphoria

Update your `eu.cfg` to use euphoria-mvc/include.

[all]
-i euphoria-mvc/include

### Update .htaccess

Tell Apache you want it to execute Euphoria scripts and use index.esp as the index.

AddHandler cgi-script .esp
Options +ExecCGI
DirectoryIndex index.esp

### Write your template.

Save this as `templates/index.html`.

<!DOCTYPE html>
<html>
<head>
<title>{{title}</title>
</head>
<body>
<h1>{{title}}</h1>
</body>
</html>

### Write your application.

Save this as `index.esp`.

#!/usr/local/bin/eui

include mvc/app.e
include mvc/template.e
include std/map.e

function index( object request )

map response = map:new()
map:put( response, "title", "Hello, world!" )

return render_template( "index.html", response )
end function
app:route( "/index" )

app:run()

### Run your application

Open your web browser to your application URL.

@@ -0,0 +1,107 @@
# Templates

## Example

<!DOCTYPE html>
<html>
<head>
<title>{{title}</title>
</head>
<body>
<h1>{{title}}</h1>
</body>
</html>

## Template routines

### render_template

`include mvc/template.e`
`public function render_template( sequence template, object response )`

- **`template`** - your template file name
- **`response`** - your map or sequence of template values

## Comment block

A comment is any text enclosed in `{# .. #}` tags.

## Expression block

An expression block is any value enclosed in `{{ .. }}` tags.

Expressions can be a variable name, a function call, or a literal value.

## Statement blocks

Statement blocks are enclosed in `{% .. %}` tags.

### if statement

{% if expression %}
<p>content if true</p>
{% elsif expression %}
<p>another possibly true expression</p>
{% else %}
<p>content if false</p>
{% end if %}

### for statement

A couting loop

<ul>
{% for i = 1 to 10 %}
<li>Item {{i}}</li>
{% end for %}
</ul>

A couting loop with steps

<ul>
{% for i = 1 to 10 by 2 %}
<li>Item {{i}}</li>
{% end for %}
</ul>

An item list loop

<table>
<tr>
<th>Name</th>
<th>Size</th>
<th>Type</th>
<th>Last modified</th>
</tr>
{# we assume list is a sequence of maps #}
{% for item in list %}
<tr>
<td>{{item.name}}</td>
<td>{{item.size}}</td>
<td>{{item.type}}</td>
<td>{{item.last_modified}}</td>
</tr>
{% end for %}
</table>

### extends statement

The extends statement allows for parent/child relationships between templates. You can define a single parent "layout" template, and then *extend* that template in all your other templates.

### block statement

Blocks are named sections used between templates. Blocks in your layout template shoudld be empty, as they will be replaced by matching blocks from the original template.

**Layout template**

<section name="content">
{% block content %}{% end block %}
</section>

**Orignal template**

{% extends layout.html %}
{% block content %}
<p>This is where my content goes!</p>
{% end block %}

2 eu.cfg
@@ -0,0 +1,2 @@
[all]
-i include
@@ -0,0 +1,2 @@
[all]
-i ../include
@@ -0,0 +1,21 @@
include mvc/template.e

set_template_path( "../templates" )

procedure main()

sequence response = {
{ "title", "Example 1" },
{ "list", {"one","two","three","four","five"} },
{ "start", 1 },
{ "stop", 10 },
{ "step", 2 }
}

sequence data = render_template( "example1.html", response )

puts( 1, data )

end procedure

main()

0 comments on commit f1161ea

Please sign in to comment.
You can’t perform that action at this time.