module Starscope::Lang::ERB
Constants
- ERB_END
- ERB_START
- VERSION
Public Class Methods
extract(_path, contents) { |FRAGMENT, :Ruby, frag: line, line_no: line_no| ... }
click to toggle source
# File lib/starscope/langs/erb.rb, line 13 def self.extract(_path, contents) multiline = false # true when parsing a multiline <% ... %> block contents.lines.each_with_index do |line, line_no| line_no += 1 # zero-index to one-index if multiline term = line.index(ERB_END) if term yield Starscope::DB::FRAGMENT, :Ruby, frag: line[0...term], line_no: line_no line = line[term + 1..-1] multiline = false else yield Starscope::DB::FRAGMENT, :Ruby, frag: line, line_no: line_no end end next if multiline line.scan(/#{ERB_START}(.*?)#{ERB_END}/) do |match| yield Starscope::DB::FRAGMENT, :Ruby, frag: match[0], line_no: line_no end line.gsub!(/<%.*?%>/, '') match = /#{ERB_START}(.*)$/.match(line) next unless match yield Starscope::DB::FRAGMENT, :Ruby, frag: match[1], line_no: line_no multiline = true end end
match_file(name)
click to toggle source
# File lib/starscope/langs/erb.rb, line 9 def self.match_file(name) name.end_with?('.erb') end