Skip to content
This repository was archived by the owner on Jun 25, 2022. It is now read-only.

Commit 33e61fd

Browse files
committed
Better handler of caching
1 parent 08b491d commit 33e61fd

File tree

9 files changed

+42
-50
lines changed

9 files changed

+42
-50
lines changed

Gruntfile.coffee

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ module.exports = (grunt) ->
1717
### Define the configuration for all the tasks ###
1818
grunt.initConfig
1919

20+
# Cache template for packaging
21+
html2js:
22+
options:
23+
base: ''
24+
module: 'stcs-templates'
25+
singleModule: true
26+
useStrict: true
27+
htmlmin:
28+
collapseBooleanAttributes: true
29+
collapseWhitespace: true
30+
removeAttributeQuotes: true
31+
removeComments: true
32+
removeEmptyAttributes: true
33+
removeRedundantAttributes: true
34+
removeScriptTypeAttributes: true
35+
removeStyleLinkTypeAttributes: true
36+
dist:
37+
src: ['<%= yeoman.src %>/html_template/**/*.html']
38+
dest: '<%= yeoman.dist %>/scripts/populate_template_cache.js'
39+
release:
40+
src: ['<%= yeoman.src %>/html_template/**/*.html']
41+
dest: '<%= yeoman.release %>/scripts/populate_template_cache.js'
42+
43+
2044
# Project settings
2145
yeoman: appConfig
2246

@@ -189,18 +213,6 @@ module.exports = (grunt) ->
189213
src: "<%= yeoman.release %>/**/*"
190214
]
191215

192-
ngtemplates:
193-
release:
194-
src: "<%= yeoman.src %>/**/*.html"
195-
dest: '<%= yeoman.release %>/templates.js'
196-
dist:
197-
src: "<%= yeoman.src %>/**/*.html"
198-
dest: '<%= yeoman.dist %>/templates.js'
199-
200-
201-
### Activate grunt-angular-templates ###
202-
grunt.loadNpmTasks 'grunt-angular-templates'
203-
204216
### Custom tasks ###
205217
grunt.registerTask "build", [
206218
"clean:dist"
@@ -210,6 +222,7 @@ module.exports = (grunt) ->
210222
"copy:demo"
211223
"less:dist"
212224
"coffee:dist"
225+
"html2js:dist"
213226
]
214227

215228
grunt.registerTask "serve", [
@@ -229,5 +242,5 @@ module.exports = (grunt) ->
229242
"copy:release"
230243
"less:release"
231244
"coffee:release"
232-
"ngtemplates:release"
245+
"html2js:release"
233246
]

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"Vincent Mézino <vincent.mezino@gmail.com>"
77
],
88
"main" : [
9-
"./release/js/toggle_switch.js",
10-
"./release/css/toggle_switch.css",
11-
"./release/templates.js"
9+
"./release/scripts/toggle_switch.js",
10+
"./release/scripts/populate_template_cache.js",
11+
"./release/css/toggle_switch.css"
1212
],
1313
"description": "Create toggle switches.",
1414
"ignore": [

demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ <h2>Summarize</h2>
8484
<!-- endbower -->
8585

8686
<script type="text/javascript" src="app.js"></script>
87+
<script src="scripts/populate_template_cache.js"></script>
8788
<script type="text/javascript" src="scripts/toggle_switch.js"></script>
8889
</body>
8990
</html>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"test": "grunt test"
88
},
99
"devDependencies": {
10-
"grunt": "~0.4.5",
11-
"grunt-angular-templates": "^0.5.7",
10+
"grunt": "^0.4.5",
1211
"grunt-bower": "~0.20.0",
1312
"grunt-contrib-clean": "~0.6.0",
1413
"grunt-contrib-coffee": "~0.13.0",
1514
"grunt-contrib-copy": "~0.8.1",
1615
"grunt-contrib-less": "~1.0.1",
1716
"grunt-contrib-watch": "~0.6.1",
1817
"grunt-express": "~1.4.1",
18+
"grunt-html2js": "^0.3.5",
1919
"grunt-newer": "~1.1.1",
2020
"grunt-open": "~0.2.3",
2121
"grunt-wiredep": "~2.0.0",

release/scripts/populate_template_cache.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/scripts/toggle_switch.js

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/scripts/toggle_switch.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/templates.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/coffee/toggle_switch.coffee

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'use strict'
22

3-
angular.module('sc-toggle-switch', [])
4-
.run ($templateCache) ->
5-
$templateCache.put('template', '../html_template/toggle_switch_template.html')
3+
angular.module('sc-toggle-switch', ['stcs-templates'])
64
.directive 'toggleSwitchDirective', ($templateCache) ->
75
restrict: 'EA'
8-
templateUrl: $templateCache.get('template')
6+
templateUrl: 'src/html_template/toggle_switch_template.html'
97
controller: 'toggleSwitchController'
108
require: 'ngModel'
119
scope:

0 commit comments

Comments
 (0)