class Rembrandt::Highlighter
Attributes
store[W]
Public Class Methods
new(input_engine = nil)
click to toggle source
# File lib/rembrandt/highlighter.rb, line 12 def initialize(input_engine = nil) @engine = input_engine.new if input_engine end
Public Instance Methods
autoselect_engine()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 41 def autoselect_engine begin engines.detect(&:available?).new rescue raise "Error: no highlight engine is available." end end
autoselect_store()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 28 def autoselect_store redis = Stores::Redis.new if redis.available? redis else Stores::File.new end end
default_language()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 24 def default_language Config.default_language end
engine()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 16 def engine @engine ||= autoselect_engine end
engines()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 37 def engines Config.engine_priority end
highlight(input, input_language = default_language)
click to toggle source
# File lib/rembrandt/highlighter.rb, line 49 def highlight(input, input_language = default_language) language = normalize_language(input_language) store.fetch(input, language) do engine.highlight(input, language) end end
highlight_file(filename, language = default_language)
click to toggle source
# File lib/rembrandt/highlighter.rb, line 56 def highlight_file(filename, language = default_language) data = File.read(filename) highlight(data, language) end
language_normalizer()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 65 def language_normalizer @language_normalizer ||= LanguageNormalizer.new end
normalize_language(input)
click to toggle source
# File lib/rembrandt/highlighter.rb, line 61 def normalize_language(input) language_normalizer.process(input) end
store()
click to toggle source
# File lib/rembrandt/highlighter.rb, line 20 def store @store ||= autoselect_store end