Ruby cssesc
A Ruby wrapper for cssesc, a JavaScript library for escaping text for use in CSS strings or identifiers.
Installation
gem install cssesc
API
CSSEsc.escape(value, options = {})
This function takes a value and returns an escaped version of the value where any characters that are not printable ASCII symbols are escaped using the shortest possible (but valid) escape sequences for use in CSS strings or identifiers.
CSSEsc.escape('Ich ♥ Bücher')
# => 'Ich \\2665 B\\FC cher'
By default, CSSEsc.escape
returns a string that can be used as part of a CSS
string. If the target is a CSS identifier rather than a CSS string, use the
is_identifier: true
setting.
The optional options
arguments accepts a Hash
with the exact options
which JavaScript version cssesc uses only converted to the snake_case
:
CSSEsc.espace('123a2b', {
escape_everything: true
})
Dependencies
This library depends on the cssesc-source
gem which is updated any time a
new version of cssesc is released. (The cssesc-source
gem's version number
is synced with each official cssesc release.)
ExecJS
The ExecJS library is used to automatically choose the best JavaScript engine for your platform. Check out its README for a complete list of supported engines.