Skip to content

Commit

Permalink
add helper methods to hook refs codefirst#140
Browse files Browse the repository at this point in the history
* plugin_root method
* render javascript file directly
  • Loading branch information
shimomura1004 committed Sep 28, 2013
1 parent 0d8fc69 commit d575720
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/asakusa_satellite/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,25 @@ def self.inherited(klass)
super
end

def self.plugin_root
Pathname("plugins/as_#{self.name.underscore.split("_")[0...-1].join("_")}")
end

@@hooks = {}
def self.render_on(hook, options={})
if @@hooks[hook]
@@hooks[hook].push options
else
@@hooks[hook] = [options]
define_method hook do |context|
@@hooks[hook].map{|options| context[:controller].send(:render_to_string, {:locals => context}.merge(options))}.join("\n")
rendered = @@hooks[hook].map do |options|
if options[:partial]
context[:controller].send(:render_to_string, {:locals => context}.merge(options))
elsif options[:jsfile]
"<script type='text/javascript'>" + File::read(options[:jsfile]) + "</script>"
end
end
rendered.join("\n")
end
end
end
Expand Down

0 comments on commit d575720

Please sign in to comment.