Sha256: 7cac573788aef65c4ef83bcea90c72697246b4292bfb84ee1e95c7a50278a549

Contents?: true

Size: 823 Bytes

Versions: 13

Compression:

Stored size: 823 Bytes

Contents

module Ruco
  module SyntaxParser
    # textpow only offers certain syntax
    TEXTPOW_CONVERT = {
      'html+erb' => 'text.html.ruby',
      'rhtml' => 'text.html.ruby',
    }

    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|
        found = Textpow.syntax(language)
      end

      found
    end
    cmemoize :syntax_node
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ruco-0.2.17 lib/ruco/syntax_parser.rb
ruco-0.2.16 lib/ruco/syntax_parser.rb
ruco-0.2.15 lib/ruco/syntax_parser.rb
ruco-0.2.14 lib/ruco/syntax_parser.rb
ruco-0.2.13 lib/ruco/syntax_parser.rb
ruco-0.2.12 lib/ruco/syntax_parser.rb
ruco-0.2.11 lib/ruco/syntax_parser.rb
ruco-0.2.10 lib/ruco/syntax_parser.rb
ruco-0.2.9 lib/ruco/syntax_parser.rb
ruco-0.2.8 lib/ruco/syntax_parser.rb
ruco-0.2.7 lib/ruco/syntax_parser.rb
ruco-0.2.6 lib/ruco/syntax_parser.rb
ruco-0.2.5 lib/ruco/syntax_parser.rb