Sha256: 35622ee5bafb449f282e2e59c1976bb90eb473359bcb7fdc1d57e7638eeddbde
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
require 'find' require 'active_record' def countl(target, to) i = 0 a = "" target.each_byte do |x| a << x a = "" unless to.index(a) == 0 i = i + 1 if a == to a = "" if a == to end i end def find_mismatches dir, tags='{,[' tags.split(',').each { |x| find_mismatch dir, x } end def find_mismatch dir, tag dir = File.join(Rails.root, dir) excludes = ["theme", "js", "touch"] openTag = tag closeTag = getCloseTag(tag) Find.find(dir) do |path| if FileTest.directory?(path) if excludes.include?(File.basename(path)) Find.prune # Don't look any further into this directory. else next end else next unless path.end_with?('.js') open = 0 close = 0 File.open(path).each do |line| open += countl(line, openTag) close += countl(line, closeTag) end puts "#{openTag} - #{path} : #{open} - #{close} = #{open - close}" unless open - close == 0 end end end def getCloseTag tag if(tag == '{') return '}' elsif(tag == '[') return ']' elsif(tag == '(') return ')' else raise "Not support tag #{tag}!" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hatio-core-0.0.6 | lib/utils/detect_mismatch_tags.rb |