Created
April 4, 2012 18:12
-
-
Save agross/2304377 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Witzig: selbst ohne return other.path kommt der Stack Overflow zustande.
Hast Du Dir mal die original path methode angeschaut? Passt die Methodensignatur genau?
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.
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?
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
Der .path beim return gehört da schon hin, vielleicht forwarded das andere Item ja selber auch.
A -> B
B -> C
A.path soll also C ergeben.