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



61
62
63
# File 'lib/ziya/html_helpers/base.rb', line 61

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_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

#ziya_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 ziya_tag(name, options = nil, open = false, escape = true)
 "<#{name}#{tag_options(options, escape) if options}" + (open ? ">" : " />")
end