Skip to content

Instantly share code, notes, and snippets.

@agross
Created April 4, 2012 18:12
Show Gist options
  • Save agross/2304377 to your computer and use it in GitHub Desktop.
Save agross/2304377 to your computer and use it in GitHub Desktop.
module Helpers
module Items
class Nanoc::Item
# path gibt die "URL" zum Item zurück
old_path = instance_method(:path)
define_method(:path) do |params = { }|
# Für manche Items will ich direkt auf eine andere Seite linken
return @site.items.find!(self[:forward]).path if self[:forward]
# Oder, falls nicht geforwarded, einfach den normalen path angeben
old_path.bind(self).call(params)
end
# Den original-Path brauch ich an manchen Stellen auch noch...
define_method(:unfordwarded_path) do |params = { }|
old_path.bind(self).call(params)
end
end
end
end
module Helpers
module Items
class Nanoc::Item
alias_method :old_path, :path
def path(params = { })
return @site.items.find!(self[:forward]).path if self[:forward]
old_path(params)
end
end
end
end
###
Captain! We’ve been hit!
=== MESSAGE:
SystemStackError: stack level too deep
=== COMPILATION STACK:
(empty)
=== BACKTRACE:
0. somewhere/tmp/gems/ruby/1.9.1/gems/haml-3.1.4/lib/haml/engine.rb:191
@agross
Copy link
Author

agross commented Apr 5, 2012

Gerade probiert, leider ohne Erfolg. Ich glaube ich verabschiede mich vom Monkey Patching für dieses Problem und erzeuge einfach eine neue Methode url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment