Module: Ziya::HtmlHelpers::Base

Included in:
Charts, Gauges, Maps
Defined in:
lib/ziya/html_helpers/base.rb

Instance Method Summary collapse

Instance Method Details

#escape_charsObject

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)
   = (name, content, options, escape)
  block_is_within_action_view?(block) ? concat(, block.binding) : 
else
  content = content_or_options_with_block
  (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

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 
  { '&' => '&amp;', '"' => '&quot;', '>' => '&gt;', '<' => '&lt;' }
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( /&amp;/, '&' ) ) : url
end

#mimeObject



7
# File 'lib/ziya/html_helpers/base.rb', line 7

def mime()        "application/x-shockwave-flash"; end

#plugin_urlObject



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( options )
  if options[:size] =~ /(\d+)x(\d+)/
    options[:width]  = $1
    options[:height] = $2
    options.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( options )
  if options[:bgcolor]
    options[:wmode] = "opaque" unless options[:wmode]
  else
    options[:wmode]   = "transparent" unless options[:wmode]
    options[: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, options = nil, open = false, escape = true)
 "<#{name}#{tag_options(options, escape) if options}" + (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 tag_options(options, escape = true)
  unless !options or options.empty?
    attrs = []
    if escape
      options.each do |key, value|
        next unless value
        key = key.to_s
        value = escape_once(value)
        attrs << %(#{key}="#{value}")
      end
    else
      attrs = options.map { |key, value| %(#{key}="#{value}") }
    end
    " #{attrs.sort * ' '}" unless attrs.empty?
  end
end