Module: Fortitude::Rails::RenderingMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/fortitude/rails/rendering_methods.rb
Class Method Summary collapse
- ._fortitude_register_renderer! ⇒ Object
- ._fortitude_render_widget(controller, widget, options) ⇒ Object
Instance Method Summary collapse
- #create_fortitude_rendering_context(options) ⇒ Object
- #fortitude_rendering_context_for(delegate_object, yield_block) ⇒ Object
- #render_with_fortitude(*args, &block) ⇒ Object
Class Method Details
._fortitude_register_renderer! ⇒ Object
57 58 59 60 61 |
# File 'lib/fortitude/rails/rendering_methods.rb', line 57 def self._fortitude_register_renderer! ::ActionController.add_renderer_without_fortitude(:widget) do |, | ::Fortitude::Rails::RenderingMethods.(self, , ) end end |
._fortitude_render_widget(controller, widget, options) ⇒ Object
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 |
# File 'lib/fortitude/rails/rendering_methods.rb', line 23 def self.(controller, , ) if ::Fortitude::Erector.() || ::Fortitude::Erector.(.class) return ::Erector::Rails.render(, controller.view_context, { }, false, ) end view_context = controller.view_context if .kind_of?(Class) if < ::Fortitude::Widget = .new(.extract_needed_assigns_from(view_context.assigns)) else raise "You tried to render something using 'render :widget' that is a class, but not a subclass of Fortitude::Widget: #{.inspect}" end end if (! .kind_of?(::Fortitude::Widget)) raise "You tried to render something using 'render :widget' that is neither an instance of a subclass of Fortitude::Widget, nor a class that inherits from Fortitude::Widget: #{.inspect}" end rendering_context = controller.create_fortitude_rendering_context( :helpers_object => view_context, :output_buffer_holder => view_context) output_buffer = view_context.with_output_buffer do .render_to(rendering_context) end = .dup .delete(:widget) [:text] = output_buffer.to_s [:layout] = true unless .has_key?(:layout) return controller.render_to_string() end |
Instance Method Details
#create_fortitude_rendering_context(options) ⇒ Object
19 20 21 |
# File 'lib/fortitude/rails/rendering_methods.rb', line 19 def create_fortitude_rendering_context() ::Fortitude::RenderingContext.new() end |
#fortitude_rendering_context_for(delegate_object, yield_block) ⇒ Object
13 14 15 16 17 |
# File 'lib/fortitude/rails/rendering_methods.rb', line 13 def fortitude_rendering_context_for(delegate_object, yield_block) @_fortitude_rendering_contexts ||= { } @_fortitude_rendering_contexts[delegate_object.object_id] ||= create_fortitude_rendering_context( :delegate_object => delegate_object, :yield_block => yield_block) end |
#render_with_fortitude(*args, &block) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fortitude/rails/rendering_methods.rb', line 63 def render_with_fortitude(*args, &block) if ( = args[0]).kind_of?(Hash) && ( = [:inline]) && ([:type] == :fortitude) .delete(:inline) rendering_context = fortitude_rendering_context_for(self, nil) = Class.new(Fortitude::Widgets::Html5) .use_instance_variables_for_assigns(true) .extra_assigns(:use) .send(:define_method, :content, &) assigns = { } instance_variables.each do |ivar_name| value = instance_variable_get(ivar_name) assigns[$1.to_sym] = value if ivar_name =~ /^@([^_].*)$/ end assigns = assigns.merge([:locals] || { }) = .new(assigns) new_args = [ .merge(:widget => ) ] + args[1..-1] return render_without_fortitude(*new_args, &block) end return render_without_fortitude(*args, &block) end |