1. Euphoria MVC framework - template parser online

I've been alluding to this for a while, and the template parser is now pretty much complete, so I decided to get it posted to GitHub to track my continued progress.

Currently only the template parser is included, but I've added an example to the README to show how an application would look. Please try out the template parser, which can be used for any type of text files.

As always, if anyone would like to contribute, I have a lot of things that need to be done. The framework is being built in layers and I'm designing it to be as modular as possible to aid in collaboration.

This is the framework on which I will eventually build a new website for OpenEuphoria.org and hopefully many more websites after that.

https://github.com/OpenEuphoria/euphoria-mvc

-Greg
Forked into: Euphoria MVC framework - application routing working now

new topic     » topic index » view message » categorize

2. Re: Euphoria MVC framework - template parser online

Woo hoo! Awesome!

I'll be having a look this week when I get back to the office.

When will the blog module and forms module be ready? grin

new topic     » goto parent     » topic index » view message » categorize

3. Re: Euphoria MVC framework - template parser online

I added another example for the template engine.

The use of functions makes the code look a little busy right now, but I'll be adding "map properties" to the parser, where you retrieve nested values, e.g. item.propery_name, etc.

Heck, as it is right now, you could just use this template parser right now to separate your logic and presentation layers for a basic website.

https://github.com/OpenEuphoria/euphoria-mvc/blob/master/examples/example2.ex

-- 
-- This is a more advanced example showing how to use functions from within templates. 
-- 
 
include std/map.e 
include mvc/template.e 
 
sequence data = { 
    { 
        {"id", 1}, 
        {"first_name", "Mommy"}, 
        {"last_name", "Mewburn"}, 
        {"email_address", "mmewburn0@oakley.com"}, 
        {"job_title", "Business Systems Development Analyst"}, 
        {"ip_address", "245.131.117.235"} 
    }, 
    { 
        {"id", 2}, 
        {"first_name", "Malinda"}, 
        {"last_name", "Yemm"}, 
        {"email_address", "myemm1@goodreads.com"}, 
        {"job_title", "Social Worker"}, 
        {"ip_address", "110.26.43.251"} 
    }, 
    -- SNIP -- 
} 
 
function get_id( object m ) 
    return map:get( m, "id", 0 ) 
end function 
add_function( "id", {"m"}, routine_id("get_id") ) 
 
function first_name( object m ) 
    return map:get( m, "first_name", "" ) 
end function 
add_function( "first_name", {"m"} ) 
 
function last_name( object m ) 
    return map:get( m, "last_name", "" ) 
end function 
add_function( "last_name", {"m"} ) 
 
function email_address( object m ) 
    return map:get( m, "email_address", "" ) 
end function 
add_function( "email_address", {"m"} ) 
 
function job_title( object m ) 
    return map:get( m, "job_title", "" ) 
end function 
add_function( "job_title", {"m"} ) 
 
function ip_address( object m ) 
    return map:get( m, "ip_address", "" ) 
end function 
add_function( "ip_address", {"m"} ) 
 
procedure main() 
 
    sequence user_list = {} 
 
    for i = 1 to length( data ) do 
        user_list &= { map:new_from_kvpairs(data[i]) } 
    end for 
 
    object response = map:new() 
    map:put( response, "title", "Example 2" ) 
    map:put( response, "user_list", user_list ) 
 
    sequence content = render_template( "example2.html", response ) 
    puts( 1, content ) 
 
end procedure 
 
main() 

{% extends layout.html %} 
{% block content %} 
 
<table> 
 
    <tr> 
        <th>ID</th> 
        <th>First Name</th> 
        <th>Last Name</th> 
        <th>Email Address</th> 
        <th>Job Title</th> 
        <th>IP Address (v4)</th> 
    </tr> 
    {% for user in user_list %} 
    <tr> 
        <td>{{ id(user) }}</td> 
        <td>{{ first_name(user) }}</td> 
        <td>{{ last_name(user) }}</td> 
        <td>{{ email_address(user) }}</td> 
        <td>{{ job_title(user) }}</td> 
        <td>{{ ip_address(user) }}</td> 
    </tr> 
    {% end for %} 
</table> 
 
{% end block %} 

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: Euphoria MVC framework - template parser online

I've only recently (last few years) been using a MVC paradigm for development of web apps. It seems you are putting Controller functionality into View space. Or is it reasonable/appropriate here?

i.e., this

    {% for user in user_list %} 
    <tr> 
        <td>{{ id(user) }}</td> 
        <td>{{ first_name(user) }}</td> 
        <td>{{ last_name(user) }}</td> 
        <td>{{ email_address(user) }}</td> 
        <td>{{ job_title(user) }}</td> 
        <td>{{ ip_address(user) }}</td> 
    </tr> 
    {% end for %} 

should be this

    {% for user in user_list %} 
    <tr> 
        <td>{{ user.id }}</td> 
        <td>{{ user.first_name }}</td> 
        <td>{{ user.last_name }}</td> 
        <td>{{ user.email_address }}</td> 
        <td>{{ user.job_title }}</td> 
        <td>{{ user.ip_address }}</td> 
    </tr> 
    {% end for %} 

Help me out!

new topic     » goto parent     » topic index » view message » categorize

5. Re: Euphoria MVC framework - template parser online

euphoric said...

I've only recently (last few years) been using a MVC paradigm for development of web apps. It seems you are putting Controller functionality into View space. Or is it reasonable/appropriate here?

You're not wrong that it's unusual and inappropriate to put controller logic into the view. But that's not what I'm doing and that's not the intent for template functions.

The immediate goal was to provide a simple way to fetch model properties in a "Euphorian" way. Euphoria doesn't natively have dot notation, but it does have functions.

I will add dot notation soon. I do believe that will be a cleaner and simpler way to display models (which are just maps) in the views.

The overall intent for template functions is to provide a way for the view to alter the display of the model without altering the model itself.

Here's an example of adding some basic formatting to the view via functions:

function mailto_link( object text ) 
    return sprintf( "<a href='mailto:%s'>%s</a>", {text} ) 
end function 
add_function( "mailto_link", {"text"} ) 
 
function title_case( object text ) 
    return text:proper( text ) 
end function 
add_function( "title_case", {"text"} ) 

    {% for user in user_list %} 
    <tr> 
        {# all of this whitespace will be ignored... #} 
        <td>{{              user.id              }}</td> 
        <td>{{  title_case( user.first_name )    }}</td> 
        <td>{{  title_case( user.last_name )     }}</td> 
        <td>{{ mailto_link( user.email_address ) }}</td> 
        <td>{{  title_case( user.job_title )     }}</td> 
        <td>{{              user.ip_address      }}</td> 
    </tr> 
    {% end for %} 

-Greg

new topic     » goto parent     » topic index » view message » categorize

6. Re: Euphoria MVC framework - template parser online

Well this was actually a lot simpler than I thought, so I've gone ahead and pushed the changes to include dot notation.

https://github.com/OpenEuphoria/euphoria-mvc/commit/498f6a41db170cf950d850acdd6cbbc2899170bb

-Greg

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu