2006-11-14 18:35:02 +00:00
|
|
|
begin
|
|
|
|
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
|
|
|
|
|
|
|
|
if action_view_included
|
|
|
|
class ActionView::Base
|
|
|
|
alias_method :old_concat, :concat unless instance_methods.include? "old_concat"
|
2006-11-16 01:15:01 +00:00
|
|
|
alias_method :old_form_tag, :form_tag unless instance_methods.include? "old_form_tag"
|
2007-01-31 04:30:08 +00:00
|
|
|
|
|
|
|
alias_method :old_form_for, :form_for unless instance_methods.include? "old_form_for"
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module Haml
|
|
|
|
module Helpers
|
2007-03-01 06:13:15 +00:00
|
|
|
# This module overrides various helpers in ActionView
|
|
|
|
# to make them work more effectively with Haml.
|
|
|
|
# It also defines several helper methods,
|
|
|
|
# available from a Haml template,
|
|
|
|
# which are only useful within the context of ActionView.
|
|
|
|
# It's not available unless ActionView is installed.
|
2006-11-21 05:54:26 +00:00
|
|
|
#
|
|
|
|
#--
|
|
|
|
# Methods in this module should be nodoc'd.
|
|
|
|
#++
|
2006-11-14 18:35:02 +00:00
|
|
|
module ActionViewMods
|
2006-11-21 05:54:26 +00:00
|
|
|
def self.included(othermod) # :nodoc:
|
2006-11-21 06:29:39 +00:00
|
|
|
othermod.class_eval do
|
|
|
|
action_view(true)
|
|
|
|
alias_method :capture_erb_with_buffer, :capture_haml_with_buffer
|
|
|
|
end
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
|
|
|
|
2006-11-21 05:54:26 +00:00
|
|
|
def concat(string, binding = nil) # :nodoc:
|
2007-01-26 04:23:09 +00:00
|
|
|
if is_haml?
|
2007-01-24 17:35:06 +00:00
|
|
|
buffer.buffer.concat(string)
|
|
|
|
else
|
|
|
|
old_concat(string, binding)
|
|
|
|
end
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
2006-11-16 01:15:01 +00:00
|
|
|
|
2006-11-21 05:54:26 +00:00
|
|
|
def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc) # :nodoc:
|
2007-01-26 04:23:09 +00:00
|
|
|
if block_given? && is_haml?
|
2006-11-16 01:15:01 +00:00
|
|
|
oldproc = proc
|
|
|
|
proc = bind_proc do |*args|
|
|
|
|
concat "\n"
|
|
|
|
tab_up
|
|
|
|
oldproc.call(*args)
|
|
|
|
tab_down
|
|
|
|
end
|
|
|
|
end
|
2007-01-31 04:30:08 +00:00
|
|
|
res = old_form_tag(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
|
|
|
concat "\n" if block_given? && is_haml?
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
2007-03-14 15:41:58 +00:00
|
|
|
# View accessor for the push_text helper
|
|
|
|
def push_text(text, tabulation = 0)
|
|
|
|
buffer.push_text(text, tabulation)
|
|
|
|
end
|
|
|
|
|
|
|
|
# open_tag helps you construct HTML in your helpers.
|
|
|
|
# It can be used this way
|
|
|
|
#
|
|
|
|
# open_tag :table do
|
|
|
|
# open_tag :tr do
|
|
|
|
# open_tag :td do
|
|
|
|
# push_text "data"
|
|
|
|
# end
|
|
|
|
# open_tag :td do
|
|
|
|
# push_text "more_data"
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# TODO: Make it output with better tabulation
|
|
|
|
def open_tag(named, &block)
|
|
|
|
push_text "<#{named}>"
|
|
|
|
tab_up
|
|
|
|
block.call
|
|
|
|
concat "\n"
|
|
|
|
tab_down
|
|
|
|
push_text "</#{named}>"
|
|
|
|
end
|
|
|
|
|
2007-03-01 06:13:15 +00:00
|
|
|
def form_for(object_name, *args, &proc) # :nodoc:
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
old_form_for(object_name, *args, &proc)
|
|
|
|
concat "\n" if block_given? && is_haml?
|
2006-11-16 01:15:01 +00:00
|
|
|
end
|
2007-02-08 15:37:02 +00:00
|
|
|
|
|
|
|
def generate_content_class_names
|
|
|
|
controller.controller_name + " " + controller.action_name
|
|
|
|
end
|
2006-11-14 18:35:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|