Permalink
Browse files

minor tweaks to inlineImages feature ref pull req #32. added another …

…test for embedding images that include paths.
  • Loading branch information...
1 parent 71d5b62 commit aa6b8152603ea2e1c51e9bfb2c2e88d9c7cda625 @gcoop gcoop committed Jun 30, 2012
@@ -20,15 +20,16 @@ function compile () {
var props = toCSS.apply(this, arguments)
// do we have a url here?
- if (/url\(([a-zA-Z\"\'.]+)\)/.test(props)) {
- var fileName = props.replace(/url\((\"|\'|)/, '').replace(/(\"|\'|)\)/, '')
- , chunks = fileName.split('.')
- , ext = chunks[chunks.length - 1]
+ if (/url\(/.test(props)) {
+ var fileName = props.match(/url\((['"]?)(.*)\1\)/)[2]
+ , ext = fileName.match(/[^.]*$/)[0]
, mimetype = 'image/' + ext.replace(/jpg/, 'jpeg')
- , pathParts = path.split('/')
+ , pathParts = path.split(seperator)
, filePath = pathParts.slice(0, pathParts.length - 1).join(seperator)
+ , imgBuffer = new Buffer(fs.readFileSync(filePath+seperator+fileName)).toString('base64')
+ , urlData = 'url(data:' + mimetype + ';base64,' + imgBuffer + ')'
- return props.replace(/url\(([a-zA-Z\"\'.]+)\)/, 'url(data:' + mimetype + ';base64,' + new Buffer(fs.readFileSync(filePath+seperator+fileName)).toString('base64') + ')')
+ return props.replace(/url\([^\)]*\)/, urlData)
}
return props
View
@@ -81,7 +81,7 @@ module.exports.DEFAULTS = RECESS.DEFAULTS = {
, stripColors: false
, watch: false
, zeroUnits: true
-, inlineImages: true
+, inlineImages: false
}
@@ -12,7 +12,7 @@
var util = require('../util')
, RULE = {
type: 'inlineImages'
- , exp: /url\(([a-zA-Z\"\'.]+)\)/
+ , exp: /^url\((?!data:)/
, message: 'Linked images should be embeded.'
}
View
@@ -1,10 +1,5 @@
/* Fat's blog styles */
-@font-face {
- font-family: "Mistral";
- src: url("/fonts/Mistral.ttf");
-}
-
html,
body {
overflow: auto;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,10 +1,5 @@
/* Fat's blog styles */
-@font-face {
- font-family: "Mistral";
- src: url("/fonts/Mistral.ttf");
-}
-
html,
body {
overflow: auto;
@@ -6,4 +6,7 @@
}
.fat {
background: url(sprite.png);
+}
+.woo {
+ background: #fff url(../sprite.png) center center no-repeat;
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -9,7 +9,7 @@ fs.readdirSync('test/fixtures').forEach(function (file, index) {
return
}
- RECESS('test/fixtures/' + file, { compile: true }, function (err, fat) {
+ RECESS('test/fixtures/' + file, { compile: true, inlineImages: true }, function (err, fat) {
file = file.replace(/less$/, 'css')
assert.ok(err == null)
assert.ok(fat.output[0] == fs.readFileSync('test/compiled/' + file, 'utf-8'))

0 comments on commit aa6b815

Please sign in to comment.