Sha256: 400473fa702122294cecc8db20ba582aa38b8ba32c80de140a4189d60d750a8d

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module Codeqa
  module Checkers
    class CheckErb < Checker
      def self.check?(sourcefile)
        sourcefile.erb?
      end

      def self.available?
        engine?
      end

      def name
        'erb syntax'
      end

      def hint
        'There is a syntax error in the ruby code of the erb parsed file.'
      end

      # rubocop:disable RescueException,HandleExceptions
      def check
        if defined?(ActionView)
          ActionView::Template::Handlers::Erubis.new(erb).result
        else
          ERB.new(sourcefile.content.gsub('<%=', '<%'), nil, '-').result
        end
      rescue SyntaxError => e
        errors.add(nil, <<-EOF)
        #{e.message}
        #{e.backtrace.join("\n")}
        EOF
      rescue Exception
        true # valid syntax - just the proper setup for the template/rendering is missing
      end
      # rubocop:enable RescueException,HandleExceptions

      def self.engine?
        @@engine ||= if %w(actionview action_view).include? Codeqa.configuration.erb_engine.downcase
                       require 'action_view'
                       true
                     else
                       require 'erb'
                       true
                     end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
codeqa-0.5.0 lib/codeqa/checkers/check_erb.rb
codeqa-0.4.2 lib/codeqa/checkers/check_erb.rb
codeqa-0.4.1 lib/codeqa/checkers/check_erb.rb
codeqa-0.4.0 lib/codeqa/checkers/check_erb.rb
codeqa-0.4.0.pre2 lib/codeqa/checkers/check_erb.rb
codeqa-0.4.0.pre lib/codeqa/checkers/check_erb.rb