Sha256: 4a029a8a8f54124eb4a619ff9e16c5db816ec6f4d526308278d937bd372186a1

Contents?: true

Size: 1.66 KB

Versions: 14

Compression:

Stored size: 1.66 KB

Contents

module Arbre
  class Context
    def resource
      helpers.resource
    end
  end

  class Element

    module BuilderMethods

      # we do not want to check the arity of the
      # block in express templates because components
      # are expected to be able to contain other components or template code
      # without use of a builder style syntax
      def build_tag(klass, *args, &block)
        tag = klass.new(arbre_context)
        tag.parent = current_arbre_element

        with_current_arbre_element tag do
          tag.build(*args, &block)
        end

        tag
      end
    end

    # Implements the method lookup chain. When you call a method that
    # doesn't exist, we:
    #
    #  1. Try to call the method on the current DOM context
    #  2. Return an assigned variable of the same name
    #  3. Call the method on the helper object
    #  4. Call super
    #
    def method_missing(name, *args, &block)
      if current_arbre_element.respond_to?(name)
        current_arbre_element.send name, *args, &block
      elsif assigns && assigns.has_key?(name)
        assigns[name]
      elsif helpers.respond_to?(name)
        helper_method(name, *args, &block)
      else
        super
      end
    end

    # In order to not pollute our templates with helpers. prefixed
    # everywhere we want to try to distinguish helpers that are almost
    # always used as parameters to other methods such as path helpers
    # and not add them as elements
    def helper_method(name, *args, &block)
      if name.match /_path$/
        helpers.send(name, *args, &block)
      else
        current_arbre_element.add_child helpers.send(name, *args, &block)
      end
    end

  end

end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
express_admin-1.4.5 vendor/gems/express_templates/lib/arbre/patches.rb
express_templates-0.9.4 lib/arbre/patches.rb
express_templates-0.9.3 lib/arbre/patches.rb
express_admin-1.4.4 vendor/gems/express_templates/lib/arbre/patches.rb
express_admin-1.4.3 vendor/gems/express_templates/lib/arbre/patches.rb
express_templates-0.9.1 lib/arbre/patches.rb
express_admin-1.4.2 vendor/gems/express_templates/lib/arbre/patches.rb
express_templates-0.9.0 lib/arbre/patches.rb
express_admin-1.4.1 vendor/gems/express_templates/lib/arbre/patches.rb
express_admin-1.4.0 vendor/gems/express_templates/lib/arbre/patches.rb
express_templates-0.8.0 lib/arbre/patches.rb
express_admin-1.3.2 vendor/gems/express_templates/lib/arbre/patches.rb
express_admin-1.3.1 vendor/gems/express_templates/lib/arbre/patches.rb
express_templates-0.7.1 lib/arbre/patches.rb