Sha256: 54ec1b8a51e2273f15d92fb82db67b91335f081f715f0da8119c556985e26541

Contents?: true

Size: 908 Bytes

Versions: 42

Compression:

Stored size: 908 Bytes

Contents

module Virgo
  module RenderHelper
    def with_format(format, &block)
      old_formats = formats
      self.formats = [format]
      block.call
      self.formats = old_formats
      nil
    end

    # render_to_string, except force formats = [:html]
    # if none are explicitly provided (so you can call
    # from a controller action body responding to a json
    # request and still render out a html partial by default)
    def render_content(*args, &block)
      augmented_args = _normalize_args(*args, &block)

      augmented_args[:formats] ||= []

      augmented_args[:formats] = [:html] unless augmented_args[:formats].include?(:html)

      # declare so below reference is not block-local
      content = ""

      # necessary to not receive warnings (see above)
      with_format :html do
        content = render_to_string(augmented_args)
      end

      content.html_safe
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
virgo-0.3.17 app/helpers/virgo/render_helper.rb
virgo-0.3.16 app/helpers/virgo/render_helper.rb
virgo-0.3.15 app/helpers/virgo/render_helper.rb
virgo-0.3.14 app/helpers/virgo/render_helper.rb
virgo-0.3.13 app/helpers/virgo/render_helper.rb
virgo-0.3.12 app/helpers/virgo/render_helper.rb
virgo-0.3.11 app/helpers/virgo/render_helper.rb
virgo-0.3.10 app/helpers/virgo/render_helper.rb
virgo-0.3.9 app/helpers/virgo/render_helper.rb
virgo-0.3.8 app/helpers/virgo/render_helper.rb
virgo-0.3.7 app/helpers/virgo/render_helper.rb
virgo-0.3.6 app/helpers/virgo/render_helper.rb
virgo-0.3.4 app/helpers/virgo/render_helper.rb
virgo-0.3.3 app/helpers/virgo/render_helper.rb
virgo-0.3.2 app/helpers/virgo/render_helper.rb
virgo-0.3.1 app/helpers/virgo/render_helper.rb
virgo-0.3 app/helpers/virgo/render_helper.rb
virgo-0.2.9 app/helpers/virgo/render_helper.rb
virgo-0.2.8 app/helpers/virgo/render_helper.rb
virgo-0.2.7 app/helpers/virgo/render_helper.rb