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 4, 2012

Witzig: selbst ohne return other.path kommt der Stack Overflow zustande.

@BjRo
Copy link

BjRo commented Apr 4, 2012

Hast Du Dir mal die original path methode angeschaut? Passt die Methodensignatur genau?

@agross
Copy link
Author

agross commented Apr 4, 2012

    def path(params={})
      rep_name = params[:rep] || :default

      # Get rep
      rep = reps.find { |r| r.name == rep_name }
      if rep.nil?
        raise Nanoc::Errors::Generic,
          "No rep named #{rep_name.inspect} was found."
      end

      # Get rep's path
      rep.path
    end

Ich bin ehrlich gesagt ratlos. Vielleicht noch interessant: Der Fehler taucht nur bei nanoc watch auf. Ein normaler Build läuft per Rake durch.

Das gleiches Problem übrigens auch unter Ubuntu.

@BjRo
Copy link

BjRo commented Apr 4, 2012

BTW, so wie Du die Klasse öffnest könnte auch ein Problem sein. Hast Du es mal mit

module Nanoc
class Item
...
end
end

versucht?

@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