Class: Hexp::Builder::NodeBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hexp/builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Allow setting HTML classes through method calls

Examples:

Hexp.build do
  div.miraculous.wondrous do
    hr
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(node, builder) ⇒ NodeBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create new NodeBuilder

Parameters:

  • node (Array)

    (tag, attrs, children) triplet

  • builder (Hexp::Builder)

    The parent builder to delegate back



202
203
204
# File 'lib/hexp/builder.rb', line 202

def initialize(node, builder)
  @node, @builder = node, builder
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, &block) ⇒ Hexp::Builder::NodeBuilder

Used for specifying CSS class names

Examples:

Hexp.build { div.strong.warn }.to_hexp
# => H[:div, class: 'strong warn']

Parameters:

  • sym (Symbol)

    the class to add

Returns:



218
219
220
221
222
223
# File 'lib/hexp/builder.rb', line 218

def method_missing(sym, &block)
  attrs = @node[1]
  @node[1] = attrs.merge class: [attrs[:class], sym.to_s].compact.join(' ')
  @builder._process(&block) if block
  self
end