module Facades module Helpers ## # # # Convenience helpers generally used in layout files # module Layout ## # # Allows easy assigning of meta tags from templates # @param [Symbol] name Name of the meta tag (ie: keywords / description) # @param [String] content The content to be used in the meta tag # @return [String] A html meta tag with the name and content attributes set # def meta_tag(name, content = nil) return _retrieve_variable(:"__#{name}") if content.nil? content = tag(:meta, :name => name, :content => content) _create_variable(:"__#{name}", content, false) content end ## # Create a script tag for activating google analytics # @param [String] site_id The site ID provided by google analytics # @return [String] script tag # def google_analytics(site_id) content_tag(:script) do ["var _gaq=[['_setAccount','#{site_id}'],['_trackPageview'],['_trackPageLoadTime']];", "(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;", "g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';", "s.parentNode.insertBefore(g,s)}(document,'script'));"].join("") end end ## # # Creates a page id to be used for identifying a page for CSS/design purposes. If a variable # is defined, it will be used. If not, one will be generated from the current controller/action. # # @param [String] content The string to be used as the page id. # @return [String] The assigned page id # @example Create a page_id and use it in the body tag # <%= page_id('home') %> # #
#=> # # @example Defaulting page id to controller/action # # IndexController#home # #=> # # def page_id(content = nil) _create_variable(:__page_id, content, false) and return if content return _retrieve_variable(:__page_id) if content_for?(:__page_id) result = if defined?(controller) cname = controller.class.to_s.gsub(/controller$/i,'').underscore.split("/").join('_') aname = controller.action_name "#{cname}_#{aname}" elsif defined?(request) && request.respond_to?(:path_info) ::File.basename(request.path_info).to_s end result end ## # # Convenienve method to create a page title for the