Class: Dommy::CSSNamespace
- Inherits:
-
Object
- Object
- Dommy::CSSNamespace
- Includes:
- Bridge::Methods
- Defined in:
- lib/dommy/css.rb
Overview
‘window.CSS` namespace object — `escape()` for safe selector building (used by Turbo and friends) and a `supports()` stub (no CSS engine).
Class Method Summary collapse
-
.escape(value) ⇒ Object
CSSOM ‘CSS.escape` — escape a string for use as an identifier in a selector.
Instance Method Summary collapse
Methods included from Bridge::Methods
Class Method Details
.escape(value) ⇒ Object
CSSOM ‘CSS.escape` — escape a string for use as an identifier in a selector. Follows the spec’s char rules closely enough for selectors.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/dommy/css.rb', line 307 def self.escape(value) str = value.to_s out = +"" str.each_char.with_index do |ch, i| code = ch.ord if code.zero? out << "\uFFFD" elsif (code >= 0x01 && code <= 0x1F) || code == 0x7F || (i.zero? && code >= 0x30 && code <= 0x39) || (i == 1 && code >= 0x30 && code <= 0x39 && str[0] == "-") out << "\\#{code.to_s(16)} " elsif code >= 0x80 || code == 0x2D || code == 0x5F || (code >= 0x30 && code <= 0x39) || (code >= 0x41 && code <= 0x5A) || (code >= 0x61 && code <= 0x7A) out << ch else out << "\\#{ch}" end end out end |
Instance Method Details
#__js_call__(method, args) ⇒ Object
296 297 298 299 300 301 302 303 |
# File 'lib/dommy/css.rb', line 296 def __js_call__(method, args) case method when "escape" self.class.escape(args[0]) when "supports" false end end |
#__js_get__(_key) ⇒ Object
291 |
# File 'lib/dommy/css.rb', line 291 def __js_get__(_key) = nil |