GithubHelp home page GithubHelp logo

caramel's Introduction

Caramel

Caramel is a MVC framework built for Jaggery. The intent of the framework is to bootstrap application development and enforce a standard for developing web applications using Jaggery. By no means Caramel trying to lock down developer creativity or freedom but simply trying enforce discipline to large development teams working on Jaggery projects.

A web application written according to Caramel, takes a certain structure, this is to separate the models, controllers and the views

Lets learn by an example;

Caramel application config (app.js)

caramel.configs({
context: '/blog',
negotiation: true,
themer: function () {
    return 'classic';
}
});

The app config informs caramel to use the specified theme to render the provided data, it also specifies the application context and if content negotiation is enabled or not, which we will get back later.

The meaning of defining a theme is that, by a configuration change, a new theme can be plugged to the application, and the concept is native to Caramel

A simple “Hello World” with Caramel

First let's write a simple Hello World Jaggery App.

Application name : hello, Theme: default

Lets call the homepage of the app “index.jag”. In Caramel, the page that servers the request act as one of the controllers of the app. it defines what data needs to be presented in that particular page. Content of the page can be as follows

Hello World home page

Lets call it index.jag

<%
var caramel;
var body = "Hello World";
caramel = require('caramel').caramel;
caramel.render({
    'title': {text :'Hello Title'}, // set html title for index page
    'body': {text:body} //set html body for index page
});
%>

This jag file will provide the title as Hello Title and the body as Hello World to caramel render.

Now lets move to the theme,

First we need to set handlebars as the caramel theming engine. Under the themes/classic directory lets create theme.js

var engine = caramel.engine('handlebars', (function () {
}()));

lets write some HTML with handlebars which is going to define the view for our theme classic.

Create simple.hbs inside themes/classic/pages

<html>
<head>
    <title>{{include title}}</title>
</head>
<body>
    <div>{{include body}}</div>
</body>
</html>

This will let our theme to include the title and the body partials, which we are going to create in the next step. Partials come to play when you have a single template that you need to use in different contexts.For example you can use above template in different contexts by setting different titles and body contents.

Now lets create above inside themes/classic/partials directory,

title.hbs

{{{title}}}

body.hbs

{{{body}}}

Lets move to the renderer, Create index.js inside themes/classic/renderes

var render = function (theme, data, meta, require) {
theme('simple', {
    title: [
        { partial:'title', context: data.title}
    ],
    body: [
        { partial:'body', context: data.body}
    ]
    });
};

Now you can browse the homepage and it will display rendered web page with Hello Title as the title and Hello World as the body.

caramel's People

Contributors

chamathb avatar madhuka avatar maheshika avatar manuranga avatar praveenaj avatar ruchiraw avatar splinter avatar tanyam avatar udarakr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caramel's Issues

Automating the minification of JS and CSS files

The Caramel framework will need to be augmented with the ability to support automatic minification of JS and CSS files. In addition, it should also support;

  1. Collation of all JS scripts into a single file
  2. Compression of JS and CSS resources

New caramel does not support sub themes

Previous version of caramel supported sub theme concept with minimum duplication of resources. The new version does not support this. Please provide a fix for this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.