Git Product home page Git Product logo

grunt-ractive-parse's Introduction

grunt-ractive-parse

Pre-parse Ractive templates for use in ExtJS or other MVC projects

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-ractive-parse --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-ractive-parse');

The "ractive_parse" task

Overview

In your project's Gruntfile, add a section named ractive_parse to the data object passed into grunt.initConfig().

grunt.initConfig({
  ractiveparse: {
    options: {
      // Task-specific options go here.
    },
    // Your src directory goes here. 
    // If you have more than one direcotry or want to specify specific files use this syntax ['/one', 'two.html']
    src: '', 

    // Your destination file goes here. Note: you may have only one destination file for each ractive_parse
    dest: ''
  },
});

Options

options.appName

Type: 'String' Default value: NA

A string value that is used set the name of the app. Note: this field is required if you use the 'extjs' type

options.type

Type: String Default value: 'javascript'

A string value that is used to identify the syntax of the parsed templates file. Options are 'javascript' || 'extjs'

options.ignorePath

Type: String Default value: ''

A string value path that is used to identify folder names to skip when creating the ExtJS class name.

options.clsConfig

Type: Object Default value: ''

An object to allow you to set custom properties on your final compiled templates file.

Usage Examples

Default Options

In this example, the default options are used to parse the templates directory. This will loop through all folders in the templates directory and create a single templates javascript file of pre-parsed Ractive templates.

grunt.initConfig({
  ractiveparse: {
    options: {},
    src: 'templates/*',
    dest: 'code/templates.js'
  },
});

Custom Options

In this example, custom options are used to do set the final javascript template file as an Sencha ExtJS class. The appName must match the name of your ExtJS applicaiton. The class path will automatically be set using the appName + the path to your final destination template.

Example

Gruntfile.js

grunt.initConfig({
  ractiveparse: {
    options: {
      appName: 'MyApp',
      type: 'extjs',
      ignorePath: 'app/',
      configCls: {
        singleton: true
      }
    },
    src: 'templates/*',
    dest: 'app/templates/templates.js'
  },
});

File Structure

MyApp/
  |- index.html

  |- app/
    |- templates/

  |- templates/
    |- temp1.html
    |- temp2.html
    |- one/
      |- onetemp1.html
      |- onetemp2.html

MyApp/app/templates/templates.js

Ext.define('MyApp.templates.Templates', {
  
  singleton: true,

  templates: {
    temp1 : [{"t":7,"e":"div","a":{"class":"box"},"f":[{"t":2,"x":{"r":["box","content"],"s":"${0}-${1}"}}]}],
    temp2 : [{"t":7,"e":"button","a":{"class":"btn"},"f":[{"t":2,"x":{"r":["button","label"],"s":"${0}-${1}"}}]}],
    one: {        
        onetemp1 : [{"t":7,"e":"div","a":{"class":"box"},"f":[{"t":2,"x":{"r":["box","content"],"s":"${0}-${1}"}}]}],
        onetemp2 : [{"t":7,"e":"button","a":{"class":"btn"},"f":[{"t":2,"x":{"r":["button","label"],"s":"${0}-${1}"}}]}]
    }
  }
})

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Use the .editorconfig file associated with this project and add unit tests for any new or changed functionality. Lint and test your code using Grunt and grunt-contrib-jshint. Please see the Contributing to grunt guide for information on contributing to this project.

Release History

  • 2014-05-16   v0.1.0   Initiated project.
  • 2014-05-16   v1.0.0   Initial release of project.
  • 2014-05-16   v1.2.0   Published to NPM
  • 2014-05-16   v1.3.0   Added additional build options

grunt-ractive-parse's People

Contributors

4lejandrito avatar

Watchers

 avatar  avatar  avatar

Forkers

demux

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.