Sha256: e35220a82d6d3bb3dc8ce2f2fdb61d577491fe7bcb97b3808654de86311f2a80

Contents?: true

Size: 745 Bytes

Versions: 12

Compression:

Stored size: 745 Bytes

Contents

description    'Tag to redirect to other pages'

Application.hook :render do |name, xml, layout|
  if params[:redirect] && layout
    links = [params[:redirect]].flatten.map do |link|
      %{<a href="#{escape_html build_path(link, action: :edit)}">#{escape_html link}</a>}
    end.join(' &#8594; ')
    xml.sub!(/<div id="menu">.*?<\/ul>/m, "\\0Redirected from #{links} &#8594; &#9678; ")
  end
end

Tag.define :redirect, requires: 'to', dynamic: true do |context, attrs|
  list = context.params[:redirect] || []
  to = attrs['to']
  if list.include?(to)
    raise "Invalid redirect to #{to}"
  else
    list << context.page.path
    throw :redirect, build_path(to, 'redirect[]' => list, version: !context.page.head? && context.page)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
olelo-0.9.15 plugins/tags/redirect.rb
olelo-0.9.14 plugins/tags/redirect.rb
olelo-0.9.13 plugins/tags/redirect.rb
olelo-0.9.12 plugins/tags/redirect.rb
olelo-0.9.11 plugins/tags/redirect.rb
olelo-0.9.10 plugins/tags/redirect.rb
olelo-0.9.9 plugins/tags/redirect.rb
olelo-0.9.8 plugins/tags/redirect.rb
olelo-0.9.7 plugins/tags/redirect.rb
olelo-0.9.6 plugins/tags/redirect.rb
olelo-0.9.5 plugins/tags/redirect.rb
olelo-0.9.4 plugins/tags/redirect.rb