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

SVG inlining #56

Merged
merged 12 commits into from
Apr 13, 2016
Merged
3 changes: 2 additions & 1 deletion grunt/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ build:
- clean:build
- truecolors_less
- less
- svg_sprite
- svg_inline
- ngtemplates
- copy
- svg_sprite
- browserify:build
- postcss

Expand Down
6 changes: 3 additions & 3 deletions grunt/ngtemplates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

module.exports = function ( grunt )
{
"use strict";

return {
options: {
module: "App",
Expand All @@ -28,7 +28,7 @@ module.exports = function ( grunt )
true;
},
dest: "build/templates.js",
cwd: "source"
cwd: ".inlined"
}
};

Expand Down
51 changes: 51 additions & 0 deletions grunt/svg_inline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";

var inline = require( "web-resource-inliner" );
var a = require( "async" );

module.exports = function ( grunt )
{
grunt.registerTask( "svg_inline", "Inline SVG use", function ()
{
var done = this.async();
var src = [
"modules/*/templates/*.html",
"!modules/_app/templates/index.html"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the index file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the index file is moved from source to build in the copy task, including it here would still lead to it being overwritten when running a build

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be run after copy then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make adjustments as needed for index, it shouldn't be too complicated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Something to consider is that ngtemplates also ignores the index file, so that would need to change as well. Either that or copy references the .inlined index file now.

];

var tasks =
grunt.file.expandMapping( src, ".inlined", { cwd: "source" } )
.map( function ( file )
{
return function ( done )
{
var fileContent = grunt.file.read( file.src );

inline.html( {
fileContent: fileContent,
images: false,
scripts: false,
links: false,
relativeTo: "build/"
}, function ( err, res )
{
if( err )
{
return done( err );
}
grunt.file.write( file.dest, res );
done();
} );
};
} );

a.series( tasks, function ( err )
{
if( err )
{
grunt.fail.warn( err, err.stack );
}
done();
} );
} );
};
2 changes: 1 addition & 1 deletion grunt/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
sprite: {
options: { cwd: "<%= svg_sprite.use.cwd %>" },
files: "<%= svg_sprite.use.src %>",
tasks: [ "svg_sprite" ]
tasks: [ "svg_sprite", "svg_inline", "ngtemplates" ]
},
livereload: {
options: { livereload: true },
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dominatr-grunt",
"version": "6.1.2",
"version": "7.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes this a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changes the default behavior of all SVG elements. To have it be a minor the default behavior should stay the same IMO.

"description": "Build all the things!",
"scripts": {
"test": ""
Expand Down Expand Up @@ -50,12 +50,14 @@
"protractor": "^2.5.1"
},
"dependencies": {
"async": "^2.0.0-rc.2",
"autoprefixer": "^6.1.1",
"aws-sdk": "^2.2.25",
"babel-preset-es2015": "^6.3.13",
"connect-modrewrite": "^0.8.2",
"cssnano": "^3.3.2",
"serve-static": "^1.10.0",
"slack-node": "^0.1.7"
"slack-node": "^0.1.7",
"web-resource-inliner": "^2.0.0"
}
}