Sha256: f4bcf5bf0736a60516b4d44a77326d0db4025aade185480639438e1b59f563ce

Contents?: true

Size: 944 Bytes

Versions: 59

Compression:

Stored size: 944 Bytes

Contents

module Jets::RenderingHelper
  # ensure that we always add the controller view name. So when rendering
  # a partial:
  #   <%= render "mypartial" %>
  # gets turned into:
  #   <%= render "articles/mypartial" %>
  def render(options = {}, locals = {}, &block)
    if options.is_a?(String) && !options.include?('/')
      folder = _get_containing_folder(caller)
      partial_name = options # happens to be the partial name
      partial_name = "#{folder}/#{partial_name}"
      options = partial_name
    end

    super(options, locals, &block)
  end

  # Ugly, going back up the caller stack to find out what view path
  # we are in
  def _get_containing_folder(caller_lines)
    caller_line = caller_lines.find { |l| !l.include?('/gems/') }
    text = caller_line.split(':').first
    # .../fixtures/apps/demo/app/views/posts/index.html.erb
    text.split('/')[-2] # posts
  end
end
ActionView::Helpers.send(:include, Jets::RenderingHelper)

Version data entries

59 entries across 59 versions & 2 rubygems

Version Path
jets-3.0.6 lib/jets/overrides/rails/rendering_helper.rb
jets-3.0.5 lib/jets/overrides/rails/rendering_helper.rb
jets-3.0.4 lib/jets/overrides/rails/rendering_helper.rb
jets-3.0.3 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.19 lib/jets/overrides/rails/rendering_helper.rb
jets-3.0.2 lib/jets/overrides/rails/rendering_helper.rb
jets-3.0.1 lib/jets/overrides/rails/rendering_helper.rb
jets-3.0.0 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.18 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.17 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.16 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.15 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.14 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.13 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.12 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.11 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.10 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.9 lib/jets/overrides/rails/rendering_helper.rb
jets-2.3.8 lib/jets/overrides/rails/rendering_helper.rb