Module: Fortitude::Widget::Rendering

Extended by:
ActiveSupport::Concern
Included in:
Fortitude::Widget
Defined in:
lib/fortitude/widget/rendering.rb

Constant Summary collapse

POTENTIAL_NEW_BUFFER_CLASSES =
%w{ActionView::OutputBuffer ActiveSupport::SafeBuffer String}

Instance Method Summary collapse

Instance Method Details

#_fortitude_yield_from_widget(*args) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/fortitude/widget/rendering.rb', line 114

def _fortitude_yield_from_widget(*args)
  if @_fortitude_block_for_content_method
    @_fortitude_block_for_content_method.call(*args)
  elsif @_fortitude_constructor_block
    @_fortitude_constructor_block.call(self, *args)
  else
    @_fortitude_rendering_context.yield_from_widget(self, *args)
  end
end

#call_blockObject

PUBLIC API (Erector compatibility)



130
131
132
# File 'lib/fortitude/widget/rendering.rb', line 130

def call_block
  _fortitude_yield_from_widget
end

#initialize(assigns = { }, &block) ⇒ Object

PUBLIC API



84
85
86
87
# File 'lib/fortitude/widget/rendering.rb', line 84

def initialize(assigns = { }, &block)
  assign_locals_from(assigns)
  @_fortitude_constructor_block = block
end

#output_bufferObject

PUBLIC API



79
80
81
# File 'lib/fortitude/widget/rendering.rb', line 79

def output_buffer
  @_fortitude_output_buffer_holder.output_buffer
end

#render(*args, &block) ⇒ Object

PUBLIC API



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fortitude/widget/rendering.rb', line 12

def render(*args, &block)
  call_through = lambda do
    @_fortitude_rendering_context.record_render(args) do
      tag_rawtext(invoke_helper(:render, *args, &block))
    end
  end

  if self.class._fortitude_record_emitting_tag? && args[0].kind_of?(Hash) && args[0].has_key?(:partial)
    @_fortitude_rendering_context.emitting_tag!(self, Fortitude::Tags::PartialTagPlaceholder.instance, nil, nil, &call_through)
  else
    call_through.call
  end
end

#render_to(rendering_context, &block_for_content_method) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fortitude/widget/rendering.rb', line 26

def render_to(rendering_context, &block_for_content_method)
  @_fortitude_rendering_context = rendering_context
  @_fortitude_output_buffer_holder = rendering_context.output_buffer_holder
  @_fortitude_block_for_content_method = block_for_content_method

  block = lambda { |*args| yield_from_widget(*args) }

  rendering_context.record_widget(self) do
    begin
      run_content(&block)
    ensure
      @_fortitude_rendering_context = nil
      @_fortitude_block_for_content_method = nil
    end
  end
end

#rendering_contextObject

PUBLIC API



50
51
52
# File 'lib/fortitude/widget/rendering.rb', line 50

def rendering_context
  @_fortitude_rendering_context
end

#to_html(rendering_context = ::Fortitude::RenderingContext.new({ })) ⇒ Object

PUBLIC API



44
45
46
47
# File 'lib/fortitude/widget/rendering.rb', line 44

def to_html(rendering_context = ::Fortitude::RenderingContext.new({ }))
  render_to(rendering_context)
  rendering_context.output_buffer_holder.output_buffer
end

#widget(w, hash = nil, &block) ⇒ Object

PUBLIC API



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fortitude/widget/rendering.rb', line 55

def widget(w, hash = nil, &block)
  if w.kind_of?(Class) && ((w < ::Fortitude::Widget) || ::Fortitude::Erector.is_erector_widget_class?(w))
    hash ||= { }
    w = w.new(hash)
  end

  if w.kind_of?(::Fortitude::Widget)
    begin
      @_fortitude_in_block_for_sub_widget = w if block
      w.render_to(@_fortitude_rendering_context, &block)
    ensure
      @_fortitude_in_block_for_sub_widget = nil
    end
  elsif ::Fortitude::Erector.is_erector_widget?(w)
    w.send(:_emit,
      :parent => rendering_context.helpers_object,
      :helpers => rendering_context.helpers_object,
      :output => rendering_context.output_buffer_holder.output_buffer)
  else
    raise "You tried to render a widget, but this is not valid: #{w.inspect}(#{hash.inspect})"
  end
end

#yield_from_widget(*args) ⇒ Object

PUBLIC API



125
126
127
# File 'lib/fortitude/widget/rendering.rb', line 125

def yield_from_widget(*args)
  _fortitude_yield_from_widget(*args)
end