Class: Papercraft::ExtensionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/papercraft/extension_proxy.rb

Overview

An ExtensionProxy proxies method calls to a renderer. Extension proxies are used to provide an namespaced interface to Papercraft extensions. When an extension is installed using ‘Papercraft.extension`, a corresponding method is defined on the `Papercraft::Renderer` class that creates an extension proxy that gives access to the different extension methods.

Instance Method Summary collapse

Constructor Details

#initialize(renderer, mod) ⇒ void

Initializes a new ExtensionProxy.

Parameters:



17
18
19
20
# File 'lib/papercraft/extension_proxy.rb', line 17

def initialize(renderer, mod)
  @renderer = renderer
  extend(mod)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, **props, &block) ⇒ Object

Proxies missing methods to the renderer.

Parameters:

  • sym (Symbol)

    method name

  • *args (Array)

    arguments

  • *props (Array)

    named arguments

Returns:

  • void



28
29
30
# File 'lib/papercraft/extension_proxy.rb', line 28

def method_missing(sym, *args, **props, &block)
  @renderer.send(sym, *args, **props, &block)
end

Instance Method Details

#p(text = nil, **props, &block) ⇒ Object

Overrides the ‘Kernel#p` method to emit a p tag.

Parameters:

  • *args (Array)

    arguments

  • *props (Array)

    named arguments

Returns:

  • void



37
38
39
# File 'lib/papercraft/extension_proxy.rb', line 37

def p(text = nil, **props, &block)
  @renderer.p(text, **props, &block)
end