Debugging deface templates

416 views Asked by At

I'm looking to use deface v1.0.2 to modify some haml templates in an existing, complex rails 4.2 application. From this issue, it looks like haml templates are compiled to erb, and then processed by nokogiri, then turned into HTML.

I'm just looking for any suggestions on how to debug the deface templates. Is there a way to capture the intermediate erb step? The particular issue I'm running into is I'm having a hard time writing the correct selectors for the rails view I want to modify (it's a form). Note that I'm using the .deface DSL (files) rather than Deface::Override, but I'm happy to hear debug suggestions in any format.

Things I've done:

  • written a simple selector against an h1 and a div in the page I want to modify
  • tried adding the code to every erb[loud] entity
  • reviewed the readme: https://github.com/DefaceCommunity/deface
  • googled, and this is the most helpful answer, and this showed up as well
  • searched for debug in the project issues (though there are enough forks that I'm not sure which one is canonical)

I'm really looking for a way to learn to write precise selectors that isn't 'guess and check'. I am also open to hearing of other libraries that would be a better choice than deface for modifying views.

Thanks for your time.

1

There are 1 answers

2
mooreds On

Looks like there are a couple of rake tasks which let you test selectors against views:

deface:test_selector - Applies a given CSS selector against a partial or template and outputs the markup for each match (if any). test_selector requires two arguments, the first is the virtual_path for the partial / template, the second is the CSS selector to apply:

rake deface:test_selector[shared/_head,title] 

looks at the shared/_head override and selects the title elements

rake deface:test_selector['admin/products/index','div.toolbar']

looks at the admin/products/index override and selects the div.toolbar elements.

Examples from: https://github.com/DefaceCommunity/deface#rake-tasks