public

index.html.haml that's giving an odd error. Why?

  • Download Gist
HAML error that's driving me nuts.md
Markdown

Introduction

The index.html.haml file that follows is from a very basic Rails app meant to demonstrate the convergence of

  • some bespoke Script code (not relevant here; we're not getting that far)
  • Twitter Bootstrap (currently using 3.03; any 3.0+ should be fine with the CSS styles here)
  • posabsolute's jQuery Validation Engine, (hereinafter "jQVE")

This is meant to be used by a Rails (3.2.16) app with Gems haml-rails 0.4 and haml 4.0.4, along with jqVE 2.6.2. The server is Thin 1.6.1.

Errors In My Errors?

I'm getting different error reports when running from the Rails app from Rails and when transpiling the Haml from the command line using the haml command-line utility.

From inside Rails

Here's the output copied from the server log:

ActionView::Template::Error (/Users/jeffdickey/src/rails/meldd/csat-demo/app/views/welcome/index.html.haml:20: unknown regexp options - pa
/Users/jeffdickey/src/rails/meldd/csat-demo/app/views/welcome/index.html.haml:20: syntax error, unexpected $undefined
...group-addon'>Node Index</span>\n              <input#{
...                               ^):
    17:               %span.input-group-addon Selector
    18:               %input.start-selector.form-control#start_selector{type: "text",
    19:                   name: "start-selector",
    20:                   data-validation-engine: "validate[required]"}
    21:             .input-group
    22:               %span.input-group-addon Node Index
    23:               %input.form-control#start_nodeindex{type: "number"}
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/template.rb:297:in `module_eval'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/template.rb:297:in `compile'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/template.rb:244:in `block in compile!'
  <internal:prelude>:10:in `synchronize'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/template.rb:232:in `compile!'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/template.rb:144:in `block in render'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications.rb:125:in `instrument'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/template.rb:143:in `render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications.rb:123:in `block in instrument'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications.rb:123:in `instrument'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/template_renderer.rb:45:in `render_template'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/template_renderer.rb:18:in `render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/renderer.rb:36:in `render_template'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_view/renderer/renderer.rb:17:in `render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/rendering.rb:110:in `_render_template'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/streaming.rb:225:in `_render_template'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/rendering.rb:103:in `render_to_body'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/rendering.rb:88:in `render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/rendering.rb:16:in `render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
  /usr/local/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/core_ext/benchmark.rb:5:in `ms'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
  vendor/ruby/1.9.1/gems/activerecord-3.2.16/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:39:in `render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/base.rb:167:in `process_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/rendering.rb:10:in `process_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:414:in `_run__1992340995968432598__process_action__1957240147877452621__callbacks'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/callbacks.rb:17:in `process_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/rescue.rb:29:in `process_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications.rb:123:in `block in instrument'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/notifications.rb:123:in `instrument'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  vendor/ruby/1.9.1/gems/activerecord-3.2.16/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/base.rb:121:in `process'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/rendering.rb:45:in `process'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal.rb:203:in `dispatch'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal.rb:246:in `block in action'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:73:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:36:in `call'
  vendor/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
  vendor/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
  vendor/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:608:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/head.rb:14:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/flash.rb:242:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/cookies.rb:341:in `call'
  vendor/ruby/1.9.1/gems/activerecord-3.2.16/lib/active_record/query_cache.rb:64:in `call'
  vendor/ruby/1.9.1/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `_run__453547187854990700__call__3903132365996989445__callbacks'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/reloader.rb:65:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/rack/logger.rb:32:in `call_app'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/rack/logger.rb:16:in `block in call'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/tagged_logging.rb:22:in `tagged'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/rack/logger.rb:16:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/request_id.rb:22:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
  vendor/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
  vendor/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/static.rb:63:in `call'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/engine.rb:484:in `call'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/application.rb:231:in `call'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/rack/log_tailer.rb:17:in `call'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/connection.rb:82:in `block in pre_process'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/connection.rb:80:in `catch'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/connection.rb:80:in `pre_process'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/connection.rb:55:in `process'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/connection.rb:41:in `receive_data'
  vendor/ruby/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
  vendor/ruby/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/backends/base.rb:73:in `start'
  vendor/ruby/1.9.1/gems/thin-1.6.1/lib/thin/server.rb:162:in `start'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/thin.rb:13:in `run'
  vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:268:in `start'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/commands/server.rb:70:in `start'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/commands.rb:55:in `block in <top (required)>'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/commands.rb:50:in `tap'
  vendor/ruby/1.9.1/gems/railties-3.2.16/lib/rails/commands.rb:50:in `<top (required)>'
  vendor/ruby/1.9.1/gems/spring-1.0.0/lib/spring/client/rails.rb:29:in `require'
  vendor/ruby/1.9.1/gems/spring-1.0.0/lib/spring/client/rails.rb:29:in `call'
  vendor/ruby/1.9.1/gems/spring-1.0.0/lib/spring/client/command.rb:7:in `call'
  vendor/ruby/1.9.1/gems/spring-1.0.0/lib/spring/client.rb:23:in `run'
  vendor/ruby/1.9.1/gems/spring-1.0.0/bin/spring:31:in `<top (required)>'
  /bin/spring:16:in `load'
  /bin/spring:16:in `<main>'

From the Command Line

Running haml --trace app/view/welcome/index.html.haml yields the following output to stderr:

/Users/jeffdickey/src/rails/meldd/csat-demo/vendor/ruby/1.9.1/gems/haml-4.0.4/lib/haml/engine.rb:131:in `rescue in render': app/views/welcome/index.html.haml:20: unknown regexp options - pa (Haml::SyntaxError)
app/views/welcome/index.html.haml:20: syntax error, unexpected $undefined
...group-addon'>Node Index</span>\n              <input#{
...                               ^
    from /Users/jeffdickey/src/rails/meldd/csat-demo/vendor/ruby/1.9.1/gems/haml-4.0.4/lib/haml/engine.rb:128:in `render'
    from /Users/jeffdickey/src/rails/meldd/csat-demo/vendor/ruby/1.9.1/gems/haml-4.0.4/lib/haml/exec.rb:313:in `process_result'
    from /Users/jeffdickey/src/rails/meldd/csat-demo/vendor/ruby/1.9.1/gems/haml-4.0.4/lib/haml/exec.rb:43:in `parse'
    from /Users/jeffdickey/src/rails/meldd/csat-demo/vendor/ruby/1.9.1/gems/haml-4.0.4/lib/haml/exec.rb:23:in `parse!'
    from /Users/jeffdickey/src/rails/meldd/csat-demo/vendor/ruby/1.9.1/gems/haml-4.0.4/bin/haml:9:in `<top (required)>'
    from ./bin/haml:16:in `load'
    from ./bin/haml:16:in `<main>'

Hmmm.

The Haml command-line output is complaining about "unknown regex options", as pa, and an unexpected $undefined. There are exactly three ways the consecutive letters p and a appear in the input file:

  1. as part of the HTML tag span, e.g. at lines 17 and 22;
  2. as part of CSS class names, e.g. .panel, .page-header, .page-content;
  3. as part of the boilerplate content following line 46.

Help?

index.html.haml
Haml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
.page-header.row
%h1 CSAT Demo
%p Demonstrates content-selection automated testing for our app.
%p
Specifically, defining a selection in terms of its endpoints, and defining
those in terms of an unambiguous selector, a node index and a text offset.
 
.page-content
.row
%form
.col-md-5
.panel.panel-default
.panel-heading
%h2.panel-title Selection Start
.panel-body
.input-group
%span.input-group-addon Selector
%input.start-selector.form-control#start_selector{type: "text",
name: "start-selector",
data-validation-engine: "validate[required]"}
.input-group
%span.input-group-addon Node Index
%input.form-control#start_nodeindex{type: "number"}
.input-group
%span.input-group-addon Text Offset
%input.form-control{type: "number", id: "start_textoffset"}
 
.col-md-5
.panel.panel-default
.panel-heading
%h2.panel-title Selection End
.panel-body
.input-group
%span.input-group-addon Selector
%input.form-control{type: "text", id: "end_selector"}
.input-group
%span.input-group-addon Node Index
%input.form-control{type: "number", id: "end_nodeindex"}
.input-group
%span.input-group-addon Text Offset
%input.form-control{type: "number", id: "end_textoffset"}
 
.col-md-2
%button.btn.btn-primary{type: 'submit'} Select
 
.row.well.well-sm
%h2 Content affected by the selection is below.
/
Courtesy of the Google Web Style Guide, 3rd edition, by Patrick J Lynch
and Sarah Horton; adapted from
http://www.webstyleguide.com/wsg3/5-site-structure/2-semantic-markup.html
.row
.col-md-12.boilerplate
%h1 This is the most important headline
%p
This is ordinary paragraph text within the body of the document, where
certain words and phrases may be <em>emphasized</em> to mark them as
%strong>
particularly important
\.
%h2 This is a headline of secondary importance to the headline above
%p
Any time you list related things, the items should be marked up in the
form of a list:
%ul
%li<
A list signals that a group of items are conceptually related to each
other
%li<
Lists may be ordered (numbered or alphabetic) or unordered (bulleted
items)
%li<
Lists may also be menus or lists of links for navigation
%li<
Cascading Style Sheets can make lists look many different ways

try putting data-validation-engine in quotes as I think - breaks the parser

Yeah, the hyphens muck it all up. You can do this a couple of different ways:

%input.start-selector.form-control#start_selector{ type: "text",
  name: "start-selector",
  'data-validation-engine': "validate[required]" #note quotes around symbol name
}

%input.start-selector.form-control#start_selector{
  type: "text",
  name: "start-selector",
  data: {
    validation_engine: 'validate[required]' #note data hash and use of underscore instead of dash
  }
}

The second syntax is nice if you have multiple data attributes.

@jnf, @siaorsi, thanks! I was able to get rid of the error by using either

'data-validation-engine' => 'validate[required]'

or

data: {validation: {engine: 'validate[required]'}}

I prefer and will use the second form because

  • it reminds me to use a consistent rule (no dashes in attributes; use hashes instead); and
  • it doesn't care if I use (or intermix) colons and hash-rockets.

Shout out to CordialMayhem and galaxian_prime on Reddit who gave equivalent answers when I asked there too.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.