postcss-rails-asset-urls
Advanced tools
Comparing version 1.0.1 to 2.0.0
# PostCSS Rails Asset URLs Changelog | ||
1.0.0 Initial Release | ||
## 1.0.1 Initial Release | ||
## 2.0.0 | ||
* Pass the sass-rails version as an option to the plugin. This will determine whether the urls are replaced with `asset-url` or `font-url` and `image-url` depending on the type of the asset. This will default to `asset-url` for backward compatability. |
47
index.js
@@ -5,14 +5,47 @@ var postcss = require('postcss'); | ||
function replaceMatchGroup(match, matchGroup) { | ||
function replaceWithFontUrl(match, matchGroup) { | ||
return "font-url" + matchGroup; | ||
} | ||
function replaceWithImageUrl(match, matchGroup) { | ||
return "image-url" + matchGroup; | ||
} | ||
function replaceWithAssetUrl(match, matchGroup) { | ||
return "asset-url" + matchGroup; | ||
} | ||
var RailsAssetUrls = postcss.plugin('postcss-rails-asset-urls', function () { | ||
return function(css) { | ||
css.eachDecl(function(decl) { | ||
decl.value = decl.value.replace(replacements, replaceMatchGroup); | ||
}); | ||
}; | ||
function isImage(string) { | ||
return !!string.match(/(\.png|\.jpg|\.jpeg|\.gif|\.svg|\.tif|\.tiff)/); | ||
} | ||
var RailsAssetUrls = postcss.plugin('postcss-rails-asset-urls', function (version) { | ||
version = version || '4.0.0'; | ||
if (version.substring(0, 1) > 3) { | ||
return function(css) { | ||
css.eachDecl(function(decl) { | ||
decl.value = decl.value.replace(replacements, replaceWithAssetUrl); | ||
}); | ||
}; | ||
} else { | ||
return function(css) { | ||
css.eachDecl(function(decl) { | ||
if (decl.parent.name === 'font-face') { | ||
decl.value = decl.value.replace(replacements, replaceWithFontUrl); | ||
} else if (isImage(decl.value)) { | ||
decl.value = decl.value.replace(replacements, replaceWithImageUrl); | ||
} | ||
}); | ||
}; | ||
} | ||
}); | ||
if (process.env.NODE_ENV === 'test') { | ||
RailsAssetUrls.replaceWithFontUrl = replaceWithFontUrl; | ||
RailsAssetUrls.replaceWithImageUrl = replaceWithImageUrl; | ||
RailsAssetUrls.replaceWithAssetUrl = replaceWithAssetUrl; | ||
RailsAssetUrls.isImage = isImage; | ||
} | ||
module.exports = RailsAssetUrls; |
{ | ||
"name": "postcss-rails-asset-urls", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "PostCSS plugin that swaps out CSS urls for Rails asset helpers.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# PostCSS Rails Asset URLs | ||
PostCSS plugin to swap CSS URLs with the Rails SASS helper, `asset-url`. This is useful for CSS postprocessor compilation outside of the Rails pipeline when you still want to deploy assets through Rails. `asset-url` in the Rails pipeline will handle fingerprinting and asset paths for you as part of the normal Rails compilation. | ||
PostCSS plugin to swap CSS URLs with the appropriate sass-rails helper. This is useful for CSS postprocessor compilation outside of the Rails pipeline when you still want to deploy assets through Rails. These helpers, when used in the Rails pipeline, will handle fingerprinting and asset paths for you as part of the normal Rails compilation. | ||
@@ -13,2 +13,6 @@ ## Installation | ||
## Use | ||
The post-css plugin function provided by this package takes an argument of the version of sass-rails that you are currently using. If this version is major version 4 or greater, it will replace all urls with `asset-url`. If it is under major version 4, it will replace font urls with `font-url` and image urls with `image-url`. If an argument is not given, it will default to replacing with `asset-url`. | ||
## Example | ||
@@ -21,3 +25,3 @@ | ||
var css = '@font-face {font-family:Test;src:url("test.woff") format("woff"),url("test.otf") format("otf")}'; | ||
console.log(postcss(railsAssetUrls()).process(css).css); | ||
console.log(postcss(railsAssetUrls('4.0.0')).process(css).css); | ||
@@ -33,3 +37,3 @@ // => '@font-face {font-family:Test;src:asset-url("test.woff") format("woff"),asset-url("test.otf") format("otf")}' | ||
processors: [ | ||
require('postcss-rails-asset-urls')() | ||
require('postcss-rails-asset-urls')('4.0.0') | ||
] | ||
@@ -36,0 +40,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5371
41
56
1