Skip to content
Newer
Older
100644 165 lines (102 sloc) 4.48 KB
5d0d009 added first public version
Nikolaus Graf authored
1 # Fusion
2
4a6c827 added hook option
Nikolaus Graf authored
3 Fusion is a simple tool to merge multiple JavaScript templates (mustache, handlebars, jquery-tmpl, …) into one namespaced template object. It also allows you to define your own precompiling functions.
5d0d009 added first public version
Nikolaus Graf authored
4
8e6ad62 udpated readme
Nikolaus Graf authored
5 ## What is fusion good for?
6
59961ce updated readme
Nikolaus Graf authored
7 You might have noticed that using script tags to manage your JavaScript templates can become quite a mess if you have a bunch of them. It's a good idea to split them into several files. Fusion helps you bring them back together in one neatly organized namespace.
8e6ad62 udpated readme
Nikolaus Graf authored
8
9 For example if you have a directory structure like
10
11 templates/home.html
12 templates/notes/overview.html
13 templates/notes/detail.html
14
15 fusion would compile it to
16
17 (function(){
18 window.templates = {};
19 window.templates.home = '<content of home.html>';
20 window.templates.notes = {};
21 window.templates.notes.overview = '<content of overview.html>';
22 window.templates.notes.detail = '<content of detail.html>';
94567ec updated readme
Nikolaus Graf authored
23 }).call(this);
5d0d009 added first public version
Nikolaus Graf authored
24
f15f6d3 converting underscore files/folders to camel case in the namespace
Nikolaus Graf authored
25 ***camel case*** Fusion generates camel case namespaces. So if you have
26
27 templates/task_list/new_comment.html
28
29 it will generate
30
bde126a Fixed readme
Nikolaus Graf authored
31 templates.taskList.newComment
f15f6d3 converting underscore files/folders to camel case in the namespace
Nikolaus Graf authored
32
1f8a148 added installation hint to readme
Nikolaus Graf authored
33 ## Installation
34
35 npm install fusion
36
5d0d009 added first public version
Nikolaus Graf authored
37 ## How to use
38
6a521db added setttings file info to readme
Nikolaus Graf authored
39 ### Command-line
40
5d0d009 added first public version
Nikolaus Graf authored
41 You can run the script to compile templates via
42
7b36ed4 fixed readme
Nikolaus Graf authored
43 fusion [options] [<directory>]
5d0d009 added first public version
Nikolaus Graf authored
44
f15f6d3 converting underscore files/folders to camel case in the namespace
Nikolaus Graf authored
45 Optional use `--watch` to watch changes in the given directory.
5d0d009 added first public version
Nikolaus Graf authored
46 You don't need to set a directory. You can leave it out and use
47 the one from settings or even fusion's default which is 'templates'.
48
49 Basically you are able to change these settings:
50
51 set output path of templates
52
53 --output [FILE]
54
55 set export namespace
56
57 --namespace [VALUE]
58
59 set extension of template files which should be merged
60
61 --templateExtension [VALUE]
62
63 set path of settings file
64
65 --config [FILE]
66
4a6c827 added hook option
Nikolaus Graf authored
67 set path of the hook file
68
69 --hook [FILE]
70
6a521db added setttings file info to readme
Nikolaus Graf authored
71 #### Example
5d0d009 added first public version
Nikolaus Graf authored
72
73 fusion --watch --config fusion_settings.yaml
74
6a521db added setttings file info to readme
Nikolaus Graf authored
75 ### Settings file
76
f15f6d3 converting underscore files/folders to camel case in the namespace
Nikolaus Graf authored
77 All options except `--watch` and `--config` can be set in the settings file.
78 Unless `--config` is defined the script will search for "settings.yaml"
6a521db added setttings file info to readme
Nikolaus Graf authored
79 in the current directory.
80
81 Possible settings are
82
83 * namespace
84 * templateExtension
85 * input
86 * output
4a6c827 added hook option
Nikolaus Graf authored
87 * hook
88
89 ### Hooks file
90
91 The hooks file provides a way to overwrite all public methods of fusion.
92 Probably the most common case will be to overwrite the compileTemplate method.
93
94 #### Example
95
96 For example to use eco's precompiling for our templates we can create a file
97 fusion_hooks.js which contains something like this
98
99 var eco = require('eco');
8689d4f small fixes in hook demo and readme
Nikolaus Graf authored
100 var fusion = require('fusion');
101 exports.createTemplateObject = function(content, source, directoryPrefix) {
102 return eco.compile(content, { identifier: fusion.templateNamespace(source, directoryPrefix)});
4a6c827 added hook option
Nikolaus Graf authored
103 };
104
105 Thats all you need to add proper precompiling to your templates.
6a521db added setttings file info to readme
Nikolaus Graf authored
106
8689d4f small fixes in hook demo and readme
Nikolaus Graf authored
107 Hint: Eco 1.0.2 yet doesn't provide options for compile, please use a master checkout
108
59961ce updated readme
Nikolaus Graf authored
109 ### Default Settings
110
0f84e33 default settings in readme
Nikolaus Graf authored
111 * settings file: "settings.yaml"
112 * namespace: "window"
113 * template extension: "html"
114 * input directory: "templates"
115 * output file: "templates.js"
4a6c827 added hook option
Nikolaus Graf authored
116 * hook file: "fusion_hooks.js"
59961ce updated readme
Nikolaus Graf authored
117
2690ce7 make fusion more useable if required
Nikolaus Graf authored
118 ### require('fusion');
119
120 For more flexability you can require fusion and run it by your own without the command-line interface.
121
122 var fusion = require('fusion');
123 var settings;
124 settings = fusion.loadSettingsFromFile('settings.yaml');
125 settings = fusion.loadDefaultSettings(settings);
126 settings.watch = true;
127 fusion.run(settings);
128
5d0d009 added first public version
Nikolaus Graf authored
129 ### Demo
130
131 You can see it running by switching to demo folder and run it with watch option.
132 You can change anything in the templates, refresh the index.html and see the new content.
133
4a6c827 added hook option
Nikolaus Graf authored
134 cd demo/simple
135 ./../../bin/fusion --watch
5d0d009 added first public version
Nikolaus Graf authored
136
137 ## Development
138
139 ### Contributing
140
141 Feel free to make a pull request or contact me on Twitter @nikgraf.
142
2a4c3e6 removed runcoffee and added Cakefile
Nikolaus Graf authored
143 To compile src files to lib use
144
145 cake watch
146
5d0d009 added first public version
Nikolaus Graf authored
147 ### Tests
148
2a4c3e6 removed runcoffee and added Cakefile
Nikolaus Graf authored
149 cake test
5d0d009 added first public version
Nikolaus Graf authored
150
8e6ad62 udpated readme
Nikolaus Graf authored
151 ## Thanks
152
59961ce updated readme
Nikolaus Graf authored
153 It was inspired by [Jammit](http://documentcloud.github.com/jammit/)'s templating functionality. Since Jammit doesn't offer file watching via command-line, it's a bit hard to use for development if you are not on a RubyOnRails stack.
8e6ad62 udpated readme
Nikolaus Graf authored
154
0b85291 @tosh
tosh authored
155 Special Thanks to the [CoffeeScript](http://jashkenas.github.com/coffee-script/) Team. We were able to re-use some parts like the optparser.
8e6ad62 udpated readme
Nikolaus Graf authored
156
5d0d009 added first public version
Nikolaus Graf authored
157 ## TODO
158
94567ec updated readme
Nikolaus Graf authored
159 * add cake to rerender all the the demos
9e6c529 @tosh adjusted wording
tosh authored
160 * watch somehow does not work with Textmate - any pointers?
500796d added bug todo
Nikolaus Graf authored
161 * output file - mkdirs or warn if directory doesn't exist
97924f9 updated readme
Nikolaus Graf authored
162 * replace optparser (mabey nomnom?)
5d0d009 added first public version
Nikolaus Graf authored
163 * add github page
9e6c529 @tosh adjusted wording
tosh authored
164 * improve regex in createTemplateObject to work with dotfiles and add option to ignoreDotFiles - tmp and swp files can cause troubles
Something went wrong with that request. Please try again.