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

- (NodeBuilder) initialize(node, builder)

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



185
186
187
# File 'lib/hexp/builder.rb', line 185

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Hexp::Builder::NodeBuilder) method_missing(sym, &block)

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:



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

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