2006-11-14 18:35:02 +00:00
|
|
|
require File.dirname(__FILE__) + '/helpers/action_view_mods'
|
|
|
|
|
2006-09-12 04:14:21 +00:00
|
|
|
module Haml
|
2006-10-14 23:50:07 +00:00
|
|
|
# This module contains various helpful methods to make it easier to do
|
|
|
|
# various tasks. Haml::Helpers is automatically included in the context
|
|
|
|
# that a HAML template is parsed in, so all these methods are at your
|
|
|
|
# disposal from within the template.
|
2006-09-12 04:14:21 +00:00
|
|
|
module Helpers
|
2006-11-06 03:01:04 +00:00
|
|
|
self.extend self
|
2006-11-14 18:35:02 +00:00
|
|
|
|
|
|
|
@@action_view = false
|
|
|
|
@@force_no_action_view = false
|
|
|
|
|
|
|
|
# Returns whether or not ActionView is available.
|
|
|
|
def self.action_view?
|
|
|
|
@@action_view
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets whether or not ActionView is available.
|
|
|
|
def self.action_view(value) # :nodoc:
|
|
|
|
@@action_view = value
|
|
|
|
end
|
2006-11-06 03:01:04 +00:00
|
|
|
|
2006-10-14 23:50:07 +00:00
|
|
|
# Takes any string, finds all the endlines and converts them to
|
|
|
|
# html entities for endlines so they'll render correctly in
|
|
|
|
# whitespace-sensitive tags.
|
2006-09-12 04:14:21 +00:00
|
|
|
def flatten(input)
|
|
|
|
input.gsub(/\n/, '
').gsub(/\r/, '')
|
|
|
|
end
|
2006-07-31 14:28:44 +00:00
|
|
|
|
2006-10-14 23:50:07 +00:00
|
|
|
# Takes an array and a block and iterates the array,
|
|
|
|
# yielding each element to the block and putting the
|
|
|
|
# result into <tt>li</tt> elements, creating a list
|
|
|
|
# of the results of the block. For example:
|
2006-09-19 14:13:49 +00:00
|
|
|
#
|
|
|
|
# For instance:
|
|
|
|
# list_of([['hello'], ['yall']]) { |i| i[0] }
|
|
|
|
# or
|
|
|
|
# list_of(['hello', 'yall'])
|
|
|
|
#
|
|
|
|
# Produces:
|
|
|
|
# <li>hello</li>
|
|
|
|
# <li>yall</li>
|
|
|
|
#
|
2006-10-14 23:50:07 +00:00
|
|
|
def list_of(array) # :yields: item
|
2006-09-19 14:13:49 +00:00
|
|
|
(array.collect { |i| "<li>#{yield(i)}</li>" }).join("\n")
|
|
|
|
end
|
2006-11-08 03:27:37 +00:00
|
|
|
|
|
|
|
# Increments the tabulation modifier of the buffer. This is the
|
|
|
|
# number of tabs the buffer automatically adds to the lines of the
|
|
|
|
# template.
|
|
|
|
def tab_up(i = 1)
|
|
|
|
buffer.tabulation += i
|
|
|
|
end
|
|
|
|
|
|
|
|
# Decrements the tabulation modifier of the buffer. This is the
|
|
|
|
# number of tabs the buffer automatically adds to the lines of the
|
|
|
|
# template.
|
|
|
|
def tab_down(i = 1)
|
|
|
|
buffer.tabulation -= i
|
|
|
|
end
|
|
|
|
|
|
|
|
# Gets a reference to the current Haml::Buffer object.
|
|
|
|
def buffer # :nodoc:
|
|
|
|
@haml_stack[-1]
|
|
|
|
end
|
2006-11-14 18:35:02 +00:00
|
|
|
|
2006-11-16 01:15:01 +00:00
|
|
|
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
|
|
|
# that the current template has.
|
|
|
|
def bind_proc(&proc)
|
|
|
|
_hamlout = buffer
|
|
|
|
_erbout = _hamlout.buffer
|
|
|
|
proc { |*args| proc.call(*args) }
|
|
|
|
end
|
|
|
|
|
2006-11-14 18:35:02 +00:00
|
|
|
include ActionViewMods if self.const_defined? "ActionViewMods"
|
2006-08-08 21:38:50 +00:00
|
|
|
end
|
2006-07-31 14:28:44 +00:00
|
|
|
end
|