Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

suggestion: add views in index.html and use templateCache #769

Closed
andreafdaf opened this issue Aug 6, 2015 · 5 comments
Closed

suggestion: add views in index.html and use templateCache #769

andreafdaf opened this issue Aug 6, 2015 · 5 comments

Comments

@andreafdaf
Copy link

Hi, I've already done this in a project based on mean 0.4.0 so I guess I can make a PR if you want. Let me explain:

config/assets/default.js

views: ['modules/*/client/**/*client.view.html']

config/config.js

var initGlobalConfigFiles = function(config, assets) {
...
  config.files.client.html = getGlobbedPaths(assets.client.views, 'public/');

config/lib/express.js

module.exports.initLocalVariables = function (app) {
...
  app.locals.htmlFiles = config.files.client.html;

modules/core/server/controllers/core.server.controller.js

exports.renderIndex = function(req, res) {
  res.locals.htmlFiles = []
  res.app.locals.htmlFiles.forEach(function (html) {
    var splitted = html.split('/')
    var name = splitted[splitted.length-1].split('.')[0]
    res.locals.htmlFiles.push({
      name: name,
      file: fs.readFileSync(path.resolve(html), 'utf8')
    })
  })
  res.render('modules/core/server/views/index', {
    user: req.user || null
  })
}

modules/core/server/views/layout.server.view.html

{% for html in htmlFiles %}
  <script type="text/ng-template" id="{{html.name}}">{{html.file | safe}}</script>
{% endfor %}

then just use it like that for a view named app.client.view.html:

$stateProvider.
  state('app', {
    url: '/:lang',
    templateUrl: 'app',
    controller: 'AppController'
  })

I saw a bunch of discussions about versions, PR and stuff so... tell me what you think and what to do :)

@trainerbill
Copy link
Contributor

@andreafdaf I too would like to use templateCache. I have a PR to return the /client to the include URL's

#758

I want to get that merged in and then work on a templating solution as well. Lets start by +1 that PR to get it in and I would work with you on getting templateCache introduced. It would increase performance as well.

@andreafdaf
Copy link
Author

Hey @trainerbill ! I'm sorry but I cannot see how is this PR related to what I said... once we introduce templateCache the above way there is no need to worry about the path for the views since they get all "stuffed" into the main HTML file and called by their id when used inside angular

If someone says that PR's are welcome I've got it ready already 👍
@lirantal ? @rhutchison ? @ilanbiala ? anyone? :)

@codydaig
Copy link
Member

codydaig commented Sep 7, 2015

@andreafdaf If you've got a PR ready, submit it and we'll all review it! :-D PR's are always welcome, then it's up to the community for reviewing and discussing if it's an addition to the code base that's wanted by the community.

@andreafdaf
Copy link
Author

after talking with @codydaig it looks that it is already implemented in mean, but works only if you build your project with gulp... I think that things will get more documented over time so it's not a problem

shall we close? :)

@lirantal
Copy link
Member

yep, thanks for confirming @andreafdaf

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

No branches or pull requests

4 participants