Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made page_header and page_title use blocks. Added rjs_flash helper.

  • Loading branch information...
commit 8bf3870661ebee4340a2b9adabcb8f7d0da7f336 1 parent faedc6f
Norman Clarke authored
View
1  base_site_generator.rb
@@ -5,6 +5,7 @@ def manifest
m.file "config/application.yml", "config/application.yml"
m.file "app/helpers/application_helper.rb", "app/helpers/application_helper.rb"
m.directory "app/views/common"
+ m.file "app/views/layouts/main.html.erb", "app/views/layouts/main.html.erb"
m.file "app/views/common/403.html.erb", "app/views/common/403.html.erb"
m.file "app/views/common/404.html.erb", "app/views/common/404.html.erb"
m.file "app/views/common/_analytics.html.erb", "app/views/common/_analytics.html.erb"
View
29 templates/app/helpers/application_helper.rb
@@ -9,18 +9,39 @@ def content_exists(name)
instance_variable_defined?("@content_for_#{name.to_s}")
end
- def page_header(text)
+ # Wrap the page header content with this function so that it can be used as
+ # a fallback page title.
+ def page_header(text = nil, options = {}, &block)
+ options[:id] ||= "page_header"
+ options[:class] ||= "page_header"
content_for :page_header do
- content_tag(:h2, text)
+ if block_given?
+ content_tag(:h2, capture(&block), options)
+ else
+ content_tag(:h2, text, options)
+ end
end
end
- def page_title(text)
+ # Set the page title.
+ def page_title(text = nil, &block)
content_for :page_title do
- text
+ if block_given?
+ capture(&block)
+ else
+ text
+ end
end
end
+ # Show the flash in an RJS template and then discard it so that it's not
+ # shown on the next page load. This allows you to avoid having to set the
+ # same flash message twice for actions that respond with RJS or HTML.
+ def rjs_flash(page)
+ page.replace "flash", :partial => "common/flash", :locals => {:flash => flash}
+ flash.discard
+ end
+
def page_title_or_header
text = @content_for_page_title || @content_for_page_header || ''
strip_tags(text) + (text.include?(APP_CONFIG["site_name"]) ? '' : " - #{APP_CONFIG["site_name"]}")
Please sign in to comment.
Something went wrong with that request. Please try again.