-
Notifications
You must be signed in to change notification settings - Fork 440
Conversation
* swig.setDefaults({ loader: swig.loaders.FileSystem() }); | ||
* @example | ||
* // Memory Loader | ||
* swig.setDefaults({ memory: swig.loaders.Memory({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: should be swig.setDefaults({ loader: swig.loaders.Memory({
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Thanks!
I just built the latest version of swig and added it to my project – great work all around. Being able to use extends and include in the browser is awesome. My flow for client-side rendering works like this:
I know there was an old flow that involved compiling the template like this
Is the goal to eventually move back to this method or to rely on something similar to the steps above? |
@gleitz: There are a lot of ways that templates can be loaded in the browser. I'd like to extend the docs to give a bit of a better method/example. While this PR doesn't really adhere to what I see as the best choice (my opinion) for loading templates in the browser, I still like it because it modularizes the ability to load templates and allows the developer to write their own loader that could pull from a database or memcached or anything, really. Ideally, as I see it, you would have a better build system that integrates with swig's CLI compile tool to do the following:
templates := $(shell cd templates && find . -name '*.test.html')
foo.js:
@echo "var templates = {" > $@
@for tpl in ${templates}; do \
bin/swig.js compile templates/$$tpl --wrap-start="'$$tpl':" --wrap-end="," >> $@ ; \
done
@echo "};" >> $@
@sed -i.bak 's/\.\//\//g' $@
@rm [email protected] So, basically, you compile every template into an executable method, keyed on an object, and you'll never need to worry about extends or includes, since the full template is compiled ahead of time. Obviously this has a shortfall on includes, but it's still my preference, since now you don't need to rely on your end-user's browser to compile the templates (and you can minify the source). swig.run(templates['myfile.html'], {), 'myfile.html'); |
…wig into feature/template-loaders Conflicts: docs/docs/loaders.html lib/loaders/filesystem.js lib/loaders/index.js lib/loaders/memory.js lib/swig.js tests/loaders.test.js
Great job @paularmstrong! |
Continuation of gh-377.
From @MaratFM:
TODO: