Ticket #58 (new defect)

Opened 7 months ago

Last modified 3 months ago

Markaby and Rails 2.0.2 got into a fist fight and Markaby got beat bad

Reported by: ccm682 Owned by: somebody
Priority: major Milestone: 0.5
Component: lib Version: 0.5
Keywords: markaby rails 2.0.2 Cc:

Description

There is an issue on line 8 in rails.rb that needs to be changed to:

compile_and_render_template(@@template_handlers[template_extension.to_sym], template, file_path, local_assigns)

to support changes made to Rails 2.0.X (first found in Rails 2.0.2). The issue is that in Rails 2.0.2, instead of passing the template_extension as the first paramater, you need to pass the actual template_handler (as indicated above).

Attachments

rails.patch (1.1 kB) - added by randypuro 6 months ago.
lib/markaby/rails.rb patch file

Change History

Changed 6 months ago by randypuro

lib/markaby/rails.rb patch file

Changed 6 months ago by randypuro

The attached patch may provide a better solution. It sends the filename along the the markaby render functionality to allow markaby to indicate the file name and line number for template parsing errors while falling back to the default rails implementation of render_template for all other use cases. In doing so, it should also fix tickets #56 and #57.

Changed 4 months ago by asalant

Randy's patch is good but creates issues when rendering ERB templates. You need to revert Markaby's reimplementation of ActionView::Base#render_template to the core Rails implementation and then use Randy's patch.

To get this fix without modifying Markaby I am patching Rails with:

# Fix up Markaby to address an exception specific to Rails 2.0.2.
# Replace the definition of ActionView::Base#render_template that 
# Markaby overrides in markaby/rails.rb with the original definition 
# from Rails at http://svn.rubyonrails.org/rails/tags/rel_2-0-2/actionpack/lib/action_view/base.rb.
# Then handle Markaby templates specifically to get line numbers in errors.
module ActionView # :nodoc:
  class Base # :nodoc:
    # Renders the +template+ which is given as a string as either erb or builder depending on <tt>template_extension</tt>.
    # The hash in <tt>local_assigns</tt> is made available as local variables.
    def render_template(template_extension, template, file_path = nil, local_assigns = {}) #:nodoc:
      handler = self.class.handler_for_extension(template_extension)

      if template_handler_is_compilable?(handler)
        compile_and_render_template(handler, template, file_path, local_assigns)
      else
        template ||= read_template_file(file_path, template_extension) # Make sure that a lazyily-read template is loaded.
        delegate_render(handler, template, local_assigns)
      end
    end

   def render_template_with_markaby_line_support(template_extension, template, file_path = nil, local_assigns = {})
     handler = self.class.handler_for_extension(template_extension)

     if (handler == Markaby::Rails::ActionViewTemplateHandler)
        template ||= read_template_file(file_path, template_extension)
        handler.new(self).render(template, local_assigns, file_path)
      else
       render_template_without_markaby_line_support(template_extension, template, file_path, local_assigns)
      end
    end

   alias_method_chain :render_template, :markaby_line_support
  end
end

Changed 4 months ago by mkristian

works great for me and the error pages are back too ! thanks

Changed 3 months ago by incense

I just checked out Markaby for evaluating it, and ran into this problem. The fact that this ticket was reported 4 months ago doesn't strengthen my faith into this project. Can I expect this problem to be fixed soon without having to use workarounds (asalant's solution works pretty well for me, but I just don't like it having to clutter my project with such codes)? Thanks, Josh

Note: See TracTickets for help on using tickets.