class PageBuilder::Elements::Basic
A wrapper for Nokogiri::XML::Element so that we can add extra helpers
Public Instance Methods
configure(content = nil, **attributes)
click to toggle source
Helper to easily set the content and attributes for this element @param content [String] text for the content of the element @param attributes [] keyword arguments for the attributes that should be set @option data [Hash] data attributes that should be set @return [self]
# File lib/pagebuilder/elements/basic.rb, line 18 def configure(content = nil, **attributes) self.content = content if content # Deal with helper attributes data_attrs = attributes.delete(:data) self.data_attributes = data_attrs if data_attrs # Set normal attributes attributes.each { |k, v| self[k] = v } self end
data_attributes=(attributes)
click to toggle source
Helper to set data attributes as a single call instead of an individual line for each attribute @param attributes [Hash] data attributes that should be set (minus the “data-” prefix) @return void
# File lib/pagebuilder/elements/basic.rb, line 35 def data_attributes=(attributes) attributes.each do |k, v| self["data-#{k}"] = v end end