Module: Asciidoctor::SyntaxHighlighter::DefaultFactory

Includes:
Factory
Included in:
Asciidoctor::SyntaxHighlighter, DefaultFactoryProxy
Defined in:
lib/asciidoctor/syntax_highlighter.rb

Constant Summary collapse

PROVIDED =
{
  'coderay' => %(#{__dir__}/syntax_highlighter/coderay),
  'prettify' => %(#{__dir__}/syntax_highlighter/prettify),
  'pygments' => %(#{__dir__}/syntax_highlighter/pygments),
  'rouge' => %(#{__dir__}/syntax_highlighter/rouge),
}
@@registry =
{}
@@mutex =
::Mutex.new

Instance Method Summary collapse

Methods included from Factory

#create

Instance Method Details

#for(name) ⇒ Object

This method will lazy require and register additional built-in implementations, which include coderay, pygments, rouge, and prettify. Refer to Factory#for for parameters and return value.


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/asciidoctor/syntax_highlighter.rb', line 195

def for name
  @@registry.fetch name do
    @@mutex.synchronize do
      @@registry.fetch name do
        if (require_path = PROVIDED[name])
          require require_path
          @@registry[name]
        else
          @@registry = @@registry.merge name => nil
          nil
        end
      end
    end
  end
end

#register(syntax_highlighter, *names) ⇒ Object


188
189
190
191
# File 'lib/asciidoctor/syntax_highlighter.rb', line 188

def register syntax_highlighter, *names
  @@mutex.owned? ? names.each {|name| @@registry = @@registry.merge name => syntax_highlighter } :
      @@mutex.synchronize { register syntax_highlighter, *names }
end