Class: RailsErbCheck::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-erb-lint/helpers/rails_erb_check.rb

Constant Summary collapse

CHECKER =
if defined?(ActionView::Template::Handlers::ERB::Erubi)
  ActionView::Template::Handlers::ERB::Erubi
else
  ActionView::Template::Handlers::Erubis
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(erb_path) ⇒ Checker

Returns a new instance of Checker.



14
15
16
# File 'lib/rails-erb-lint/helpers/rails_erb_check.rb', line 14

def initialize(erb_path)
  @erb = File.read(erb_path)
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



12
13
14
# File 'lib/rails-erb-lint/helpers/rails_erb_check.rb', line 12

def error
  @error
end

Instance Method Details

#valid_syntax?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/rails-erb-lint/helpers/rails_erb_check.rb', line 18

def valid_syntax?
  begin
    CHECKER.new(@erb).result
  rescue SyntaxError => e
    @error = e
    return false
  rescue Exception
    return true
  end
end