Conversation
|
@marcoroth im seeing some test fails here, but I think they're on main. Anything I can do to help? |
|
@jherdman thanks! I think you might have to run |
| class_attribute :erb_implementation, default: Handlers::Herb::Herb | ||
|
|
||
| def call(template, source) | ||
| return compile_with_fallback_erb_implementation(template, source) unless local_template?(template) |
There was a problem hiding this comment.
If people opt-in to use Herb (or have a .herb file) we should compile everything using Herb. So I think we want to move this condition to lib/reactionview/template/handlers/erb.rb:10:
There was a problem hiding this comment.
OK, I think I understand your motivation, but I want to double check. Am I correct to understand that ReActionView::Template::Handlers::Herb is never used unless we intercept ERb files?
There was a problem hiding this comment.
Correct yes, see here:
reactionview/lib/reactionview/railtie.rb
Lines 28 to 34 in 416995f
So if you have .html.herb it uses ReActionView::Template::Handlers::Herb directly, and otherwise if you have intercept_erb = true it goes through ReActionView::Template::Handlers::ERB
There was a problem hiding this comment.
Ideally, we would still try to compile everything through Herb::Engine and only fall back (and warn) if there are some parse errors. But we don't need to do this in this PR.
There was a problem hiding this comment.
Do you reckon the cost of a rescue, log, retry through the fallback, is acceptable? Implementation doesn't seem that difficult imho.
There was a problem hiding this comment.
Since this is a compile-time concern I'm not too worried about the performance cost, that said, we could also just do it in development/test and not in production.
User's should not be beholden to template errors outside of their application. When we detect a template not local to the project we use the fallback ERB implementation.
5b7269c to
05ead32
Compare
| compiled_source = template_obj.handler.call(template_obj, template) | ||
| result = @view_context.instance_eval(compiled_source).to_s | ||
|
|
||
| normalized_result = result.gsub(/>\s+</, "><").gsub(/\s+/, " ").strip | ||
| assert_equal "<p><h2>I am invalid</h2></p>", normalized_result |
There was a problem hiding this comment.
This test pattern follows your others, but, much to my surprise, something in this setup doesn't raise an error when I encounter an erroneous template. This frustrated my abilities to implement logging.
We know real world usage raises per the original issue. Is there something askew with the test setup?
| template.format == :html && ReActionView.config.intercept_erb && local_template?(template) | ||
| end | ||
|
|
||
| def local_template?(template) |
There was a problem hiding this comment.
Short of exposing this as a class method on the Herb handler, it felt like this duplication was either warranted, so we should consider a TemplateUtilities module that we can mix in. Thoughts?
User's should not be beholden to template errors outside of their application. When we detect a template not local to the project we use the fallback ERB implementation.
Resolves #91