This repository has been archived by the owner on Dec 30, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:twitter/recess
Conflicts: package.json test/types/lint.js
- Loading branch information
Showing
16 changed files
with
195 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ========================================== | ||
// RECESS | ||
// COMPILE: replaces image links with base64 image data | ||
// ========================================== | ||
// Copyright 2012 Twitter, Inc | ||
// Licensed under the Apache License v2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// ========================================== | ||
|
||
'use strict' | ||
|
||
var less = require('less') | ||
, fs = require('fs') | ||
, seperator = (process.platform == 'win32') ? '\\' : '/' | ||
, toCSS | ||
, path | ||
|
||
function compile () { | ||
// strip units from 0 values | ||
var props = toCSS.apply(this, arguments) | ||
|
||
// do we have a url here? | ||
if (/url\(/.test(props)) { | ||
var fileName = props.match(/url\((['"]?)(.*)\1\)/)[2] | ||
, ext = fileName.match(/[^.]*$/)[0] | ||
, mimetype = 'image/' + ext.replace(/jpg/, 'jpeg') | ||
, 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\([^\)]*\)/, urlData) | ||
} | ||
|
||
return props | ||
} | ||
|
||
module.exports.on = function () { | ||
path = this.path | ||
toCSS = less.tree.Value.prototype.toCSS | ||
less.tree.Value.prototype.toCSS = compile | ||
} | ||
|
||
module.exports.off = function () { | ||
less.tree.Value.prototype.toCSS = toCSS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// =================================================== | ||
// RECESS | ||
// RULE: Linked images should be embeded. | ||
// =================================================== | ||
// Copyright 2012 Twitter, Inc | ||
// Licensed under the Apache License v2.0 | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// =================================================== | ||
|
||
'use strict' | ||
|
||
var util = require('../util') | ||
, RULE = { | ||
type: 'inlineImages' | ||
, exp: /^url\((?!data:)/ | ||
, message: 'Linked images should be embeded.' | ||
} | ||
|
||
// validation method | ||
module.exports = function (def, data) { | ||
|
||
// default validation to true | ||
var isValid = true | ||
|
||
// return if no selector to validate | ||
if (!def.rules) return isValid | ||
|
||
// loop over selectors | ||
def.rules.forEach(function (rule) { | ||
var extract | ||
|
||
// continue to next rule if no url is present | ||
if ( !(rule.value | ||
&& rule.value.is == 'value' | ||
&& RULE.exp.test(rule.value.toCSS({}))) ) return | ||
|
||
// calculate line number for the extract | ||
extract = util.getLine(rule.index, data) | ||
extract = util.padLine(extract) | ||
|
||
// highlight invalid 0 units | ||
extract += rule.toCSS({}).replace(RULE.exp, function ($1) { | ||
return $1.magenta | ||
}) | ||
|
||
// set invalid flag to false | ||
isValid = false | ||
|
||
// set error object on defintion token | ||
util.throwError(def, { | ||
type: RULE.type | ||
, message: RULE.message | ||
, extract: extract | ||
}) | ||
|
||
}) | ||
|
||
// return validation state | ||
return isValid | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.foo { | ||
background-image: url("sprite.png"); | ||
} | ||
.bar { | ||
background: url('sprite.png'); | ||
} | ||
.fat { | ||
background: url(sprite.png); | ||
} | ||
.woo { | ||
background: #fff url(../sprite.png) center center no-repeat; | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters