Permalink
Browse files

Add some more goodies into core extensions

  • Loading branch information...
1 parent b28a429 commit 72c055c963890247cda062f613d3d646eba19d1b @UnderpantsGnome committed Apr 7, 2007
Showing with 37 additions and 0 deletions.
  1. +37 −0 lib/rails_extensions.rb
View
@@ -4,4 +4,41 @@ def referrer
self.env['HTTP_REFERER']
end
end
+
+ class Base
+ class << self
+ def simple_action(*actions)
+ actions.each {|action| class_eval("def #{action}; end")}
+ end
+ end
+ end
+end
+
+module ApplicationHelper
+ module_eval do
+ def stylesheet_controller_tag
+ stylesheet_link_tag(controller.controller_name) if
+ public_file_exists?(stylesheet_path(controller.controller_name))
+ end
+
+ def javascript_controller_tag
+ javascript_include_tag(controller.controller_name) if
+ public_file_exists?(javascript_path(controller.controller_name))
+ end
+
+ def javascript_action_tag
+ name = "#{controller.controller_name}_#{controller.action_name}"
+ javascript_include_tag(name) if
+ public_file_exists?(javascript_path(name))
+ end
+
+ def public_file_exists?(file)
+ File.exist?(public_file_path(file))
+ end
+
+ def public_file_path(file)
+ file ||= ''
+ File.expand_path(File.join(RAILS_ROOT, 'public', file.gsub(/\?.*$/, '')))
+ end
+ end
end

0 comments on commit 72c055c

Please sign in to comment.