Coder Social home page Coder Social logo

burtbeckwith / closure-templates-resources Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sheehan/closure-templates-resources

0.0 2.0 0.0 11.25 MB

Grails plugin that supports server-side compilation of .soy template files to .js files.

Groovy 8.66% JavaScript 91.34%

closure-templates-resources's Introduction

Closure Templates Resources plug-in for Grails

This plug-in converts HTML templates into JavaScript functions using Google's Closure Templates.

Closure Templates Documentation: https://developers.google.com/closure/templates/

Note: Google's Closure JavaScript library is not required to use Closure Templates.

Templates

Closure Templates allow you to compile HTML templates into JavaScript functions. The template file includes a namespace declaration followed by one or more templates.

Example file: webapp/soy/task.soy

{namespace grails.views.task}

/**
 * @param name
 * @param dateDue
 */
{template .show}
  <div>
    <div>Name: {$name}</div>
    <div>Date Due: {$dateDue}</div>
  </div>
{/template}

/**
 * @param taskInstanceList
 */
{template .list}
  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Date Due</th>
      </tr>
    </thead>
    <tbody>
      {foreach $taskInstance in $taskInstanceList}
        <tr>
          <td>{$taskInstance.name}</td>
          <td>{$taskInstance.dateDue}</td>
        </tr>
       {/foreach}
    </tbody>
  </table>
{/template}

You can invoke the template from JavaScript using the namespace and the template name like this:

var html = grails.views.task.show({name:'Pay bills', dateDue: '11/11/2011'});

The resulting html can then be inserted into the DOM:

document.getElementById('myContainer').innerHTML = html;

Full documentation can be found here.

Usage

modules = {

    task {
        dependsOn 'soyutils'

        resource url:'js/some-other-file.js'
        resource url: '/soy/task.soy', attrs:[type:'js']
    }
}

Note:

  • The template file must have a .soy extension
  • attrs[type] must be set to 'js'
  • 'soyutils' must be in the dependsOn list. If you're using Google Closure JavaScript library, 'soyutils_usegoog' should be used instead.

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.