Giter VIP home page Giter VIP logo

undfangularjsbundle's Introduction

AngularJsBundle

This bundle provides you with an easy way to integrate AngularJs into your Symfony2 projects.

It comes with the version 1.0.4 of the AngularJs framework and with a catalogue of angular modules which is very easy to extend with your own modules. Such modules are at this moment split into two main groups:

- vendors: Includes a set of widely used modules (ngResource, angular-ui, ...)
- undf: Includes a set of modules developed by our developers team.

The bundle also comes with an assetic filter (called 'angularjs'), which provides you with an easy way to include all the modules you want to use in your application (and only those) in one single output file.

Installation

Edit your composer.json and add this line in the "require" object

	"undf/angularjsbundle" :"dev-master"

Enable the bundle in your AppKernel.php

	new Undf\AngularJsBundle\UndfAngularJsBundle()

Usage

- [1]. Take a look at the list of available modules:

	php app/console undf:angularjs:catalogue

####- [2]. Make your module selection

The bundle comes with 3 predefined sets of modules:

  • novendors: It includes just the framework with no modules.
  • default: It includes all vendor modules from the catalogue.
  • all: It includes all available modules from the catalogue.

You can add your own module set by editing your config.yml file:

undf_angular_js:
  module_sets:
    mycustomset:
      #Use the star character to include all modules from a root module
      vendors: '*'
      undf: [uFileUpload, taggable]

You can also extend one of the predefined sets:

undf_angular_js:
  module_sets:
    novendors:
      vendors: [ngResource, ui]

####- [3]. Generate the master document for every configured module set:

php app/console undf:angularjs:create-master-files @MyBundle/Resources/public/js

####- [4]. Include the master document corresponding to the module set you want to use in your templates:

{% javascripts
                //...your other javascript files...

                '@MyBundle/Resources/public/js/default.undfangular.js'

                //...your angularjs application files...

                filter="angularjs"
                output="yourOutputFile.js" %}
    <script src="{{ asset_url }}" type="text/javascript" ></script>
{% endjavascripts %}

The "angularjs" is compatible with any other chained filter you want to apply. Just keep in mind that it should run in the first place, otherwise, the generated content will not go throw the chained filter.

####- [5]. Configure your angular application to use the generated module set: Once the angularjs assets are dumped, a new angular module will be created at the end of the dumped file; this module will include all modules within your module set as module dependencies. However, this module will be useless untill you add it as a dependency for you angular application. The name of such a module is always build based on the name of the module set:

Module set Module name
default undfDefaultModule
novendors undfNovendorsModule
... ...
var app = angular.module('myangularapp', ['undfDefaultModule']);

Using your own modules

####- [1]. Extend the catalogue:

undf_angular_js:
  catalogue:
    mypackagename:
      myfirstmodule:
        description: 'Enter the module description here'
        files:
            # Absolute paths to the required files to use this module
            - @MyBundle/Resources/public/js/mymodule.js
      mysecondmodule:
        description: 'Enter the module description here'
        files:
            - @MyOtherBundle/Resources/public/othermodule.js

Tip: Run the undf:angularjs:catalogue command to make sure your new modules have been added.

####- [2]. Add the new modules into a module set:

undf_angular_js:
  module_sets:
    mycustomset:
      vendors: [ngResource, ui]
      mypackagename: [myfirstmodule, mysecondmodule]

Repeat steps 3, 4 and 5 described in the "Usage" section.

Contributing

This is our first approach to the Symfony2-AngularJs integration. The main goal is to get a flexible and easy to extend repository of AngularJs modules, so those modules can be easily reused from one project to another.

Any ideas or suggestions to improve this bundle will be very welcome.

Also, don´t hesitate sending a pull request to include your Angular module within the bundle catalogue, which can be done in only 2 steps:

1. Add the JS files within the Resources/public/js folder
2. Edit the catalogue file (Resources/config/catalogue.yml).

Make sure that the name you use for the module in the catalogue in exactly the same as in the module declaration in the JS file.

TODO

  • Create a css filter to handle all related css files.

  • Allow twig template files as related files.

  • Split vendor modules in separate files.

  • Add unit testing

undfangularjsbundle's People

Contributors

danidelalin avatar guilleferrer avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

undf amadu80

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.