module Haml::RailsHelpers

Constants

DEFAULT_PRESERVE_TAGS

Public Instance Methods

capture_haml(*args, &block) click to toggle source
# File lib/haml/rails_helpers.rb, line 49
def capture_haml(*args, &block)
  capture(*args, &block)
end
find_and_preserve(input = nil, tags = DEFAULT_PRESERVE_TAGS, &block) click to toggle source
# File lib/haml/rails_helpers.rb, line 12
def find_and_preserve(input = nil, tags = DEFAULT_PRESERVE_TAGS, &block)
  return find_and_preserve(capture_haml(&block), input || tags) if block

  tags = tags.each_with_object('') do |t, s|
    s << '|' unless s.empty?
    s << Regexp.escape(t)
  end

  re = /<(#{tags})([^>]*)>(.*?)(<\/\1>)/im
  input.to_s.gsub(re) do |s|
    s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
    "<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
  end
end
precede(str, &block) click to toggle source
# File lib/haml/rails_helpers.rb, line 39
def precede(str, &block)
  str = escape_once(str) unless str.html_safe?
  "#{str}#{capture_haml(&block).chomp}\n".html_safe
end
preserve(input = nil, &block) click to toggle source
Calls superclass method Haml::Helpers::preserve
# File lib/haml/rails_helpers.rb, line 27
def preserve(input = nil, &block)
  return preserve(capture_haml(&block)) if block
  super.html_safe
end
succeed(str, &block) click to toggle source
# File lib/haml/rails_helpers.rb, line 44
def succeed(str, &block)
  str = escape_once(str) unless str.html_safe?
  "#{capture_haml(&block).chomp}#{str}\n".html_safe
end
surround(front, back = front, &block) click to toggle source
# File lib/haml/rails_helpers.rb, line 32
def surround(front, back = front, &block)
  output = capture_haml(&block)
  front  = escape_once(front) unless front.html_safe?
  back   = escape_once(back)  unless back.html_safe?
  "#{front}#{output.chomp}#{back}\n".html_safe
end