[Haml] Convert Haml::Helpers::ActionViewExtensions docs to YARD.
This commit is contained in:
parent
83b0fc8209
commit
f60d0f691e
|
@ -1,5 +1,7 @@
|
||||||
require 'haml/helpers/action_view_mods'
|
if defined?(ActionView)
|
||||||
require 'haml/helpers/action_view_extensions'
|
require 'haml/helpers/action_view_mods'
|
||||||
|
require 'haml/helpers/action_view_extensions'
|
||||||
|
end
|
||||||
|
|
||||||
module Haml
|
module Haml
|
||||||
# This module contains various helpful methods to make it easier to do various tasks.
|
# This module contains various helpful methods to make it easier to do various tasks.
|
||||||
|
|
|
@ -1,45 +1,40 @@
|
||||||
require 'haml/helpers/action_view_mods'
|
require 'haml/helpers/action_view_mods'
|
||||||
|
|
||||||
if defined?(ActionView)
|
module Haml
|
||||||
module Haml
|
module Helpers
|
||||||
module Helpers
|
# This module contains various useful helper methods
|
||||||
# This module contains various useful helper methods
|
# that either tie into ActionView or the rest of the ActionPack stack,
|
||||||
# that either tie into ActionView or the rest of the ActionPack stack,
|
# or are only useful in that context.
|
||||||
# or are only useful in that context.
|
# Thus, the methods defined here are only available
|
||||||
# Thus, the methods defined here are only available
|
# if ActionView is installed.
|
||||||
# if ActionView is installed.
|
module ActionViewExtensions
|
||||||
module ActionViewExtensions
|
# Returns a value for the "class" attribute
|
||||||
# Returns a value for the "class" attribute
|
# unique to this controller/action pair.
|
||||||
# unique to this controller/action pair.
|
# This can be used to target styles specifically at this action or controller.
|
||||||
# This can be used to target styles specifically at this action or controller.
|
# For example, if the current action were `EntryController#show`,
|
||||||
# For example, if the current action were EntryController#show,
|
#
|
||||||
#
|
# %div{:class => page_class} My Div
|
||||||
# %div{:class => page_class} My Div
|
#
|
||||||
#
|
# would become
|
||||||
# would become
|
#
|
||||||
#
|
# <div class="entry show">My Div</div>
|
||||||
# <div class="entry show">My Div</div>
|
#
|
||||||
#
|
# Then, in a stylesheet (shown here as {Sass}),
|
||||||
# Then, in a stylesheet
|
# you could refer to this specific action:
|
||||||
# (shown here as Sass),
|
#
|
||||||
# you could refer to this specific action:
|
# .entry.show
|
||||||
#
|
# :font-weight bold
|
||||||
# .entry.show
|
#
|
||||||
# :font-weight bold
|
# or to all actions in the entry controller:
|
||||||
#
|
#
|
||||||
# or to all actions in the entry controller:
|
# .entry
|
||||||
#
|
# :color #00f
|
||||||
# .entry
|
#
|
||||||
# :color #00f
|
# @return [String] The class name for the current page
|
||||||
#
|
def page_class
|
||||||
def page_class
|
controller.controller_name + " " + controller.action_name
|
||||||
controller.controller_name + " " + controller.action_name
|
|
||||||
end
|
|
||||||
|
|
||||||
# :stopdoc:
|
|
||||||
alias_method :generate_content_class_names, :page_class
|
|
||||||
# :startdoc:
|
|
||||||
end
|
end
|
||||||
|
alias_method :generate_content_class_names, :page_class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,163 +1,139 @@
|
||||||
if defined?(ActionView) and not defined?(Merb::Plugins)
|
module ActionView
|
||||||
module ActionView
|
class Base
|
||||||
class Base
|
def render_with_haml(*args, &block)
|
||||||
def render_with_haml(*args, &block)
|
options = args.first
|
||||||
options = args.first
|
|
||||||
|
|
||||||
# If render :layout is used with a block,
|
# If render :layout is used with a block,
|
||||||
# it concats rather than returning a string
|
# it concats rather than returning a string
|
||||||
# so we need it to keep thinking it's Haml
|
# so we need it to keep thinking it's Haml
|
||||||
# until it hits the sub-render
|
# until it hits the sub-render
|
||||||
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
|
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
|
||||||
return non_haml { render_without_haml(*args, &block) }
|
return non_haml { render_without_haml(*args, &block) }
|
||||||
end
|
|
||||||
render_without_haml(*args, &block)
|
|
||||||
end
|
end
|
||||||
alias_method :render_without_haml, :render
|
render_without_haml(*args, &block)
|
||||||
alias_method :render, :render_with_haml
|
end
|
||||||
|
alias_method :render_without_haml, :render
|
||||||
|
alias_method :render, :render_with_haml
|
||||||
|
|
||||||
# Rails >2.1
|
# Rails >2.1
|
||||||
if Haml::Util.has?(:instance_method, self, :output_buffer)
|
if Haml::Util.has?(:instance_method, self, :output_buffer)
|
||||||
def output_buffer_with_haml
|
def output_buffer_with_haml
|
||||||
return haml_buffer.buffer if is_haml?
|
return haml_buffer.buffer if is_haml?
|
||||||
output_buffer_without_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 :output_buffer_without_haml, :output_buffer
|
end
|
||||||
alias_method :output_buffer, :output_buffer_with_haml
|
alias_method :set_output_buffer_without_haml, :output_buffer=
|
||||||
|
alias_method :output_buffer=, :set_output_buffer_with_haml
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def set_output_buffer_with_haml(new)
|
module Helpers
|
||||||
if is_haml?
|
# In Rails <=2.1, we've got to override considerable capturing infrastructure.
|
||||||
haml_buffer.buffer = new
|
# In Rails >2.1, we can make do with only overriding #capture
|
||||||
|
# (which no longer behaves differently in helper contexts).
|
||||||
|
unless Haml::Util.has?(:instance_method, ActionView::Base, :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.
|
||||||
|
|
||||||
|
if is_haml? && block_is_haml?(block)
|
||||||
|
capture_haml(*args, &block)
|
||||||
else
|
else
|
||||||
set_output_buffer_without_haml new
|
capture_without_haml(*args, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias_method :set_output_buffer_without_haml, :output_buffer=
|
alias_method :capture_without_haml, :capture
|
||||||
alias_method :output_buffer=, :set_output_buffer_with_haml
|
alias_method :capture, :capture_with_haml
|
||||||
|
|
||||||
|
def capture_erb_with_buffer_with_haml(buffer, *args, &block)
|
||||||
|
if is_haml?
|
||||||
|
capture_haml(*args, &block)
|
||||||
|
else
|
||||||
|
capture_erb_with_buffer_without_haml(buffer, *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
|
||||||
|
|
||||||
|
module TextHelper
|
||||||
|
def concat_with_haml(string, binding = nil)
|
||||||
|
if is_haml?
|
||||||
|
haml_buffer.buffer.concat(string)
|
||||||
|
else
|
||||||
|
concat_without_haml(string, binding)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
alias_method :concat_without_haml, :concat
|
||||||
|
alias_method :concat, :concat_with_haml
|
||||||
|
end
|
||||||
|
else
|
||||||
|
module CaptureHelper
|
||||||
|
def capture_with_haml(*args, &block)
|
||||||
|
if Haml::Helpers.block_is_haml?(block)
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
module TagHelper
|
||||||
# In Rails <=2.1, we've got to override considerable capturing infrastructure.
|
def content_tag_with_haml(name, *args, &block)
|
||||||
# In Rails >2.1, we can make do with only overriding #capture
|
return content_tag_without_haml(name, *args, &block) unless is_haml?
|
||||||
# (which no longer behaves differently in helper contexts).
|
|
||||||
unless Haml::Util.has?(:instance_method, ActionView::Base, :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.
|
|
||||||
|
|
||||||
if is_haml? && block_is_haml?(block)
|
preserve = haml_buffer.options[:preserve].include?(name.to_s)
|
||||||
capture_haml(*args, &block)
|
|
||||||
else
|
|
||||||
capture_without_haml(*args, &block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
alias_method :capture_without_haml, :capture
|
|
||||||
alias_method :capture, :capture_with_haml
|
|
||||||
|
|
||||||
def capture_erb_with_buffer_with_haml(buffer, *args, &block)
|
if block_given? && block_is_haml?(block) && preserve
|
||||||
if is_haml?
|
return content_tag_without_haml(name, *args) {preserve(&block)}
|
||||||
capture_haml(*args, &block)
|
|
||||||
else
|
|
||||||
capture_erb_with_buffer_without_haml(buffer, *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
|
end
|
||||||
|
|
||||||
module TextHelper
|
returning content_tag_without_haml(name, *args, &block) do |content|
|
||||||
def concat_with_haml(string, binding = nil)
|
return Haml::Helpers.preserve(content) if preserve && content
|
||||||
if is_haml?
|
|
||||||
haml_buffer.buffer.concat(string)
|
|
||||||
else
|
|
||||||
concat_without_haml(string, binding)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
alias_method :concat_without_haml, :concat
|
|
||||||
alias_method :concat, :concat_with_haml
|
|
||||||
end
|
|
||||||
else
|
|
||||||
module CaptureHelper
|
|
||||||
def capture_with_haml(*args, &block)
|
|
||||||
if Haml::Helpers.block_is_haml?(block)
|
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TagHelper
|
alias_method :content_tag_without_haml, :content_tag
|
||||||
def content_tag_with_haml(name, *args, &block)
|
alias_method :content_tag, :content_tag_with_haml
|
||||||
return content_tag_without_haml(name, *args, &block) unless is_haml?
|
end
|
||||||
|
|
||||||
preserve = haml_buffer.options[:preserve].include?(name.to_s)
|
class InstanceTag
|
||||||
|
# Includes TagHelper
|
||||||
|
|
||||||
if block_given? && block_is_haml?(block) && preserve
|
def haml_buffer
|
||||||
return content_tag_without_haml(name, *args) {preserve(&block)}
|
@template_object.send :haml_buffer
|
||||||
end
|
|
||||||
|
|
||||||
returning content_tag_without_haml(name, *args, &block) do |content|
|
|
||||||
return Haml::Helpers.preserve(content) if preserve && content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
alias_method :content_tag_without_haml, :content_tag
|
|
||||||
alias_method :content_tag, :content_tag_with_haml
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class InstanceTag
|
def is_haml?
|
||||||
# Includes TagHelper
|
@template_object.send :is_haml?
|
||||||
|
|
||||||
def haml_buffer
|
|
||||||
@template_object.send :haml_buffer
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_haml?
|
|
||||||
@template_object.send :is_haml?
|
|
||||||
end
|
|
||||||
|
|
||||||
alias_method :content_tag_without_haml, :content_tag
|
|
||||||
alias_method :content_tag, :content_tag_with_haml
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module FormTagHelper
|
alias_method :content_tag_without_haml, :content_tag
|
||||||
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
|
alias_method :content_tag, :content_tag_with_haml
|
||||||
if is_haml?
|
end
|
||||||
if block_given?
|
|
||||||
oldproc = proc
|
|
||||||
proc = haml_bind_proc do |*args|
|
|
||||||
concat "\n"
|
|
||||||
tab_up
|
|
||||||
oldproc.call(*args)
|
|
||||||
tab_down
|
|
||||||
concat haml_indent
|
|
||||||
end
|
|
||||||
concat haml_indent
|
|
||||||
end
|
|
||||||
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
|
||||||
concat "\n" if block_given?
|
|
||||||
res
|
|
||||||
else
|
|
||||||
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
alias_method :form_tag_without_haml, :form_tag
|
|
||||||
alias_method :form_tag, :form_tag_with_haml
|
|
||||||
end
|
|
||||||
|
|
||||||
module FormHelper
|
module FormTagHelper
|
||||||
def form_for_with_haml(object_name, *args, &proc)
|
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
|
||||||
if block_given? && is_haml?
|
if is_haml?
|
||||||
|
if block_given?
|
||||||
oldproc = proc
|
oldproc = proc
|
||||||
proc = haml_bind_proc do |*args|
|
proc = haml_bind_proc do |*args|
|
||||||
|
concat "\n"
|
||||||
tab_up
|
tab_up
|
||||||
oldproc.call(*args)
|
oldproc.call(*args)
|
||||||
tab_down
|
tab_down
|
||||||
|
@ -165,13 +141,34 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
|
||||||
end
|
end
|
||||||
concat haml_indent
|
concat haml_indent
|
||||||
end
|
end
|
||||||
form_for_without_haml(object_name, *args, &proc)
|
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
||||||
concat "\n" if block_given? && is_haml?
|
concat "\n" if block_given?
|
||||||
|
res
|
||||||
|
else
|
||||||
|
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
|
||||||
end
|
end
|
||||||
alias_method :form_for_without_haml, :form_for
|
|
||||||
alias_method :form_for, :form_for_with_haml
|
|
||||||
end
|
end
|
||||||
|
alias_method :form_tag_without_haml, :form_tag
|
||||||
|
alias_method :form_tag, :form_tag_with_haml
|
||||||
|
end
|
||||||
|
|
||||||
|
module FormHelper
|
||||||
|
def form_for_with_haml(object_name, *args, &proc)
|
||||||
|
if block_given? && is_haml?
|
||||||
|
oldproc = proc
|
||||||
|
proc = haml_bind_proc do |*args|
|
||||||
|
tab_up
|
||||||
|
oldproc.call(*args)
|
||||||
|
tab_down
|
||||||
|
concat haml_indent
|
||||||
|
end
|
||||||
|
concat haml_indent
|
||||||
|
end
|
||||||
|
form_for_without_haml(object_name, *args, &proc)
|
||||||
|
concat "\n" if block_given? && is_haml?
|
||||||
|
end
|
||||||
|
alias_method :form_for_without_haml, :form_for
|
||||||
|
alias_method :form_for, :form_for_with_haml
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue