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-4.0.12 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.11 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.10 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.9 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.8 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.7 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.6 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.5 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.4 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.3 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.2 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.1 lib/jets/overrides/rails/rendering_helper.rb
jets-4.0.0 lib/jets/overrides/rails/rendering_helper.rb
jets-3.2.2 lib/jets/overrides/rails/rendering_helper.rb
jets-3.2.1 lib/jets/overrides/rails/rendering_helper.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/overrides/rails/rendering_helper.rb
jets-3.2.0 lib/jets/overrides/rails/rendering_helper.rb
jets-3.1.5 lib/jets/overrides/rails/rendering_helper.rb
jets-3.1.4 lib/jets/overrides/rails/rendering_helper.rb
jets-3.1.3 lib/jets/overrides/rails/rendering_helper.rb