Module: Ziya::HtmlHelpers::Base
Instance Method Summary collapse
-
#escape_chars ⇒ Object
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) if block_given? options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) content = capture_block(&block) content_tag = content_tag_string(name, content, options, escape) block_is_within_action_view?(block) ? concat(content_tag, block.binding) : content_tag else content = content_or_options_with_block content_tag_string(name, content, options, escape) end end def capture_block( *args, &block ) block.call(*args) end def content_tag_string(name, content, options, escape = true) tag_options = tag_options(options, escape) if options “<#name##tag_options>#content</#name>” end.
- #escape_once(html) ⇒ Object
-
#escape_url(url) ⇒ Object
escape url.
- #mime ⇒ Object
- #plugin_url ⇒ Object
-
#setup_movie_size(options) ⇒ Object
Check args for size option in the format wXy (Submitted by Sam Livingston-Gray).
-
#setup_wmode(options) ⇒ Object
Set the wmode to opaque if a bgcolor is specified.
-
#tag(name, options = nil, open = false, escape = true) ⇒ Object
# All this stolen form rails to make Ziya work with other fmks.…
- #tag_options(options, escape = true) ⇒ Object
Instance Method Details
#escape_chars ⇒ Object
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
if block_given?
= if .is_a?(Hash)
content = capture_block(&block)
content_tag = content_tag_string(name, content, , escape)
block_is_within_action_view?(block) ? concat(content_tag, block.binding) : content_tag
else
content =
content_tag_string(name, content, , escape)
end
end
def capture_block( *args, &block )
block.call(*args)
end
def content_tag_string(name, content, options, escape = true)
= (, escape) if
"<#{name}#{}>#{content}</#{name}>"
end
def block_is_within_action_view?(block)
eval("defined? _erbout", block.binding)
end
86 87 88 |
# File 'lib/ziya/html_helpers/base.rb', line 86 def escape_chars { '&' => '&', '"' => '"', '>' => '>', '<' => '<' } end |
#escape_once(html) ⇒ Object
40 41 42 |
# File 'lib/ziya/html_helpers/base.rb', line 40 def escape_once(html) html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| escape_chars[special] } end |
#escape_url(url) ⇒ Object
escape url
31 32 33 |
# File 'lib/ziya/html_helpers/base.rb', line 31 def escape_url( url ) url ? CGI.escape( url.gsub( /&/, '&' ) ) : url end |
#mime ⇒ Object
7 |
# File 'lib/ziya/html_helpers/base.rb', line 7 def mime() "application/x-shockwave-flash"; end |
#plugin_url ⇒ Object
8 |
# File 'lib/ziya/html_helpers/base.rb', line 8 def plugin_url() "http://www.macromedia.com/go/getflashplayer"; end |
#setup_movie_size(options) ⇒ Object
Check args for size option in the format wXy (Submitted by Sam Livingston-Gray)
22 23 24 25 26 27 28 |
# File 'lib/ziya/html_helpers/base.rb', line 22 def setup_movie_size( ) if [:size] =~ /(\d+)x(\d+)/ [:width] = $1 [:height] = $2 .delete :size end end |
#setup_wmode(options) ⇒ Object
Set the wmode to opaque if a bgcolor is specified. If not set to transparent mode unless user overrides it
12 13 14 15 16 17 18 19 |
# File 'lib/ziya/html_helpers/base.rb', line 12 def setup_wmode( ) if [:bgcolor] [:wmode] = "opaque" unless [:wmode] else [:wmode] = "transparent" unless [:wmode] [:bgcolor] = "#FFFFFF" end end |
#tag(name, options = nil, open = false, escape = true) ⇒ Object
# All this stolen form rails to make Ziya work with other fmks.…
36 37 38 |
# File 'lib/ziya/html_helpers/base.rb', line 36 def tag(name, = nil, open = false, escape = true) "<#{name}#{(, escape) if }" + (open ? ">" : " />") end |
#tag_options(options, escape = true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ziya/html_helpers/base.rb', line 44 def (, escape = true) unless ! or .empty? attrs = [] if escape .each do |key, value| next unless value key = key.to_s value = escape_once(value) attrs << %(#{key}="#{value}") end else attrs = .map { |key, value| %(#{key}="#{value}") } end " #{attrs.sort * ' '}" unless attrs.empty? end end |