2006-11-14 18:35:02 +00:00
|
|
|
begin
|
2007-11-17 19:55:26 +00:00
|
|
|
raise LoadError if defined?(Merb::Plugins)
|
2006-11-14 18:35:02 +00:00
|
|
|
require 'rubygems'
|
|
|
|
require 'active_support'
|
2007-01-19 02:54:40 +00:00
|
|
|
require 'action_controller'
|
2006-11-14 18:35:02 +00:00
|
|
|
require 'action_view'
|
|
|
|
action_view_included = true
|
|
|
|
rescue LoadError
|
|
|
|
action_view_included = false
|
|
|
|
end
|
|
|
|
|
2007-03-30 02:52:57 +00:00
|
|
|
if action_view_included
|
|
|
|
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)
|
2007-04-05 19:09:07 +00:00
|
|
|
was_haml = is_haml?
|
|
|
|
@haml_is_haml = false
|
2007-09-07 09:13:03 +00:00
|
|
|
res = render_without_haml(*args, &block)
|
2007-04-05 19:09:07 +00:00
|
|
|
@haml_is_haml = was_haml
|
|
|
|
res
|
|
|
|
end
|
2007-04-09 03:47:25 +00:00
|
|
|
alias_method :render_without_haml, :render
|
|
|
|
alias_method :render, :render_with_haml
|
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:
|
2007-05-12 21:33:58 +00:00
|
|
|
module CaptureHelper
|
|
|
|
def capture_erb_with_buffer_with_haml(*args, &block)
|
|
|
|
if is_haml?
|
|
|
|
capture_haml_with_buffer(*args, &block)
|
|
|
|
else
|
|
|
|
capture_erb_with_buffer_without_haml(*args, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer
|
|
|
|
alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml
|
|
|
|
end
|
|
|
|
|
2007-03-30 02:52:57 +00:00
|
|
|
module TextHelper
|
2007-03-31 23:21:16 +00:00
|
|
|
def concat_with_haml(string, binding = nil)
|
2007-01-26 04:23:09 +00:00
|
|
|
if is_haml?
|
2007-01-24 17:35:06 +00:00
|
|
|
buffer.buffer.concat(string)
|
|
|
|
else
|
2007-03-30 02:52:57 +00:00
|
|
|
concat_without_haml(string, binding)
|
2007-01-24 17:35:06 +00:00
|
|
|
end
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
2007-04-09 03:47:25 +00:00
|
|
|
alias_method :concat_without_haml, :concat
|
|
|
|
alias_method :concat, :concat_with_haml
|
2007-03-30 02:52:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
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?
|
|
|
|
oldproc = proc
|
|
|
|
proc = bind_proc do |*args|
|
|
|
|
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?
|
|
|
|
oldproc = proc
|
|
|
|
proc = bind_proc do |*args|
|
|
|
|
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
|
|
|
|
|