Glimmer DSL for Web (Fukuoka Award Winning Ruby-in-the-Browser Frontend Framework for Rails) had a new release in version 0.8.3, which now raises an exception plus a correction hint if the user attempts to define a component or a component slot with a name that shadows an existing HTML element.
For example, suppose a developer defines a Glimmer Web Component class called `Input`, which would automatically generate the `input` keyword for use in the Ruby HTML DSL:
class Input
include Glimmer::Web::Component
markup {
h1 { "Hello!" }
}
}
This would normally shadow the HTML input element, preventing the user from being able to use HTML input as in this code:
input(type: 'text', id: 'name', placeholder: 'John Doe')
Instead, input now can only be used according to the component definition (which currently defines zero attributes):
input
This renders <h1>Hello!</h1> as per the Glimmer Web Component definition above. Of course, this is a contrived example as normally, an input component would have some form of inputting behavior, but for the sake of this example, let's imagine that it just renders an h1.
In version 0.8.3, Glimmer DSL for Web now raises an exception if the developer attempts to shadow an existing HTML element:
Cannot define the Glimmer::Web::Component class "Input" because it shadows the HTML element "input"! Either rename the class (e.g. "MyAppInput") to avoid conflicting with an existing HTML element name or nest it within a namespace module/class (e.g. "MyApp::Input")!
class AcmeInput
include Glimmer::Web::Component
markup {
h1 { "Hello!" }
}
}
module Acme
class Input
include Glimmer::Web::Component
markup {
h1 { "Hello!" }
}
}
end
That way, the user can now continue to use standard HTML input in addition to the new input components:
div {
acme_input # the renamed class version
acme__input # the namespaced class version (double-underscores in place of ::)
input(type: 'text', id: 'name', placeholder: 'John Doe') # standard HTML input
}
The same sort of safety harness has been implemented for Component Slots as well.
Glimmer on!!!
No comments:
Post a Comment