class ChangeAttrDrop
Wrap a Change in a Drop that emits Element attribute keys as well as the value. An underlying ChangeDrop
will instantiate us as an instance variable and forward its Change to us, then return that instance from its own :attr method.
Our templates can use this to avoid emitting empty attributes for corresponding empty values by calling {{ change.attr.whatever }} instead of invoking the regular ChangeDrop
via {{ change.whatever }}.
For example, if a <source>'s Change defines a media-query, {{ change.media }} will emit the plain value (e.g. `min-width: 800px`) and would typically be used in a template inside an explicit attribute key, e.g. `<source … media=“{{ change.media }}”>`.
A template could instead call this drop via e.g. <source … {{ attr_media }}>` to emit the same thing if a media-query is set but emit nothing if one isn't!
Public Class Methods
# File lib/distorted-jekyll/liquid_liquid.rb, line 217 def initialize(change) @change = change end
Public Instance Methods
# File lib/distorted-jekyll/liquid_liquid.rb, line 220 def liquid_method_missing(method) # The underlying ChangeDrop is what responds to :attr, so we only # need to respond to the Change keys in the same way ChangeDrop does. value = @change&.send(method.to_sym) # Return an empty String if there is no value, otherwise return `attr="value"`. # Intentional leading-space in output so Liquid tags can abut in templates. value.nil? ? ''.freeze : " #{method.to_str}=\"#{value.to_s}\"" end