module Cuhaml::Contrib::ContentFor

Public Class Methods

setup(app) click to toggle source
# File lib/cuhaml/contrib/content_for.rb, line 6
def self.setup(app)
  app.settings[:render][:template_engine] = "haml"
end

Public Instance Methods

content_for(symbol, &block) click to toggle source

Public: Sets the content for a given symbol

symbol - The symbol key &block - Block to be called

Examples:

<% content_for :menu do %>
  Home | Admin
<% end %>
# File lib/cuhaml/contrib/content_for.rb, line 31
def content_for(symbol, &block)
  content_blocks[symbol] << capture_haml(&block)
end
content_for?(symbol) click to toggle source

Public: return true if content has been provided for the given symbol, false otherwise

symbol - The symbol to be searched

Examples:

<% if content_for? :menu %>
<% end %>
# File lib/cuhaml/contrib/content_for.rb, line 43
def content_for?(symbol)
  !content_blocks[symbol].empty?
end
yield_for(symbol) click to toggle source

Public: yields content in a view

symbol - The symbol to be searched

Examples:

<% yield_for :menu %>
# File lib/cuhaml/contrib/content_for.rb, line 17
def yield_for(symbol)
  haml_concat(content_blocks[symbol].join)
end

Private Instance Methods

content_blocks() click to toggle source

Private: Hash of arrays to store content blocks

# File lib/cuhaml/contrib/content_for.rb, line 50
def content_blocks
  @content_blocks ||= Hash.new { |h, k| h[k] = [] }
end