Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular templates asset #107

Closed

Conversation

bryanchriswhite
Copy link

Synopsis:

This will allow the directory in which your angular templates live to contain jade and/or html and will compile (in the case of jade) and put them in the $templateCache.

This does work with the @rack.assets object if you have multiple assets and are using assets.url(...) in your jade templates.

Need to add the example to the readme but the only notable bit is the need for a templateCacheDirname option for each AngularTemplatesAsset asset. The value of the templateCacheDirname option is the dirname of the templateUrl you will be using in your angular routing configuration or directives to reference the template file.

Example:

This example will compile html and jade documents located on the filesystem in the __dirname + '../widget/app/views' directory, and embed them in JS file served by the server at '/js/widget/templates.js'.

NOTE: all files in the templateUrl should use the .html file extension (including jade templates)

Server

Project directory structure:

  MyExpressApp
  ├── app.js
  ├── assets.js
  ├── public
  │   └── js
  │       └── (nothing on FS here)
  └── widget
      ├── app
      │   ├── controllers
      │   ├── directives
      │   ├── services
      │   └── views
      │       ├── view1.html
      │       └── view2.jade
      └── test
          ├── e2e
          └── spec

In your projects assets.js:

...
  new rack.AngularTemplatesAsset({
    url: '/js/widget/templates.js',
    dirname: __dirname + '../widget/app/views',
    templateCacheDirname: '/widget/views'
  }),
...

Client

In an angular route config:

...
  $routeProvider
    .when('/view1/:id', {
      templateUrl: '/widget/views/view1.html',
      controller: 'MainCtrl'
    },
    .when('/view2/:id', {
      templateUrl: '/widget/views/view2.html',
      controller: 'MainCtrl'
    },
  )
...

…s assets+

* Update readme with examples
* Change `root` option to `templateCacheDirname`: more descriptive
@bryanchriswhite
Copy link
Author

included in #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant