Sha256: 9ca5723eb5cc6c7e16cf818c129ff187ef1bf58cd2014bc9c433282f36e7a3b2

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module WLang
  class Dialect
    module Tags

      module ClassMethods

        protected

        def tag(symbols, dialects = nil, method = nil, &block)
          if block
            tag(symbols, dialects, block)
          else
            dialects, method = nil, dialects if method.nil?
            define_tag_method(symbols, dialects, method)
          end
        end

      end

      module InstanceMethods

        protected

        def render(fn, scope = nil, buffer = "")
          if scope.nil?
            case fn
            when String
              buffer << fn
            when Proc
              fn.call(self, buffer)
            when Template
              fn.call(@scope, buffer)
            else
              raise ArgumentError, "Unable to render `#{fn}`"
            end
          else
            with_scope(scope){ render(fn, nil, buffer) }
          end
        end

      end

      def self.included(mod)
        mod.instance_eval{ include(InstanceMethods) }
        mod.extend(ClassMethods)
      end

    end # module Tags
  end # class Dialect
end # module WLang

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wlang-2.0.0.beta lib/wlang/dialect/tags.rb