Module: Dommy::Internal::ReflectedAttributes
- Included in:
- HTMLElement, SVGElement
- Defined in:
- lib/dommy/internal/reflected_attributes.rb
Overview
IDL-attribute reflection for ‘HTMLElement` and `SVGElement` subclasses.
Two layers:
-
**Instance helpers** (‘reflected_string` / `set_reflected_string` / `reflected_boolean` / `set_reflected_boolean`) delegate to the host element’s standard attribute API (‘get_attribute` / `set_attribute` / `has_attribute?` / `remove_attribute`), so case-sensitivity is inherited from the host’s namespace — HTML lowercases, SVG keeps the spec name (‘viewBox`).
-
String: property mirrors the attribute value. Missing → ‘“”`.
-
Boolean: property is true iff the attribute is present. Setting true writes ‘“”`; setting false removes the attribute.
-
-
**A class-level DSL** (‘reflect_string` / `reflect_boolean`) that declares reflected attributes once and generates BOTH the snake_case getter/setter pair AND a `js_key => ruby_name` registry entry. A shared `js_get` / `js_set` consults that registry, so bridge property access needs no hand-written `case` arm. This keeps the Ruby accessor, the JS getter, and the JS setter from drifting apart (the same class of bug the `js_methods` macro prevents for `js_call`).
reflect_string :cx, :cy, :r reflect_string view_box: "viewBox", class_name: { attr: "class" } reflect_boolean :disabled, :requiredIdentifier defaults (override via a String or Hash value):
- js_key (camelCase IDL name) = camelize(ruby_name) - attr (content attribute) = camelize(ruby_name) - String value overrides attr only: text_anchor: "text-anchor" - Hash value overrides either: tabindex: { js: "tabIndex" }
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#__js_get__(key) ⇒ Object
Bridge property read: route reflected keys to their accessor (which a subclass may have overridden with coercion), else up the super chain.
- #__js_set__(key, value) ⇒ Object
Class Method Details
.included(base) ⇒ Object
38 39 40 |
# File 'lib/dommy/internal/reflected_attributes.rb', line 38 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#__js_get__(key) ⇒ Object
Bridge property read: route reflected keys to their accessor (which a subclass may have overridden with coercion), else up the super chain.
98 99 100 101 102 103 |
# File 'lib/dommy/internal/reflected_attributes.rb', line 98 def __js_get__(key) prop = self.class.reflected_property_map[key] return __send__(prop) if prop super end |
#__js_set__(key, value) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/dommy/internal/reflected_attributes.rb', line 105 def __js_set__(key, value) prop = self.class.reflected_property_map[key] return __send__(:"#{prop}=", value) if prop super end |