lib/rubyoshka/renderer.rb
def method_missing(sym, *args, **opts, &block)
      value = @local && @local[sym]
      return value if value

      if sym =~ R_CONST_SYM
        # Component reference (capitalized method name)
        o = instance_eval(sym.to_s) rescue Rubyoshka.const_get(sym) \
            rescue Object.const_get(sym)
        case o
        when ::Proc
          self.class.define_method(sym) { |*a, **c, &b| emit(o.(*a, **c, &b)) }
          emit(o.(*args, **opts, &block))
        when Rubyoshka
          self.class.define_method(sym) do |**ctx|
            ctx.empty? ? emit(o) : with(**ctx) { emit(o) }
          end
          Hash === opts.empty? ? emit(o) : with(**opts) { emit(o) }
        when ::String
          @buffer << o
        else
          e = StandardError.new "Cannot render #{o.inspect}"
          e.set_backtrace(caller)
          raise e
        end
      else
        tag = sym.to_s
        code = S_TAG_METHOD % { tag: tag, TAG: tag.upcase }
        self.class.class_eval(code, __FILE__, S_TAG_METHOD_LINE)
        send(sym, *args, **opts, &block)
      end
    end
# Catches undefined tag method call and handles them by defining the method
# @param sym [Symbol] HTML tag or component identifier
# @param args [Array] method call arguments
# @param block [Proc] block passed to method call
# @return [void]
Catches undefined tag method call and handles them by defining the method
Catches undefined tag method call and handles them by defining the method
def method_missing(sym, *args, **opts, &block)
      value = @local && @local[sym]
      return value if value
      if sym =~ R_CONST_SYM
        o = instance_eval(sym.to_s) rescue Rubyoshka.const_get(sym) \
            rescue Object.const_get(sym)
        case o
        when ::Proc
          self.class.define_method(sym) { |*a, **c, &b| emit(o.(*a, **c, &b)) }
          emit(o.(*args, **opts, &block))
        when Rubyoshka
          self.class.define_method(sym) do |**ctx|
            ctx.empty? ? emit(o) : with(**ctx) { emit(o) }
          end
          Hash === opts.empty? ? emit(o) : with(**opts) { emit(o) }
        when ::String
          @buffer << o
        else
          e = StandardError.new "Cannot render #{o.inspect}"
          e.set_backtrace(caller)
          raise e
        end
      else
        tag = sym.to_s
        code = S_TAG_METHOD % { tag: tag, TAG: tag.upcase }
        self.class.class_eval(code, __FILE__, S_TAG_METHOD_LINE)
        send(sym, *args, **opts, &block)
      end
    end
def method_missing ( sym , * args , ** opts , & block ) value = @local && @local [ sym ] return value if value if sym =~ R_CONST_SYM o = instance_eval ( sym . to_s ) rescue Rubyoshka . const_get ( sym ) rescue Object . const_get ( sym ) case o when :: Proc self . class . define_method ( sym ) { | * a , ** c , & b | emit ( o . ( * a , ** c , & b ) ) } emit ( o . ( * args , ** opts , & block ) ) when Rubyoshka self . class . define_method ( sym ) do | ** ctx | ctx . empty? ? emit ( o ) : with ( ** ctx ) { emit ( o ) } end Hash === opts . empty? ? emit ( o ) : with ( ** opts ) { emit ( o ) } when :: String @buffer << o else e = StandardError . new "Cannot render #{o.inspect}" e . set_backtrace ( caller ) raise e end else tag = sym . to_s code = S_TAG_METHOD % { tag : tag , TAG : tag . upcase } self . class . class_eval ( code , __FILE__ , S_TAG_METHOD_LINE ) send ( sym , * args , ** opts , & block ) end end
Catches undefined tag method call and handles them by defining the method
Catches undefined tag method call and handles them by defining the method
# Component reference (capitalized method name)
None
void
sym
HTML tag or component identifier
HTML tag or component identifier
args
method call arguments
method call arguments
opts
block
block passed to method call
block passed to method call