Giter Club home page Giter Club logo

Comments (8)

leafo avatar leafo commented on September 3, 2024

Using add_renderer will also make render_to_string widget: Widget work correctly too.

from fortitude.

ageweke avatar ageweke commented on September 3, 2024

OK, I'm looking at this right now. Some of this stuff is just me not knowing about view_context or add_renderer, which I will now use. It's also test cases that I was missing. I imagine it will all be relatively quick to fix…stand by.

from fortitude.

leafo avatar leafo commented on September 3, 2024

As a side note, I don't think the add_renderer approach adds the layout when passing layout: true. It never worked in Erector, so I'm not too concerned, but it would probably be nice to have.

from fortitude.

leafo avatar leafo commented on September 3, 2024

view_context is equal to the template_handler argument that you receive in Fortitude::Rails::Renderer.render btw

from fortitude.

leafo avatar leafo commented on September 3, 2024

add_renderer does not work well if two renderers of the same name are added. It appears to keep the first one only. I ended up patching Erector::Rails.render in my initializer so I could still render widgets even if Erector is loaded first: (this also handles passing a class as the widget options)

If you're planning on keeping erector/fortitude at same time support you can use or modify this.

module Erector
  module Rails
    class << self
      def render_with_fortitude(widget, view, local_assigns = {}, is_partial = false, options = {})
        if widget.is_a?(Class) && widget < ::Fortitude::Widget
          widget = widget.new widget.extract_needed_assigns_from(view.assigns)
        end

        if widget.is_a? ::Fortitude::Widget
          context = ::Fortitude::RenderingContext.new helpers_object: view

          widget.render_to(context)
          return context.output_buffer_holder.output_buffer.to_s
        end

        render_without_fortitude(widget, view, local_assigns, is_partial, options)
      end
      alias_method_chain :render, :fortitude
    end
  end
end

from fortitude.

ageweke avatar ageweke commented on September 3, 2024

OK, just added a whole bunch of specs to the branch ageweke/render_widget that, I think, handle all the cases you reported above. They all fail right now, but I'm going to work on making them pass, using add_renderer. They also cover the case of being able to use render :widget with both Erector and Fortitude widgets simultaneously, so I'm going to do my best to make that work correctly, too.

from fortitude.

ageweke avatar ageweke commented on September 3, 2024

(I have to take off for a few hours shortly, so the fixes will come later this evening, just as a heads-up.)

from fortitude.

ageweke avatar ageweke commented on September 3, 2024

OK, master now has fixes for all this stuff, and there are no issues that I know of remaining around this. I think I even took care of the difficult cases above — you now get layouts (unless you turn them off) using render :widget, and I monkeypatched ActionController.add_renderer so that even if Erector comes in to register its own handler for :widget, we re-register after to make sure both will still work. (It seems like ActionController is last-call-wins there.)

Assuming Travis is happy, I plan to cut 0.0.9 tomorrow with all these fixes.

from fortitude.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.