Skip to content

Commit

Permalink
Improve hook compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyken committed Sep 4, 2014
1 parent 90f5050 commit cc3f98a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/fat_free_crm/callback.rb
Expand Up @@ -30,7 +30,7 @@ def self.responder(method)
def self.hook(method, caller, context = {})
str = ""
responder(method).map do |m|
str << m.send(method, caller, context)
str << m.send(method, caller, context) if m.respond_to?(method)
end
str
end
Expand Down Expand Up @@ -98,7 +98,7 @@ def hook(method, caller, context = {}, &block)
is_view_hook = caller.is_haml?

# If a block was given, hooks are able to replace, append or prepend view content.
if block_given? and is_view_hook
if is_view_hook
hooks = FatFreeCRM::Callback.view_hook(method, caller, context)
# Add content to the view in the following order:
# -- before
Expand All @@ -108,7 +108,12 @@ def hook(method, caller, context = {}, &block)
hooks[:before].each{|data| view_data << data }
# Only render the original view block if there are no pending :replace operations
if hooks[:replace].empty?
view_data << capture(&block)
view_data << if block_given?
capture(&block)
else
# legacy view hooks
FatFreeCRM::Callback.hook(method, caller, context)
end
else
hooks[:replace].each{|data| view_data << data }
end
Expand Down

0 comments on commit cc3f98a

Please sign in to comment.