Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Built-in formats:
- `'css'`: http://www.w3.org/Style/CSS/
- `'prefixed-css'`: A version of `'css'` that generates a smaller stylesheet but requires the use of the `'prefix'` stylesheet option
- `'javascript'`: Creates a file that exports javascrip object with sprites data.
- `'json'`: Creates a json file with sprites data.

#### options.stylesheetOptions
Type: `Object`
Expand Down
1 change: 1 addition & 0 deletions lib/stylesheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function readTemplatedStylesheetFromFile(file) {
module.exports = {
css: readTemplatedStylesheetFromFile(path.join(__dirname, '/templates/css.tpl')),
javascript: readTemplatedStylesheetFromFile(path.join(__dirname, '/templates/javascript.tpl')),
json: readTemplatedStylesheetFromFile(path.join(__dirname, '/templates/json.tpl')),
less: readTemplatedStylesheetFromFile(path.join(__dirname, '/templates/less.tpl')),
'prefixed-css': require('./prefixed-css'),
sass: readTemplatedStylesheetFromFile(path.join(__dirname, '/templates/sass.tpl')),
Expand Down
4 changes: 4 additions & 0 deletions lib/stylesheet/templates/json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
<% layout.images.forEach(function (image, idx) { %>"<%= image.className %>": { "x": <%= image.x %>, "y": <%= image.y %>, "width": <%= image.width %>, "height": <%= image.height %> }<% if (idx !== layout.images.length - 1) { %>,<% } %>
<% }); %>
}
6 changes: 6 additions & 0 deletions test/fixtures/stylesheets/json/no-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"foo": { "x": 0, "y": 0, "width": 150, "height": 12 },
"bar": { "x": 0, "y": 12, "width": 150, "height": 24 },
"test": { "x": 0, "y": 36, "width": 150, "height": 12 }

}
6 changes: 6 additions & 0 deletions test/fixtures/stylesheets/json/with-nameMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"oof": { "x": 0, "y": 0, "width": 150, "height": 12 },
"rab": { "x": 0, "y": 12, "width": 150, "height": 24 },
"tset": { "x": 0, "y": 36, "width": 150, "height": 12 }

}
6 changes: 6 additions & 0 deletions test/fixtures/stylesheets/json/with-pixelRatio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"foo": { "x": 0, "y": 0, "width": 75, "height": 6 },
"bar": { "x": 0, "y": 6, "width": 75, "height": 12 },
"test": { "x": 0, "y": 18, "width": 75, "height": 6 }

}
6 changes: 6 additions & 0 deletions test/fixtures/stylesheets/json/with-prefix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"prefix-foo": { "x": 0, "y": 0, "width": 150, "height": 12 },
"prefix-bar": { "x": 0, "y": 12, "width": 150, "height": 24 },
"prefix-test": { "x": 0, "y": 36, "width": 150, "height": 12 }

}
6 changes: 6 additions & 0 deletions test/fixtures/stylesheets/json/with-spritePath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"foo": { "x": 0, "y": 0, "width": 150, "height": 12 },
"bar": { "x": 0, "y": 12, "width": 150, "height": 24 },
"test": { "x": 0, "y": 36, "width": 150, "height": 12 }

}
5 changes: 5 additions & 0 deletions test/specs/stylesheet/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var testTemplatedStylesheet = require('./testTemplatedStylesheet');

testTemplatedStylesheet('json');