Sha256: 8c4dc64c3ed05abd00b30a528f1886d567971a52b3c52456ef0346715f6a3b6a
Contents?: true
Size: 928 Bytes
Versions: 4
Compression:
Stored size: 928 Bytes
Contents
module Ruco module SyntaxParser # textpow only offers certain syntax TEXTPOW_CONVERT = { 'scss' => 'sass', 'html+erb' => 'html', 'rhtml' => 'html', } def self.syntax_for_line(line, languages) syntax_for_lines([line], languages).first end cmemoize :syntax_for_line def self.syntax_for_lines(lines, languages) if syntax = syntax_node(languages) processor = syntax.parse(lines.join("\n"), Ruco::ArrayProcessor.new) processor.lines else [] end end def self.syntax_node(languages) found = nil fallbacks = languages.map{|l| TEXTPOW_CONVERT[l] }.compact (languages + fallbacks).detect do |language| syntax = File.join(Textpow.syntax_path, "#{language}.syntax") found = Textpow::SyntaxNode.load(syntax) if File.exist?(syntax) end found end cmemoize :syntax_node end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ruco-0.2.3 | lib/ruco/syntax_parser.rb |
ruco-0.2.2 | lib/ruco/syntax_parser.rb |
ruco-0.2.1 | lib/ruco/syntax_parser.rb |
ruco-0.2.0 | lib/ruco/syntax_parser.rb |