Module: Ziya::Helper
- Included in:
- Components::Draw, Ziya::Helpers::BaseHelper
- Defined in:
- lib/ziya/ziya_helper.rb
Instance Method Summary collapse
- #block_is_within_action_view?(block) ⇒ Boolean
- #capture_block(*args, &block) ⇒ Object
- #chart_path ⇒ Object
- #charts_swf ⇒ Object
- #class_id ⇒ Object
- #codebase ⇒ Object
- #composite_url ⇒ Object
- #content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object
- #content_tag_string(name, content, options, escape = true) ⇒ Object
- #escape_chars ⇒ Object
- #escape_once(html) ⇒ Object
-
#escape_url(url) ⇒ Object
escape url.
- #gauge_path ⇒ Object
- #gauges_swf ⇒ Object
-
#gen_composite_path(swf_chart_dir, url) ⇒ Object
flash chart library path.
-
#gen_swf_path(path_directive, swf_dir, url) ⇒ Object
generates swf path.
-
#generate_flash_tag(url, swf_path, swf_file, options) ⇒ Object
generated the object and embed tag necessary for the flash movie.
- #generate_old_style_flash_tag(url, swf_path, options) ⇒ Object
-
#mime ⇒ Object
Const accessors…
- #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
setup up wmode 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
-
#ziya_chart(url, chart_options = {}) ⇒ Object
————————————————————————————- generates neccessary html tags to display a chart.
-
#ziya_chart_js(url, chart_options = {}) ⇒ Object
generates necessary object and embed tags to display a flash movie on various browsers using javascript.
-
#ziya_gauge(url, gauge_options = {}) ⇒ Object
————————————————————————- generates necessary html tags to display a gauge.
-
#ziya_javascript_include_tag ⇒ Object
————————————————————————- generates a javascript tag to include the js script to create object and embed tags.
Instance Method Details
#block_is_within_action_view?(block) ⇒ Boolean
366 367 368 |
# File 'lib/ziya/ziya_helper.rb', line 366 def block_is_within_action_view?(block) eval("defined? _erbout", block.binding) end |
#capture_block(*args, &block) ⇒ Object
357 358 359 |
# File 'lib/ziya/ziya_helper.rb', line 357 def capture_block( *args, &block ) block.call(*args) end |
#chart_path ⇒ Object
159 |
# File 'lib/ziya/ziya_helper.rb', line 159 def chart_path() "/charts"; end |
#charts_swf ⇒ Object
155 |
# File 'lib/ziya/ziya_helper.rb', line 155 def charts_swf() "library_path=%s/charts_library&xml_source=%s"; end |
#class_id ⇒ Object
160 |
# File 'lib/ziya/ziya_helper.rb', line 160 def class_id() "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" end |
#codebase ⇒ Object
161 |
# File 'lib/ziya/ziya_helper.rb', line 161 def codebase() "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0"; end |
#composite_url ⇒ Object
154 |
# File 'lib/ziya/ziya_helper.rb', line 154 def composite_url() "%s/charts.swf?library_path=%s/charts_library&xml_source=%s" end |
#content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/ziya/ziya_helper.rb', line 345 def content_tag(name, = nil, = 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 |
#content_tag_string(name, content, options, escape = true) ⇒ Object
361 362 363 364 |
# File 'lib/ziya/ziya_helper.rb', line 361 def content_tag_string(name, content, , escape = true) = (, escape) if "<#{name}#{}>#{content}</#{name}>" end |
#escape_chars ⇒ Object
370 371 372 |
# File 'lib/ziya/ziya_helper.rb', line 370 def escape_chars { '&' => '&', '"' => '"', '>' => '>', '<' => '<' } end |
#escape_once(html) ⇒ Object
324 325 326 |
# File 'lib/ziya/ziya_helper.rb', line 324 def escape_once(html) html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| escape_chars[special] } end |
#escape_url(url) ⇒ Object
escape url
294 295 296 |
# File 'lib/ziya/ziya_helper.rb', line 294 def escape_url( url ) CGI.escape( url.gsub( /&/, '&' ) ) end |
#gauge_path ⇒ Object
158 |
# File 'lib/ziya/ziya_helper.rb', line 158 def gauge_path() "/gauges"; end |
#gauges_swf ⇒ Object
157 |
# File 'lib/ziya/ziya_helper.rb', line 157 def gauges_swf() "%s/gauge.swf?xml_source=%s"; end |
#gen_composite_path(swf_chart_dir, url) ⇒ Object
flash chart library path
145 146 147 |
# File 'lib/ziya/ziya_helper.rb', line 145 def gen_composite_path( swf_chart_dir, url ) composite_url % [swf_chart_dir, swf_chart_dir, escape_url( url )] end |
#gen_swf_path(path_directive, swf_dir, url) ⇒ Object
generates swf path
164 165 166 |
# File 'lib/ziya/ziya_helper.rb', line 164 def gen_swf_path( path_directive, swf_dir, url ) path_directive % [swf_dir, escape_url( url )] end |
#generate_flash_tag(url, swf_path, swf_file, options) ⇒ Object
generated the object and embed tag necessary for the flash movie
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/ziya/ziya_helper.rb', line 218 def generate_flash_tag( url, swf_path, swf_file, ) # Setup options for opaque mode setup_wmode( ) # setup width and height setup_movie_size( ) color_param = tag( 'param', {:name => 'bgcolor', :value => [:bgcolor]}, true ) color_param += tag( 'param', {:name => "wmode", :value => [:wmode]}, true ) xml_swf_path = gen_swf_path( swf_path, [:swf_path], url ) xml_swf_path << "×tamp=#{Time.now.to_i}" if [:cache] == false xml_swf_path << "&timeout=#{[:timeout]}" if [:timeout] xml_swf_path << "&stage_width=#{[:width]}&stage_height=#{[:height]}" if [:use_stage] == true # if options[:tag_type] == "object" = <<-TAGS <object codebase="#{codebase}" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="#{[:id]}" height="#{[:height]}" width="#{[:width]}"> <param name="scale" value="noscale"> <param name="salign" value="#{[:salign]}"> <param name="bgcolor" value="#{[:bgcolor]}"> <param name="wmode" value="#{[:wmode]}"> <param name="movie" value="#{[:swf_path]}/#{swf_file}"> <param name="FlashVars" value="#{xml_swf_path}&chart_id=#{[:id]}"> <param name="menu" value="true"> <param name="allowFullScreen" value="true"> <param name="allowScriptAccess" value="sameDomain"> <param name="quality" value="high"> <param name="play" value="true"> <param name="devicefont" value="false"> <embed scale="noscale" allowfullscreen="true" allowscriptaccess="sameDomain" bgcolor="#{[:bgcolor]}" devicefont="false" flashvars="#{xml_swf_path}" menu="true" name="#{[:id]}" play="true" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" salign="#{[:salign]}" src="#{[:swf_path]}/#{swf_file}" type="application/x-shockwave-flash" wmode="#{[:wmode]}" align="#{[:align]}" height="#{[:height]}" width="#{[:width]}"/> </object> TAGS # else # tags = <<-TAGS # <embed scale="noscale" # allowfullscreen="true" # allowscriptaccess="sameDomain" # bgcolor="#{options[:bgcolor]}" # devicefont="false" # flashvars="#{xml_swf_path}" # menu="true" # name="#{options[:id]}" # play="true" # pluginspage="http://www.macromedia.com/go/getflashplayer" # quality="high" # salign="#{options[:salign]}" # src="#{options[:swf_path]}/#{swf_file}" # type="application/x-shockwave-flash" # wmode="#{options[:wmode]}" # align="#{options[:align]}" # height="#{options[:height]}" # width="#{options[:width]}"/> # TAGS # end end |
#generate_old_style_flash_tag(url, swf_path, options) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/ziya/ziya_helper.rb', line 168 def generate_old_style_flash_tag( url, swf_path, ) # Setup options for opaque mode setup_wmode( ) # setup width and height setup_movie_size( ) color_param = tag( 'param', {:name => 'bgcolor', :value => [:bgcolor]}, true ) color_param += tag( 'param', {:name => "wmode", :value => [:wmode]}, true ) xml_swf_path = swf_path % [[:swf_path], url] xml_swf_path << "×tamp=#{Time.now.to_i}" if [:use_cache] == true xml_swf_path << "&timeout=#{[:timeout]}&retry=#{[:retry]}" if [:timeout] == true xml_swf_path << "&stage_width=#{[:width]}&stage_height=#{[:height]}" if [:use_stage] == true = <<-TAGS <object codebase="#{codebase}" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="#{[:id]}" height="#{[:height]}" width="#{[:width]}"> <param name="scale" value="noscale"> <param name="align" value="#{[:align]}"> <param name="bgcolor" value="#{[:bgcolor]}"> <param name="wmode" value="#{[:wmode]}"> <param name="movie" value="#{xml_swf_path}"> <param name="menu" value="true"> <param name="allowFullScreen" value="true"> <param name="allowScriptAccess" value="sameDomain"> <param name="quality" value="high"> <param name="play" value="true"> <param name="devicefont" value="false"> <embed scale="noscale" allowfullscreen="true" allowscriptaccess="sameDomain" bgcolor="#{[:bgcolor]}" devicefont="false" src="#{xml_swf_path}" menu="true" name="#{[:id]}" play="true" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" salign="#{[:salign]}" src="#{xml_swf_path}" type="application/x-shockwave-flash" wmode="#{[:wmode]}" salign="#{[:salign]}" height="#{[:height]}" width="#{[:width]}"> </object> TAGS end |
#mime ⇒ Object
Const accessors…
153 |
# File 'lib/ziya/ziya_helper.rb', line 153 def mime() "application/x-shockwave-flash"; end |
#plugin_url ⇒ Object
156 |
# File 'lib/ziya/ziya_helper.rb', line 156 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)
311 312 313 314 315 316 317 |
# File 'lib/ziya/ziya_helper.rb', line 311 def setup_movie_size( ) if [:size] =~ /(\d+)x(\d+)/ [:width] = $1 [:height] = $2 .delete :size end end |
#setup_wmode(options) ⇒ Object
setup up wmode Set the wmode to opaque if a bgcolor is specified. If not set to transparent mode unless user overrides it
301 302 303 304 305 306 307 308 |
# File 'lib/ziya/ziya_helper.rb', line 301 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.…
320 321 322 |
# File 'lib/ziya/ziya_helper.rb', line 320 def tag(name, = nil, open = false, escape = true) "<#{name}#{(, escape) if }" + (open ? ">" : " />") end |
#tag_options(options, escape = true) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/ziya/ziya_helper.rb', line 328 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 |
#ziya_chart(url, chart_options = {}) ⇒ Object
generates neccessary html tags to display a chart.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ziya/ziya_helper.rb', line 126 def ziya_chart( url, = {} ) = { :width => "400", :height => "300", :tag_type => "embed", :align => "l", :salign => "tl", :scale => "noscale", :class => "", :id => "ziya_chart", :swf_path => chart_path, :use_cache => false, :timeout => nil, :use_stage => false }.merge!() generate_flash_tag( url, charts_swf, "charts.swf", ) end |
#ziya_chart_js(url, chart_options = {}) ⇒ Object
generates necessary object and embed tags to display a flash movie on various browsers using javascript
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ziya/ziya_helper.rb', line 34 def ziya_chart_js( url, ={} ) = { :width => "400", :height => "300", :bgcolor => "000000", :wmode => "opaque", :menu => true, :full_screen => true, :align => "l", :salign => "tl", :scale => "noscale", :use_cache => false, :timeout => nil, :retry => 2, :use_stage => false, :id => "ziya_chart", :swf_path => chart_path, }.merge!() # Setup options for opaque mode setup_wmode( ) # setup width and height setup_movie_size( ) xml_swf_path = charts_swf % [[:swf_path], escape_url(url)] xml_swf_path << "×tamp=#{Time.now.to_i}" if [:cache] == false xml_swf_path << "&timeout=#{[:timeout]}&retry=#{[:retry]}" if [:timeout] xml_swf_path << "&stage_width=#{[:width]}&stage_height=#{[:height]}" if [:use_stage] == true js = <<-JS <script language="javascript" type="text/javascript"> if (AC_FL_RunContent == 0 || DetectFlashVer == 0) { alert( "This page requires AC_RunActiveContent.js." ); } else { var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); if( hasRightVersion ) { AC_FL_RunContent( 'codebase' , 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0', 'width' , '#{[:width]}', 'height' , '#{[:height]}', 'scale' , '#{[:scale]}', 'salign' , '#{[:salign]}', 'bgcolor' , '#{[:bgcolor]}', 'wmode' , '#{[:wmode]}', 'movie' , '#{[:swf_path]}/charts', 'src' , '#{[:swf_path]}/charts', 'FlashVars' , '#{xml_swf_path}', 'id' , '#{[:id]}', 'name' , '#{[:id]}', 'menu' , '#{[:]}', 'allowFullScreen' , '#{[:full_screen]}', 'allowScriptAccess','sameDomain', 'quality' , 'high', 'align' , '#{[:align]}', 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer', 'play' , 'true', 'devicefont' , 'false' ); } else { var alternateContent = 'This content requires the Adobe Flash Player. ' + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.'; document.write(alternateContent); } } </script> JS end |
#ziya_gauge(url, gauge_options = {}) ⇒ Object
generates necessary html tags to display a gauge.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ziya/ziya_helper.rb', line 106 def ziya_gauge( url, ={} ) = { :width => "200", :height => "200", :align => "middle", :scale => "noscale", :salign => "", :class => "", :id => "ziya_gauge", :swf_path => gauge_path, :use_cache => false, :timeout => false, :retry => 2, :use_stage => false }.merge!() generate_old_style_flash_tag( url, gauges_swf, ) end |
#ziya_javascript_include_tag ⇒ Object
generates a javascript tag to include the js script to create object and embed tags
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ziya/ziya_helper.rb', line 17 def ziya_javascript_include_tag js = <<-JS <script language="javascript" type="text/javascript"> AC_FL_RunContent = 0; DetectFlashVer = 0; </script> <script src="/charts/AC_RunActiveContent.js" language="javascript"></script> <script language="javascript" type="text/javascript"> var requiredMajorVersion = 9; var requiredMinorVersion = 0; var requiredRevision = 45; </script> JS end |