Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I syntax check (not render) a Rails 3 ERB template file?

I'm trying to have a git pre-commit hook perform a syntax check on all Ruby code; there is one on GitHub at https://github.com/cypher/git-ruby-syntax-check.

It attempts to check .erb files by erb -x to translate them into Ruby code and then passes the output to ruby -c for syntax checking. Unfortunately, Rails 3 introduced a custom ERB parser that is incompatible with Ruby's standard ERB, and so the pre-commit hook is finding errors where there are none.

Is there some equivalent to erb -x that will output Ruby code from a Rails 3 ERB file?

like image 350
benzado Avatar asked Mar 14 '12 05:03

benzado


People also ask

What is ERB file in Ruby?

ERB (Embedded RuBy) is a feature of Ruby that enables you to conveniently generate any kind of text, in any quantity, from templates. The templates themselves combine plain text with Ruby code for variable substitution and flow control, which makes them easy to write and maintain.

What is ERB templating?

An ERB template looks like a plain-text document interspersed with tags containing Ruby code. When evaluated, this tagged code can modify text in the template. Puppet passes data to templates via special objects and variables, which you can use in the tagged Ruby code to control the templates' output.

Does RuboCop format ERB?

Rubocop. Runs RuboCop on all ruby statements found in ERB templates. The RuboCop configuration that erb-lint uses can inherit from the configuration that the rest of your application uses.


1 Answers

If you get an "argument list too long error" for rails-erb-check , you can try rails-erb-lint which scans your current views folder.

like image 133
kgpdeveloper Avatar answered Sep 19 '22 14:09

kgpdeveloper