Module: Asciidoctor::SyntaxHighlighter::Factory

Included in:
CustomFactory, DefaultFactory
Defined in:
lib/asciidoctor/syntax_highlighter.rb

Instance Method Summary collapse

Instance Method Details

#create(name, backend = 'html5', opts = {}) ⇒ SyntaxHighlighter

Resolves the name to a syntax highlighter instance, if found in the registry.

Parameters:

  • name

    The String name of the syntax highlighter to create.

  • backend (defaults to: 'html5')

    The String name of the backend for which this syntax highlighter is being used (default: ‘html5’).

  • opts (defaults to: {})

    A Hash of options providing information about the context in which this syntax highlighter is used:

Options Hash (opts):

  • :doc (Object)

    The Document for which this syntax highlighter was created.

Returns:

  • (SyntaxHighlighter)

    Returns a SyntaxHighlighter instance for the specified name.



140
141
142
143
144
145
146
# File 'lib/asciidoctor/syntax_highlighter.rb', line 140

def create name, backend = 'html5', opts = {}
  if (syntax_hl = self.for name)
    syntax_hl = syntax_hl.new name, backend, opts if ::Class === syntax_hl
    raise ::NameError, %(#{syntax_hl.class} must specify a value for `name') unless syntax_hl.name
    syntax_hl
  end
end

#for(name) ⇒ Object

Retrieves the syntax highlighter class or object registered for the specified name.

Parameters:

  • name

    The String name of the syntax highlighter to retrieve.

Returns:

  • the SyntaxHighlighter Class or Object instance registered for this name.



128
129
130
# File 'lib/asciidoctor/syntax_highlighter.rb', line 128

def for name
  registry[name]
end

#register(syntax_highlighter, *names) ⇒ void

This method returns an undefined value.

Associates the syntax highlighter class or object with the specified names.

Parameters:

  • syntax_highlighter

    the syntax highlighter implementation to register

  • names

    one or more String names with which to register this syntax highlighter implementation.



119
120
121
# File 'lib/asciidoctor/syntax_highlighter.rb', line 119

def register syntax_highlighter, *names
  names.each {|name| registry[name] = syntax_highlighter }
end