class HLJS::Adapter
Private Class Methods
source_paths(*patterns)
click to toggle source
# File lib/hljs/adapter.rb, line 19 def self.source_paths(*patterns) define_method :source_paths do base_path = File.expand_path("../../../vendor", __FILE__) patterns.map{ |pattern| Dir["#{base_path}/#{pattern}"] }.flatten.uniq end end
Public Instance Methods
inspect()
click to toggle source
# File lib/hljs/adapter.rb, line 8 def inspect additions = "Version #{version}, #{supported_syntaxes.count} syntaxes supported" to_s.sub(/>\z/, " #{additions}>") end
supported_syntaxes() { || ... }
click to toggle source
# File lib/hljs/adapter.rb, line 13 def supported_syntaxes @supported_syntaxes ||= yield.sort end
Private Instance Methods
check_if_syntax_supported!(syntax)
click to toggle source
# File lib/hljs/adapter.rb, line 38 def check_if_syntax_supported!(syntax) raise UnsupportedSyntaxError, "#{syntax.inspect} syntax is not supported" unless support_syntax?(syntax) end
context()
click to toggle source
# File lib/hljs/adapter.rb, line 34 def context @context ||= ExecJS.compile(source) end
source()
click to toggle source
# File lib/hljs/adapter.rb, line 26 def source @source ||= String.new.tap do |source| source_paths.each do |path| source << File.read(path) end end end
support_syntax?(syntax)
click to toggle source
# File lib/hljs/adapter.rb, line 42 def support_syntax?(syntax) supported_syntaxes.include?(syntax.to_s) end