GithubHelp home page GithubHelp logo

cake-opt's Introduction

Open Power Cake

Open Power Cake is a plugin for CakePHP web framework, that allows You to use [Open Power Template][OPT] system instead of built-in views.

Open Power Template is a web template engine that uses a dedicated XML template language for writing templates. It is not a general-purpose, but a domain-specific language. It was primarily designed to support and simplify template-specific problems with a set of declarative instructions. See [Wikipedia][OPTwiki] for details.

Requirements

  1. CakePHP (download page)
  2. Open Power Template library ([download page][OPTdownload])

Make sure to check Open Power Template requirements listed [here][OPTreqs].

Installation

Change the current working directory to vendors/ directory above Your app/ directory, and download the source of a plugin using git:

git clone git://github.com/dejw/cake-opt.git OpenPowerCake

After this operations You should have directory structure similar to this:

app/
   ...
cake/
   ...
vendors/
   js/
   css/
   shells/
   OpenPowerCake/
      libs/
      src/
      ...

Next copy whole Open Power Template libs directory into vendors/OpenPowerCake/libs/.

Configuration

To make the new View class visible in Your application paste the line below at the top of Your app_controller.php:

App::import('Vendor', "OpenPowerCake", array('file' => 'Plugin.php'));

Now You can use brand new Open Power Cake view the same as standard views in CakePHP. E.g. write:

class AppController extends Controller {
    var $view = "OpenPowerTemplate";
    // ... rest of the code
}

To enable Open Power Template in whole application. OpenPowerTemplate class behaves exactly the same as standard view classes so it can be turned on per-controller or per-action by writing:

class MyController extends AppController {
    /* OPT will render templates for MyController */
    var $view = "OpenPowerTemplate";

    /* OPT will render templates only for someAction in MyController */
    function someAction(){
        $this->view = "OpenPowerTemplate";
    }
}

Template files used by this plugin should end with .tpl extension.

config/core.php

Open Power Cake uses built-in Cake's configuration module to set-up template system. Following variables can be used in Your config/core.php file:

  • Opt.compileDir

    Points at directory, relative to APP/views, where compiled templates will be stored. It should be writeable by Your web-server in order to make Open Power Template works. Default value is /views/compiled.

Basic usage

Open Power Cake uses template inheritance to render views. See [this section][OPTinheritance] for details.

Helpers

Thanks to OPT's extensibility Open Power Cake introduces some extra instructions, which adds some flavour to Your Cake.

cake:link_to

Generates anchor from given controller and action:

<cake:link_to controller="users" action="login">Anchor</cake:link_to>

It takes optional full attribute that makes generated URLs to be absolute.

If You need to pass some unnamed parameters to generated url You can write arbitrary number of attributes started with param*. This attributes will be sorted in alphabetical order and passed to Router::url() method, thus:

<cake:link_to controller="articles" action="show" parama="1" paramA="2">Anchor</cake:link_to>

Produces:

<a href="/articles/show/2/1">Anchor</a>

since A < a when ASCII codes are taken into consideration.

This tag also takes anchor optional argument which allows You to write simple tags:

<cake:link_to anchor="Anchor" controller="users" action="login" />

cake:url

Generates URL (the same as cake:link_to tag) and adds it as an attribute to the parent tag:

<a id="my-id">
    <cake:url controller="users" action="login" />
    Anchor
</a>

might produce:

<a id="my-id" href="/users/login">
    Anchor
</a>

Url is inserted as value of href tag by default, but You can change this behaviour by specifying the attribute:

<form method="post">
    <cake:url controller="users" action="login" attribute="action" />
    <!-- rest of a form -->
</form>

Compatibility

Open Power Cake is compatible with CakePHp 1.2.2.8120 and Open Power Template 2.0.4.

Future

List below includes features that certainly will be implemented in the future:

  1. Extended set() and get() methods to handle Object Types from OPT
  2. Helpers (for html, ajax etc.)
  3. Compatibility test against older CakePHP and OPT versions.
  4. Alter not only view class, but also whole rendering system

[OPTwiki]: http://en.wikipedia.org/wiki/Open_Power_Template ""Open Power Template: Wikipedia" [OPT]: http://www.invenzzia.org/en/projects/open-power-libraries/open-power-template "Open Power Template" [OPTreqs]: http://static.invenzzia.org/docs/opt/2_0/book/en/installation.html "Open Power Template: Requirements" [OPTdownload]: http://www.invenzzia.org/en/download/open-power-template/2-0/2-0-4 "Open Power Template: Download page" [OPTinheritance]: http://static.invenzzia.org/docs/opt/2_0/book/en/syntax.topics.modularization.inheritance.html "Open Power Template: Template inheritance"

cake-opt's People

Contributors

dejw avatar

Stargazers

Jacek Jędrzejewski avatar  avatar

Watchers

James Cloos avatar

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.