Skip to content

class NodeBuilder public

Template DSL used in Hokusai::Block.template

.build(name, &block) public

Builds an AST using a DSL

Arguments

  • name - a Hokusai::Block.class
  • block - a DSL callback to build this AST

#merge_styles(names) public

Merge style defintions into this template

Arguments

  • names - a splatted array of style names (*names)

Returns

Returns nothing

#static(name, value, Examples:) public

Declares a static prop

Arguments

  • name - the prop key (Symbol)
  • value - a String containing the static prop value
  • Examples: - static :size, "10" static :content, "'string'"

Returns

Returns nothing

#prop(name, value, &block) public

declare a prop value.

evaluates in the context of the Hokusai::Block

Arguments

  • name - the prop name (Symbol)
  • value - a prop value (required if &block is nil)
  • block - a callback that returns the prop value

Returns

Returns nothing

#show_if(method, &block) public

conditionally render this node if the provided method evaluates to true

Arguments

  • method - name of a method on the calling Hokusai::Block (optional if passing block)
  • block - callback that should evaluate to a boolean (optional if passing method)

Returns

Returns nothing

#each_child(klass, method, &block) public

defines a loop directive

Arguments

  • klass - the Hokusai::Block to use
  • method - a method name (Symbol) that returns an Enumerable
  • block - callback for building this AST node

Examples

ruby
class Something < Hokusai::Block
  template do
    child(Hokusai::Blocks::Vblock) do
      each_child(Hokusai::Blocks::Text, :items) do |item|
        prop :key do
          "key-#{item.value}"
        end
        #
        # item is a Hokusai::ProxyValue
        #
        prop :content do
          item.value
        end
      end
    end
  end
  #
  def items
    %w[foo bar baz]
  end
end

Returns

Returns nothing

#on(event_name, &block) public

Event handler subscription

Arguments

  • event_name - name of event (Symbol | String)
  • block - callback that is passed the event parameters as block params

Examples

ruby
on :click do |event|
  puts event.pos.x # clicked x coordinate
end

Returns

Returns nothing

#child(klass, &block) public

declare a child block

Arguments

  • klass - a Hokusai::Block
  • block - a callback to build this AST node

Examples

ruby
template do
  child(Hokusai::Blocks::Vblock) do
    child(Hokusai::Blocks::Text) do
      #...
    end
  end
end

Returns

Returns nothing