2007-11-18 11:14:12 +00:00
|
|
|
if defined?(ActionView) and not defined?(Merb::Plugins)
|
2007-03-30 02:52:57 +00:00
|
|
|
module ActionView
|
2007-04-05 19:09:07 +00:00
|
|
|
class Base # :nodoc:
|
2007-09-07 09:13:03 +00:00
|
|
|
def render_with_haml(*args, &block)
|
2008-09-24 09:10:33 +00:00
|
|
|
options = args.first
|
|
|
|
|
|
|
|
# If render :layout is used with a block,
|
|
|
|
# it concats rather than returning a string
|
|
|
|
# so we need it to keep thinking it's Haml
|
|
|
|
# until it hits the sub-render
|
|
|
|
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
|
|
|
|
return non_haml { render_without_haml(*args, &block) }
|
|
|
|
end
|
2008-04-24 17:23:01 +00:00
|
|
|
render_without_haml(*args, &block)
|
2007-04-05 19:09:07 +00:00
|
|
|
end
|
2007-04-09 03:47:25 +00:00
|
|
|
alias_method :render_without_haml, :render
|
|
|
|
alias_method :render, :render_with_haml
|
2008-06-09 03:38:46 +00:00
|
|
|
|
|
|
|
# Rails >2.1
|
|
|
|
if instance_methods.include?('output_buffer')
|
|
|
|
def output_buffer_with_haml
|
|
|
|
return haml_buffer.buffer if is_haml?
|
|
|
|
output_buffer_without_haml
|
|
|
|
end
|
|
|
|
alias_method :output_buffer_without_haml, :output_buffer
|
|
|
|
alias_method :output_buffer, :output_buffer_with_haml
|
|
|
|
|
|
|
|
def set_output_buffer_with_haml(new)
|
|
|
|
if is_haml?
|
|
|
|
haml_buffer.buffer = new
|
|
|
|
else
|
|
|
|
set_output_buffer_without_haml new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
alias_method :set_output_buffer_without_haml, :output_buffer=
|
|
|
|
alias_method :output_buffer=, :set_output_buffer_with_haml
|
|
|
|
end
|
2007-04-05 19:09:07 +00:00
|
|
|
end
|
|
|
|
|
2007-03-30 02:52:57 +00:00
|
|
|
# This overrides various helpers in ActionView
|
|
|
|
# to make them work more effectively with Haml.
|
2006-11-14 18:35:02 +00:00
|
|
|
module Helpers
|
2007-03-31 23:21:16 +00:00
|
|
|
# :stopdoc:
|
2008-06-11 19:55:11 +00:00
|
|
|
# In Rails <=2.1, we've got to override considerable capturing infrastructure.
|
|
|
|
# In Rails >2.1, we can make do with only overriding #capture
|
|
|
|
# (which no longer behaves differently in helper contexts).
|
2008-06-09 03:38:46 +00:00
|
|
|
unless ActionView::Base.instance_methods.include?('output_buffer')
|
|
|
|
module CaptureHelper
|
|
|
|
def capture_with_haml(*args, &block)
|
|
|
|
# Rails' #capture helper will just return the value of the block
|
|
|
|
# if it's not actually in the template context,
|
|
|
|
# as detected by the existance of an _erbout variable.
|
|
|
|
# We've got to do the same thing for compatibility.
|
2008-05-12 00:32:41 +00:00
|
|
|
|
2008-11-25 05:23:58 +00:00
|
|
|
if is_haml? && block_is_haml?(block)
|
2008-06-09 03:38:46 +00:00
|
|
|
capture_haml(*args, &block)
|
|
|
|
else
|
|
|
|
capture_without_haml(*args, &block)
|
|
|
|
end
|
2008-03-15 21:14:12 +00:00
|
|
|
end
|
2008-06-09 03:38:46 +00:00
|
|
|
alias_method :capture_without_haml, :capture
|
|
|
|
alias_method :capture, :capture_with_haml
|
2008-03-15 21:14:12 +00:00
|
|
|
|
2008-10-02 18:14:55 +00:00
|
|
|
def capture_erb_with_buffer_with_haml(buffer, *args, &block)
|
2008-06-09 03:38:46 +00:00
|
|
|
if is_haml?
|
2008-10-02 18:14:55 +00:00
|
|
|
capture_haml(*args, &block)
|
2008-06-09 03:38:46 +00:00
|
|
|
else
|
2008-10-02 18:14:55 +00:00
|
|
|
capture_erb_with_buffer_without_haml(buffer, *args, &block)
|
2008-06-09 03:38:46 +00:00
|
|
|
end
|
2007-05-12 21:33:58 +00:00
|
|
|
end
|
2008-06-09 03:38:46 +00:00
|
|
|
alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer
|
|
|
|
alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml
|
2007-05-12 21:33:58 +00:00
|
|
|
end
|
|
|
|
|
2008-06-09 03:38:46 +00:00
|
|
|
module TextHelper
|
|
|
|
def concat_with_haml(string, binding = nil)
|
|
|
|
if is_haml?
|
|
|
|
haml_buffer.buffer.concat(string)
|
|
|
|
else
|
|
|
|
concat_without_haml(string, binding)
|
|
|
|
end
|
2007-01-24 17:35:06 +00:00
|
|
|
end
|
2008-06-09 03:38:46 +00:00
|
|
|
alias_method :concat_without_haml, :concat
|
|
|
|
alias_method :concat, :concat_with_haml
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
2008-06-11 19:55:11 +00:00
|
|
|
else
|
|
|
|
module CaptureHelper
|
|
|
|
def capture_with_haml(*args, &block)
|
2008-12-05 20:41:35 +00:00
|
|
|
if is_haml? && block_is_haml?(block)
|
2008-06-11 19:55:11 +00:00
|
|
|
capture_haml(*args, &block)
|
|
|
|
else
|
|
|
|
capture_without_haml(*args, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
alias_method :capture_without_haml, :capture
|
|
|
|
alias_method :capture, :capture_with_haml
|
|
|
|
end
|
2007-03-30 02:52:57 +00:00
|
|
|
end
|
|
|
|
|
2008-04-08 06:09:17 +00:00
|
|
|
module TagHelper
|
2008-11-25 05:23:58 +00:00
|
|
|
def content_tag_with_haml(name, *args, &block)
|
|
|
|
return content_tag_without_haml(name, *args, &block) unless is_haml?
|
2008-03-08 23:27:59 +00:00
|
|
|
|
2008-11-25 05:23:58 +00:00
|
|
|
preserve = haml_buffer.options[:preserve].include?(name.to_s)
|
2008-11-23 04:53:19 +00:00
|
|
|
|
2008-11-25 09:22:18 +00:00
|
|
|
if block_given? && block_is_haml?(block) && preserve
|
2008-11-25 05:23:58 +00:00
|
|
|
return content_tag_without_haml(name, *args) {preserve(&block)}
|
2008-03-08 23:27:59 +00:00
|
|
|
end
|
|
|
|
|
2008-11-25 05:23:58 +00:00
|
|
|
returning content_tag_without_haml(name, *args, &block) do |content|
|
|
|
|
return Haml::Helpers.preserve(content) if preserve && content
|
2008-11-23 04:53:19 +00:00
|
|
|
end
|
2008-03-03 00:12:57 +00:00
|
|
|
end
|
2008-11-23 04:53:19 +00:00
|
|
|
|
2008-03-03 00:12:57 +00:00
|
|
|
alias_method :content_tag_without_haml, :content_tag
|
|
|
|
alias_method :content_tag, :content_tag_with_haml
|
|
|
|
end
|
|
|
|
|
|
|
|
class InstanceTag
|
|
|
|
# Includes TagHelper
|
|
|
|
|
2008-03-03 00:24:47 +00:00
|
|
|
def haml_buffer
|
|
|
|
@template_object.send :haml_buffer
|
|
|
|
end
|
|
|
|
|
2008-03-08 23:27:59 +00:00
|
|
|
def is_haml?
|
|
|
|
@template_object.send :is_haml?
|
|
|
|
end
|
|
|
|
|
2008-03-03 00:12:57 +00:00
|
|
|
alias_method :content_tag_without_haml, :content_tag
|
|
|
|
alias_method :content_tag, :content_tag_with_haml
|
|
|
|
end
|
|
|
|
|
2007-03-30 02:52:57 +00:00
|
|
|
module FormTagHelper
|
2007-03-31 23:21:16 +00:00
|
|
|
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
|
2007-04-05 19:09:07 +00:00
|
|
|
if is_haml?
|
|
|
|
if block_given?
|
2007-11-26 23:01:58 +00:00
|
|
|
oldproc = proc
|
2008-02-23 02:40:26 +00:00
|
|
|
proc = haml_bind_proc do |*args|
|
2007-04-05 19:09:07 +00:00
|
|
|
concat "\n"
|
|
|
|
tab_up
|
|
|
|
oldproc.call(*args)
|
|
|
|
tab_down
|
|
|
|
end
|
2006-11-16 01:15:01 +00:00
|
|
|
end
|
2007-04-05 19:09:07 +00:00
|
|
|
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
|
|
|
concat "\n" if block_given? && is_haml?
|
|
|
|
res
|
|
|
|
else
|
|
|
|
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
|
2006-11-16 01:15:01 +00:00
|
|
|
end
|
2007-01-31 04:30:08 +00:00
|
|
|
end
|
2007-04-09 03:47:25 +00:00
|
|
|
alias_method :form_tag_without_haml, :form_tag
|
|
|
|
alias_method :form_tag, :form_tag_with_haml
|
2007-03-30 02:52:57 +00:00
|
|
|
end
|
2007-01-31 04:30:08 +00:00
|
|
|
|
2007-03-30 02:52:57 +00:00
|
|
|
module FormHelper
|
2007-03-31 23:21:16 +00:00
|
|
|
def form_for_with_haml(object_name, *args, &proc)
|
2007-01-31 04:30:08 +00:00
|
|
|
if block_given? && is_haml?
|
2008-04-08 06:09:17 +00:00
|
|
|
oldproc = proc
|
2008-02-23 02:40:26 +00:00
|
|
|
proc = haml_bind_proc do |*args|
|
2007-01-31 04:30:08 +00:00
|
|
|
tab_up
|
|
|
|
oldproc.call(*args)
|
|
|
|
tab_down
|
2007-03-14 16:00:08 +00:00
|
|
|
end
|
2007-01-31 04:30:08 +00:00
|
|
|
end
|
2007-03-30 02:52:57 +00:00
|
|
|
form_for_without_haml(object_name, *args, &proc)
|
2007-01-31 04:30:08 +00:00
|
|
|
concat "\n" if block_given? && is_haml?
|
2006-11-16 01:15:01 +00:00
|
|
|
end
|
2007-04-09 03:47:25 +00:00
|
|
|
alias_method :form_for_without_haml, :form_for
|
|
|
|
alias_method :form_for, :form_for_with_haml
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
2007-03-31 23:21:16 +00:00
|
|
|
# :startdoc:
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|