derailed-ziya 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +405 -0
- data/README.txt +232 -0
- data/Rakefile +44 -0
- data/bin/ziyafy +53 -0
- data/charts/AC_RunActiveContent.js +292 -0
- data/charts/charts.swf +0 -0
- data/charts/charts_library/ar3d.swf +0 -0
- data/charts/charts_library/arno.swf +0 -0
- data/charts/charts_library/ars3.swf +0 -0
- data/charts/charts_library/arst.swf +0 -0
- data/charts/charts_library/brfl.swf +0 -0
- data/charts/charts_library/brno.swf +0 -0
- data/charts/charts_library/brst.swf +0 -0
- data/charts/charts_library/buno.swf +0 -0
- data/charts/charts_library/cl3d.swf +0 -0
- data/charts/charts_library/clfl.swf +0 -0
- data/charts/charts_library/clno.swf +0 -0
- data/charts/charts_library/clp3.swf +0 -0
- data/charts/charts_library/cls3.swf +0 -0
- data/charts/charts_library/clst.swf +0 -0
- data/charts/charts_library/cnno.swf +0 -0
- data/charts/charts_library/dono.swf +0 -0
- data/charts/charts_library/lnno.swf +0 -0
- data/charts/charts_library/mxno.swf +0 -0
- data/charts/charts_library/pi3d.swf +0 -0
- data/charts/charts_library/pino.swf +0 -0
- data/charts/charts_library/pono.swf +0 -0
- data/charts/charts_library/scno.swf +0 -0
- data/charts/full_screen.swf +0 -0
- data/charts/scripts/output_jpg.php +23 -0
- data/charts/sliders/black.swf +0 -0
- data/charts/sliders/preview_handle_1.swf +0 -0
- data/charts/sliders/preview_handle_2.swf +0 -0
- data/gauges/designs/circle.yml +18 -0
- data/gauges/designs/signal.yml +14 -0
- data/gauges/designs/thermo.yml +119 -0
- data/gauges/designs/title.yml +11 -0
- data/gauges/gauge.swf +0 -0
- data/lib/ziya/charts/area.rb +18 -0
- data/lib/ziya/charts/area_threed.rb +16 -0
- data/lib/ziya/charts/bar.rb +16 -0
- data/lib/ziya/charts/base.rb +510 -0
- data/lib/ziya/charts/bubble.rb +18 -0
- data/lib/ziya/charts/candle_stick.rb +16 -0
- data/lib/ziya/charts/column.rb +16 -0
- data/lib/ziya/charts/column_threed.rb +16 -0
- data/lib/ziya/charts/donut.rb +18 -0
- data/lib/ziya/charts/floating_bar.rb +16 -0
- data/lib/ziya/charts/floating_column.rb +16 -0
- data/lib/ziya/charts/line.rb +16 -0
- data/lib/ziya/charts/mixed.rb +16 -0
- data/lib/ziya/charts/parallel_threed_column.rb +16 -0
- data/lib/ziya/charts/pie.rb +16 -0
- data/lib/ziya/charts/pie_threed.rb +16 -0
- data/lib/ziya/charts/polar.rb +16 -0
- data/lib/ziya/charts/scatter.rb +16 -0
- data/lib/ziya/charts/stacked_area.rb +16 -0
- data/lib/ziya/charts/stacked_bar.rb +16 -0
- data/lib/ziya/charts/stacked_column.rb +16 -0
- data/lib/ziya/charts/stacked_threed_area.rb +16 -0
- data/lib/ziya/charts/stacked_threed_column.rb +16 -0
- data/lib/ziya/components/area.rb +17 -0
- data/lib/ziya/components/axis_category.rb +17 -0
- data/lib/ziya/components/axis_ticks.rb +35 -0
- data/lib/ziya/components/axis_value.rb +16 -0
- data/lib/ziya/components/base.rb +142 -0
- data/lib/ziya/components/bevel.rb +15 -0
- data/lib/ziya/components/blur.rb +13 -0
- data/lib/ziya/components/chart_border.rb +14 -0
- data/lib/ziya/components/chart_grid_h.rb +26 -0
- data/lib/ziya/components/chart_grid_v.rb +27 -0
- data/lib/ziya/components/chart_guide.rb +16 -0
- data/lib/ziya/components/chart_label.rb +16 -0
- data/lib/ziya/components/chart_pref.rb +22 -0
- data/lib/ziya/components/chart_rect.rb +37 -0
- data/lib/ziya/components/chart_transition.rb +25 -0
- data/lib/ziya/components/circle.rb +16 -0
- data/lib/ziya/components/context_menu.rb +15 -0
- data/lib/ziya/components/draw.rb +47 -0
- data/lib/ziya/components/draw_base.rb +10 -0
- data/lib/ziya/components/filter.rb +26 -0
- data/lib/ziya/components/glow.rb +14 -0
- data/lib/ziya/components/image.rb +17 -0
- data/lib/ziya/components/legend.rb +18 -0
- data/lib/ziya/components/line.rb +16 -0
- data/lib/ziya/components/link.rb +29 -0
- data/lib/ziya/components/link_data.rb +18 -0
- data/lib/ziya/components/rect.rb +18 -0
- data/lib/ziya/components/scroll.rb +26 -0
- data/lib/ziya/components/series.rb +16 -0
- data/lib/ziya/components/series_color.rb +35 -0
- data/lib/ziya/components/series_explode.rb +38 -0
- data/lib/ziya/components/shadow.rb +14 -0
- data/lib/ziya/components/text.rb +17 -0
- data/lib/ziya/components/update.rb +19 -0
- data/lib/ziya/gauges/base.rb +172 -0
- data/lib/ziya/gauges/radial.rb +18 -0
- data/lib/ziya/gauges/signal.rb +138 -0
- data/lib/ziya/gauges/support/area.rb +13 -0
- data/lib/ziya/gauges/support/base.rb +33 -0
- data/lib/ziya/gauges/support/circle.rb +14 -0
- data/lib/ziya/gauges/support/design.rb +5 -0
- data/lib/ziya/gauges/support/image.rb +12 -0
- data/lib/ziya/gauges/support/line.rb +12 -0
- data/lib/ziya/gauges/support/link.rb +24 -0
- data/lib/ziya/gauges/support/move.rb +15 -0
- data/lib/ziya/gauges/support/point.rb +12 -0
- data/lib/ziya/gauges/support/polygon.rb +13 -0
- data/lib/ziya/gauges/support/radial_base.rb +21 -0
- data/lib/ziya/gauges/support/radial_numbers.rb +41 -0
- data/lib/ziya/gauges/support/radial_ticks.rb +29 -0
- data/lib/ziya/gauges/support/rect.rb +14 -0
- data/lib/ziya/gauges/support/rotate.rb +15 -0
- data/lib/ziya/gauges/support/scale.rb +15 -0
- data/lib/ziya/gauges/support/text.rb +21 -0
- data/lib/ziya/gauges/support/update.rb +12 -0
- data/lib/ziya/gauges/thermo.rb +121 -0
- data/lib/ziya/helpers/base_helper.rb +70 -0
- data/lib/ziya/utils/logger.rb +125 -0
- data/lib/ziya/utils/text.rb +39 -0
- data/lib/ziya/version.rb +15 -0
- data/lib/ziya/ziya_helper.rb +374 -0
- data/lib/ziya.rb +112 -0
- data/spec/charts/base_spec.rb +134 -0
- data/spec/charts/chart_type_spec.rb +63 -0
- data/spec/components/area_spec.rb +67 -0
- data/spec/components/draw_spec.rb +32 -0
- data/spec/components/filter_spec.rb +27 -0
- data/spec/components/link_spec.rb +22 -0
- data/spec/components/series.rb +18 -0
- data/spec/components/series_color_spec.rb +39 -0
- data/spec/components/series_explode.rb +39 -0
- data/spec/components/series_explode_spec.rb +39 -0
- data/spec/designs/circle.yml +7 -0
- data/spec/designs/crapping_out.yml +8 -0
- data/spec/designs/gauge_1.yml +43 -0
- data/spec/designs/gauge_2.yml +11 -0
- data/spec/designs/gauge_no_name.yml +43 -0
- data/spec/designs/gauge_raw.yml +5 -0
- data/spec/designs/thermo.yml +13 -0
- data/spec/gauges/base_spec.rb +90 -0
- data/spec/gauges/signal_spec.rb +36 -0
- data/spec/gauges/support/area_spec.rb +40 -0
- data/spec/gauges/support/circle_spec.rb +78 -0
- data/spec/gauges/support/image_spec.rb +35 -0
- data/spec/gauges/support/line_spec.rb +34 -0
- data/spec/gauges/support/link_spec.rb +35 -0
- data/spec/gauges/support/move_spec.rb +45 -0
- data/spec/gauges/support/polygon_spec.rb +36 -0
- data/spec/gauges/support/radial_numbers_spec.rb +35 -0
- data/spec/gauges/support/radial_ticks_spec.rb +30 -0
- data/spec/gauges/support/rotate_spec.rb +45 -0
- data/spec/gauges/support/scale_spec.rb +46 -0
- data/spec/gauges/support/text_spec.rb +40 -0
- data/spec/gauges/thermo_spec.rb +49 -0
- data/spec/helpers/base_helper_spec.rb +36 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/test_helpers/gauge_2_helper.rb +17 -0
- data/spec/themes/default/fred.yml +6 -0
- data/spec/themes/default/line_chart.yml +6 -0
- data/spec/utils/logger_spec.rb +55 -0
- data/spec/utils/text_spec.rb +33 -0
- data/spec/ziya_helper_spec.rb +117 -0
- data/spec/ziya_spec.rb +19 -0
- data/tasks/ann.rake +76 -0
- data/tasks/annotations.rake +22 -0
- data/tasks/doc.rake +48 -0
- data/tasks/gem.rake +110 -0
- data/tasks/manifest.rake +49 -0
- data/tasks/post_load.rake +26 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +227 -0
- data/tasks/spec.rake +61 -0
- data/tasks/svn.rake +44 -0
- data/tasks/test.rake +38 -0
- metadata +468 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# Ziya default logger if none is given
|
3
|
+
#
|
4
|
+
# -----------------------------------------------------------------------------
|
5
|
+
require 'logging'
|
6
|
+
require 'forwardable'
|
7
|
+
|
8
|
+
module Ziya
|
9
|
+
class Logger
|
10
|
+
class ConfigurationError < StandardError ; end #:nodoc:
|
11
|
+
|
12
|
+
attr_reader :log # here for testing, don't really use it.
|
13
|
+
|
14
|
+
extend Forwardable
|
15
|
+
def_delegators :@log, :debug, :warn, :info, :error, :fatal
|
16
|
+
def_delegators :@log, :level=, :level
|
17
|
+
def_delegators :@log, :debug?, :warn?, :info?, :error?, :fatal?
|
18
|
+
def_delegators :@log, :add, :clear_appenders
|
19
|
+
|
20
|
+
# there are more options here than are typically utilized for the
|
21
|
+
# logger, they are made available if someone wants to utilize
|
22
|
+
# them directly.
|
23
|
+
#
|
24
|
+
def self.default_options #:nodoc:
|
25
|
+
@default_options ||= {
|
26
|
+
|
27
|
+
# log event layout pattern
|
28
|
+
# YYYY-MM-DDTHH:MM:SS 12345 LEVEL LoggerName : The Log message
|
29
|
+
#
|
30
|
+
:layout_pattern => '%d %5p %5l %c : %m\n'.freeze ,
|
31
|
+
:logger_name => 'ZiYa' ,
|
32
|
+
:additive => true ,
|
33
|
+
|
34
|
+
# log file configuration options
|
35
|
+
# age -> how often to rotate the logs if a file is used
|
36
|
+
# keep_count -> how many of the log files to keep
|
37
|
+
:log_level => :info ,
|
38
|
+
:log_file => $stdout ,
|
39
|
+
:log_file_age => 'daily'.freeze ,
|
40
|
+
:log_file_keep_count => 7 ,
|
41
|
+
|
42
|
+
# email logging options
|
43
|
+
# buffsize -> number of log events used as a threshold to send an
|
44
|
+
# email. If that is not reached before the program
|
45
|
+
# exists then the at_exit handler for logging will flush
|
46
|
+
# the log to smtp.
|
47
|
+
:email_alerts_to => nil ,
|
48
|
+
:email_alert_level => :error ,
|
49
|
+
:email_alert_server => nil ,
|
50
|
+
:email_alert_buffsize => 200 ,
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# create a new logger
|
55
|
+
#
|
56
|
+
def initialize( opts = {} )
|
57
|
+
@options = ::Ziya::Logger.default_options.merge(opts)
|
58
|
+
@log = ::Logging::Logger[@options[:logger_name]]
|
59
|
+
@layout = ::Logging::Layouts::Pattern.new( { :pattern => @options[:layout_pattern] } )
|
60
|
+
|
61
|
+
# add appenders explicitly, since this logger may already be defined and
|
62
|
+
# already have loggers
|
63
|
+
@appenders = []
|
64
|
+
@appenders << log_file_appender if @options[:log_file]
|
65
|
+
@appenders << email_appender if @options[:email_alerts_to]
|
66
|
+
|
67
|
+
@log.appenders = @appenders
|
68
|
+
@log.level = @options[:log_level]
|
69
|
+
@log.additive = @options[:additive]
|
70
|
+
end
|
71
|
+
|
72
|
+
# File appender, this is either an IO appender or a RollingFile appender
|
73
|
+
# depending on if an IO object or a String is passed in.
|
74
|
+
#
|
75
|
+
# a configuration error is raised in any other circumstance
|
76
|
+
def log_file_appender #:nodoc:
|
77
|
+
appender_name = "#{@log.name}-log_file_appender"
|
78
|
+
if String === @options[:log_file] then
|
79
|
+
::Logging::Appenders::RollingFile.new( appender_name,
|
80
|
+
{ :layout => @layout,
|
81
|
+
:filename => @options[:log_file],
|
82
|
+
:age => @options[:log_file_age],
|
83
|
+
:keep => @options[:log_file_keep_count],
|
84
|
+
:safe => true # make sure log files are rolled using lockfile
|
85
|
+
})
|
86
|
+
elsif @options[:log_file].respond_to?(:print) then
|
87
|
+
::Logging::Appenders::IO.new( appender_name, @options[:log_file], :layout => @layout )
|
88
|
+
else
|
89
|
+
raise ConfigurationError, "Invalid :log_file option [#{@options[:log_file].inspect}]"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# an email appender that uses :email_alerts_to option to send emails to.
|
94
|
+
# :email_alerts_to can either be a singe email address as a string or an
|
95
|
+
# Array of email addresses. Any other option for :email_alerts_to is
|
96
|
+
# invalid and raises an error.
|
97
|
+
#
|
98
|
+
def email_appender #:nodoc:
|
99
|
+
email_alerts_to = [ @options[:email_alerts_to] ].flatten.reject { |x| x == nil }
|
100
|
+
raise ConfigurationError, "Invalid :email_alerts_to option [#{@options[:email_alerts_to].inspect}]" unless email_alerts_to.size > 0
|
101
|
+
::Logging::Appenders::Email.new("#{@log.name}-email_appender",
|
102
|
+
{
|
103
|
+
:level => @options[:email_alert_level],
|
104
|
+
:layout => @layout,
|
105
|
+
:from => "#{@log.name}",
|
106
|
+
:to => "#{email_alerts_to.join(', ')}",
|
107
|
+
:subject => "Logging Alert from #{@log.name} on #{ENV['HOSTNAME']}",
|
108
|
+
:server => @options[:email_alert_server],
|
109
|
+
:buffsize => @options[:email_alert_buffsize], # lines
|
110
|
+
})
|
111
|
+
end
|
112
|
+
|
113
|
+
# create a new logger thi logger has no options when it is created although
|
114
|
+
# more can be added with the logger instance that is returned. The
|
115
|
+
# appenders of the current instance of Logger will be set on the new
|
116
|
+
# logger and the options of the current logger will be applied
|
117
|
+
def for( arg ) #:nodoc:
|
118
|
+
new_logger = ::Logging::Logger[arg]
|
119
|
+
new_logger.level = @options[:level]
|
120
|
+
new_logger.additive = @options[:additive]
|
121
|
+
new_logger.appenders = @appenders
|
122
|
+
return new_logger
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# == Ziya::Utils::Text
|
3
|
+
#
|
4
|
+
# TODO !! Just make this a core extension to String already...
|
5
|
+
#
|
6
|
+
# Various text utils. Yes indeed lifted from Inflecto to remove Inflector
|
7
|
+
# dependencies...
|
8
|
+
#
|
9
|
+
# Author:: Fernand Galiana
|
10
|
+
# Date:: Dec 15th, 2006
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
module Ziya::Utils
|
13
|
+
module Text
|
14
|
+
# Pulled from the Rails Inflector class and modified slightly to fit our needs.
|
15
|
+
def camelize(string)
|
16
|
+
string.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Same as Rails Inflector but eliminating inflector dependency
|
20
|
+
def underscore(camel_cased_word)
|
21
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
22
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
23
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
24
|
+
tr("-", "_").
|
25
|
+
downcase
|
26
|
+
end
|
27
|
+
|
28
|
+
# Pulled from the Rails Inflector class and modified slightly to fit our needs.
|
29
|
+
def classify(string)
|
30
|
+
camelize(string.to_s.sub(/.*\./, ''))
|
31
|
+
end
|
32
|
+
|
33
|
+
# strip out module name and return bare class name
|
34
|
+
def demodulize( clazz )
|
35
|
+
clazz.gsub( /^.*::/, '' )
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/ziya/version.rb
ADDED
@@ -0,0 +1,374 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# Generates necessary html flash tag to support ZiYa
|
3
|
+
#
|
4
|
+
# TODO !! Rewrite to use content tag block instead...
|
5
|
+
#
|
6
|
+
# Author: Fernand Galiana
|
7
|
+
# -----------------------------------------------------------------------------
|
8
|
+
require 'cgi'
|
9
|
+
require 'erb'
|
10
|
+
|
11
|
+
module Ziya
|
12
|
+
module Helper
|
13
|
+
|
14
|
+
# -------------------------------------------------------------------------
|
15
|
+
# generates a javascript tag to include the js script to create object and
|
16
|
+
# embed tags
|
17
|
+
def ziya_javascript_include_tag
|
18
|
+
js = <<-JS
|
19
|
+
<script language="javascript" type="text/javascript">
|
20
|
+
AC_FL_RunContent = 0;
|
21
|
+
DetectFlashVer = 0;
|
22
|
+
</script>
|
23
|
+
<script src="/charts/AC_RunActiveContent.js" language="javascript"></script>
|
24
|
+
<script language="javascript" type="text/javascript">
|
25
|
+
var requiredMajorVersion = 9;
|
26
|
+
var requiredMinorVersion = 0;
|
27
|
+
var requiredRevision = 45;
|
28
|
+
</script>
|
29
|
+
JS
|
30
|
+
end
|
31
|
+
|
32
|
+
# generates necessary object and embed tags to display a flash movie on various
|
33
|
+
# browsers using javascript
|
34
|
+
def ziya_chart_js( url, chart_options={} )
|
35
|
+
options = { :width => "400",
|
36
|
+
:height => "300",
|
37
|
+
:bgcolor => "000000",
|
38
|
+
:wmode => "opaque",
|
39
|
+
:menu => true,
|
40
|
+
:full_screen => true,
|
41
|
+
:align => "l",
|
42
|
+
:salign => "tl",
|
43
|
+
:scale => "noscale",
|
44
|
+
:use_cache => false,
|
45
|
+
:timeout => nil,
|
46
|
+
:retry => 2,
|
47
|
+
:use_stage => false,
|
48
|
+
:id => "ziya_chart",
|
49
|
+
:swf_path => chart_path,
|
50
|
+
}.merge!(chart_options)
|
51
|
+
|
52
|
+
# Setup options for opaque mode
|
53
|
+
setup_wmode( options )
|
54
|
+
|
55
|
+
# setup width and height
|
56
|
+
setup_movie_size( options )
|
57
|
+
|
58
|
+
xml_swf_path = charts_swf % [options[:swf_path], escape_url(url)]
|
59
|
+
xml_swf_path << "×tamp=#{Time.now.to_i}" if options[:cache] == false
|
60
|
+
xml_swf_path << "&timeout=#{options[:timeout]}&retry=#{options[:retry]}" if options[:timeout]
|
61
|
+
xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
|
62
|
+
|
63
|
+
js = <<-JS
|
64
|
+
<script language="javascript" type="text/javascript">
|
65
|
+
if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
|
66
|
+
alert( "This page requires AC_RunActiveContent.js." );
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
|
70
|
+
if( hasRightVersion ) {
|
71
|
+
AC_FL_RunContent(
|
72
|
+
'codebase' , 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
|
73
|
+
'width' , '#{options[:width]}',
|
74
|
+
'height' , '#{options[:height]}',
|
75
|
+
'scale' , '#{options[:scale]}',
|
76
|
+
'salign' , '#{options[:salign]}',
|
77
|
+
'bgcolor' , '#{options[:bgcolor]}',
|
78
|
+
'wmode' , '#{options[:wmode]}',
|
79
|
+
'movie' , '#{options[:swf_path]}/charts',
|
80
|
+
'src' , '#{options[:swf_path]}/charts',
|
81
|
+
'FlashVars' , '#{xml_swf_path}',
|
82
|
+
'id' , '#{options[:id]}',
|
83
|
+
'name' , '#{options[:id]}',
|
84
|
+
'menu' , '#{options[:menu]}',
|
85
|
+
'allowFullScreen' , '#{options[:full_screen]}',
|
86
|
+
'allowScriptAccess','sameDomain',
|
87
|
+
'quality' , 'high',
|
88
|
+
'align' , '#{options[:align]}',
|
89
|
+
'pluginspage' , 'http://www.macromedia.com/go/getflashplayer',
|
90
|
+
'play' , 'true',
|
91
|
+
'devicefont' , 'false'
|
92
|
+
);
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
var alternateContent = 'This content requires the Adobe Flash Player. '
|
96
|
+
+ '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
|
97
|
+
document.write(alternateContent);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
</script>
|
101
|
+
JS
|
102
|
+
end
|
103
|
+
|
104
|
+
# -------------------------------------------------------------------------
|
105
|
+
# generates necessary html tags to display a gauge.
|
106
|
+
def ziya_gauge( url, gauge_options={} )
|
107
|
+
options = { :width => "200",
|
108
|
+
:height => "200",
|
109
|
+
:align => "middle",
|
110
|
+
:scale => "noscale",
|
111
|
+
:salign => "",
|
112
|
+
:class => "",
|
113
|
+
:id => "ziya_gauge",
|
114
|
+
:swf_path => gauge_path,
|
115
|
+
:use_cache => false,
|
116
|
+
:timeout => false,
|
117
|
+
:retry => 2,
|
118
|
+
:use_stage => false
|
119
|
+
}.merge!(gauge_options)
|
120
|
+
|
121
|
+
generate_old_style_flash_tag( url, gauges_swf, options )
|
122
|
+
end
|
123
|
+
|
124
|
+
# -------------------------------------------------------------------------------------
|
125
|
+
# generates neccessary html tags to display a chart.
|
126
|
+
def ziya_chart( url, chart_options = {} )
|
127
|
+
options = { :width => "400",
|
128
|
+
:height => "300",
|
129
|
+
:tag_type => "embed",
|
130
|
+
:align => "l",
|
131
|
+
:salign => "tl",
|
132
|
+
:scale => "noscale",
|
133
|
+
:class => "",
|
134
|
+
:id => "ziya_chart",
|
135
|
+
:swf_path => chart_path,
|
136
|
+
:use_cache => false,
|
137
|
+
:timeout => nil,
|
138
|
+
:use_stage => false
|
139
|
+
}.merge!(chart_options)
|
140
|
+
|
141
|
+
generate_flash_tag( url, charts_swf, "charts.swf", options )
|
142
|
+
end
|
143
|
+
|
144
|
+
# flash chart library path
|
145
|
+
def gen_composite_path( swf_chart_dir, url )
|
146
|
+
composite_url % [swf_chart_dir, swf_chart_dir, escape_url( url )]
|
147
|
+
end
|
148
|
+
|
149
|
+
# =========================================================================
|
150
|
+
# private
|
151
|
+
|
152
|
+
# Const accessors...
|
153
|
+
def mime() "application/x-shockwave-flash"; end
|
154
|
+
def composite_url() "%s/charts.swf?library_path=%s/charts_library&xml_source=%s" end
|
155
|
+
def charts_swf() "library_path=%s/charts_library&xml_source=%s"; end
|
156
|
+
def plugin_url() "http://www.macromedia.com/go/getflashplayer"; end
|
157
|
+
def gauges_swf() "%s/gauge.swf?xml_source=%s"; end
|
158
|
+
def gauge_path() "/gauges"; end
|
159
|
+
def chart_path() "/charts"; end
|
160
|
+
def class_id() "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" end
|
161
|
+
def codebase() "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0"; end
|
162
|
+
|
163
|
+
# generates swf path
|
164
|
+
def gen_swf_path( path_directive, swf_dir, url )
|
165
|
+
path_directive % [swf_dir, escape_url( url )]
|
166
|
+
end
|
167
|
+
|
168
|
+
def generate_old_style_flash_tag( url, swf_path, options )
|
169
|
+
# Setup options for opaque mode
|
170
|
+
setup_wmode( options )
|
171
|
+
|
172
|
+
# setup width and height
|
173
|
+
setup_movie_size( options )
|
174
|
+
|
175
|
+
color_param = tag( 'param', {:name => 'bgcolor', :value => options[:bgcolor]}, true )
|
176
|
+
color_param += tag( 'param', {:name => "wmode", :value => options[:wmode]}, true )
|
177
|
+
|
178
|
+
xml_swf_path = swf_path % [options[:swf_path], url]
|
179
|
+
xml_swf_path << "×tamp=#{Time.now.to_i}" if options[:use_cache] == true
|
180
|
+
xml_swf_path << "&timeout=#{options[:timeout]}&retry=#{options[:retry]}" if options[:timeout] == true
|
181
|
+
xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
|
182
|
+
tags = <<-TAGS
|
183
|
+
<object codebase="#{codebase}" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="#{options[:id]}" height="#{options[:height]}" width="#{options[:width]}">
|
184
|
+
<param name="scale" value="noscale">
|
185
|
+
<param name="align" value="#{options[:align]}">
|
186
|
+
<param name="bgcolor" value="#{options[:bgcolor]}">
|
187
|
+
<param name="wmode" value="#{options[:wmode]}">
|
188
|
+
<param name="movie" value="#{xml_swf_path}">
|
189
|
+
<param name="menu" value="true">
|
190
|
+
<param name="allowFullScreen" value="true">
|
191
|
+
<param name="allowScriptAccess" value="sameDomain">
|
192
|
+
<param name="quality" value="high">
|
193
|
+
<param name="play" value="true">
|
194
|
+
<param name="devicefont" value="false">
|
195
|
+
<embed scale="noscale"
|
196
|
+
allowfullscreen="true"
|
197
|
+
allowscriptaccess="sameDomain"
|
198
|
+
bgcolor="#{options[:bgcolor]}"
|
199
|
+
devicefont="false"
|
200
|
+
src="#{xml_swf_path}"
|
201
|
+
menu="true"
|
202
|
+
name="#{options[:id]}"
|
203
|
+
play="true"
|
204
|
+
pluginspage="http://www.macromedia.com/go/getflashplayer"
|
205
|
+
quality="high"
|
206
|
+
salign="#{options[:salign]}"
|
207
|
+
src="#{xml_swf_path}"
|
208
|
+
type="application/x-shockwave-flash"
|
209
|
+
wmode="#{options[:wmode]}"
|
210
|
+
salign="#{options[:salign]}"
|
211
|
+
height="#{options[:height]}"
|
212
|
+
width="#{options[:width]}">
|
213
|
+
</object>
|
214
|
+
TAGS
|
215
|
+
end
|
216
|
+
|
217
|
+
# generated the object and embed tag necessary for the flash movie
|
218
|
+
def generate_flash_tag( url, swf_path, swf_file, options )
|
219
|
+
# Setup options for opaque mode
|
220
|
+
setup_wmode( options )
|
221
|
+
|
222
|
+
# setup width and height
|
223
|
+
setup_movie_size( options )
|
224
|
+
|
225
|
+
color_param = tag( 'param', {:name => 'bgcolor', :value => options[:bgcolor]}, true )
|
226
|
+
color_param += tag( 'param', {:name => "wmode", :value => options[:wmode]}, true )
|
227
|
+
|
228
|
+
xml_swf_path = gen_swf_path( swf_path, options[:swf_path], url )
|
229
|
+
xml_swf_path << "×tamp=#{Time.now.to_i}" if options[:cache] == false
|
230
|
+
xml_swf_path << "&timeout=#{options[:timeout]}" if options[:timeout]
|
231
|
+
xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
|
232
|
+
|
233
|
+
# if options[:tag_type] == "object"
|
234
|
+
tags = <<-TAGS
|
235
|
+
<object codebase="#{codebase}" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="#{options[:id]}" height="#{options[:height]}" width="#{options[:width]}">
|
236
|
+
<param name="scale" value="noscale">
|
237
|
+
<param name="salign" value="#{options[:salign]}">
|
238
|
+
<param name="bgcolor" value="#{options[:bgcolor]}">
|
239
|
+
<param name="wmode" value="#{options[:wmode]}">
|
240
|
+
<param name="movie" value="#{options[:swf_path]}/#{swf_file}">
|
241
|
+
<param name="FlashVars" value="#{xml_swf_path}&chart_id=#{options[:id]}">
|
242
|
+
<param name="menu" value="true">
|
243
|
+
<param name="allowFullScreen" value="true">
|
244
|
+
<param name="allowScriptAccess" value="sameDomain">
|
245
|
+
<param name="quality" value="high">
|
246
|
+
<param name="play" value="true">
|
247
|
+
<param name="devicefont" value="false">
|
248
|
+
<embed scale="noscale"
|
249
|
+
allowfullscreen="true"
|
250
|
+
allowscriptaccess="sameDomain"
|
251
|
+
bgcolor="#{options[:bgcolor]}"
|
252
|
+
devicefont="false"
|
253
|
+
flashvars="#{xml_swf_path}"
|
254
|
+
menu="true"
|
255
|
+
name="#{options[:id]}"
|
256
|
+
play="true"
|
257
|
+
pluginspage="http://www.macromedia.com/go/getflashplayer"
|
258
|
+
quality="high"
|
259
|
+
salign="#{options[:salign]}"
|
260
|
+
src="#{options[:swf_path]}/#{swf_file}"
|
261
|
+
type="application/x-shockwave-flash"
|
262
|
+
wmode="#{options[:wmode]}"
|
263
|
+
align="#{options[:align]}"
|
264
|
+
height="#{options[:height]}"
|
265
|
+
width="#{options[:width]}"/>
|
266
|
+
</object>
|
267
|
+
TAGS
|
268
|
+
# else
|
269
|
+
# tags = <<-TAGS
|
270
|
+
# <embed scale="noscale"
|
271
|
+
# allowfullscreen="true"
|
272
|
+
# allowscriptaccess="sameDomain"
|
273
|
+
# bgcolor="#{options[:bgcolor]}"
|
274
|
+
# devicefont="false"
|
275
|
+
# flashvars="#{xml_swf_path}"
|
276
|
+
# menu="true"
|
277
|
+
# name="#{options[:id]}"
|
278
|
+
# play="true"
|
279
|
+
# pluginspage="http://www.macromedia.com/go/getflashplayer"
|
280
|
+
# quality="high"
|
281
|
+
# salign="#{options[:salign]}"
|
282
|
+
# src="#{options[:swf_path]}/#{swf_file}"
|
283
|
+
# type="application/x-shockwave-flash"
|
284
|
+
# wmode="#{options[:wmode]}"
|
285
|
+
# align="#{options[:align]}"
|
286
|
+
# height="#{options[:height]}"
|
287
|
+
# width="#{options[:width]}"/>
|
288
|
+
# TAGS
|
289
|
+
# end
|
290
|
+
tags
|
291
|
+
end
|
292
|
+
|
293
|
+
# escape url
|
294
|
+
def escape_url( url )
|
295
|
+
CGI.escape( url.gsub( /&/, '&' ) )
|
296
|
+
end
|
297
|
+
|
298
|
+
# setup up wmode
|
299
|
+
# Set the wmode to opaque if a bgcolor is specified. If not set to
|
300
|
+
# transparent mode unless user overrides it
|
301
|
+
def setup_wmode( options )
|
302
|
+
if options[:bgcolor]
|
303
|
+
options[:wmode] = "opaque" unless options[:wmode]
|
304
|
+
else
|
305
|
+
options[:wmode] = "transparent" unless options[:wmode]
|
306
|
+
options[:bgcolor] = "#FFFFFF"
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
# Check args for size option in the format wXy (Submitted by Sam Livingston-Gray)
|
311
|
+
def setup_movie_size( options )
|
312
|
+
if options[:size] =~ /(\d+)x(\d+)/
|
313
|
+
options[:width] = $1
|
314
|
+
options[:height] = $2
|
315
|
+
options.delete :size
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
# All this stolen form rails to make Ziya work with other fmks....
|
320
|
+
def tag(name, options = nil, open = false, escape = true)
|
321
|
+
"<#{name}#{tag_options(options, escape) if options}" + (open ? ">" : " />")
|
322
|
+
end
|
323
|
+
|
324
|
+
def escape_once(html)
|
325
|
+
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| escape_chars[special] }
|
326
|
+
end
|
327
|
+
|
328
|
+
def tag_options(options, escape = true)
|
329
|
+
unless !options or options.empty?
|
330
|
+
attrs = []
|
331
|
+
if escape
|
332
|
+
options.each do |key, value|
|
333
|
+
next unless value
|
334
|
+
key = key.to_s
|
335
|
+
value = escape_once(value)
|
336
|
+
attrs << %(#{key}="#{value}")
|
337
|
+
end
|
338
|
+
else
|
339
|
+
attrs = options.map { |key, value| %(#{key}="#{value}") }
|
340
|
+
end
|
341
|
+
" #{attrs.sort * ' '}" unless attrs.empty?
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
|
346
|
+
if block_given?
|
347
|
+
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
|
348
|
+
content = capture_block(&block)
|
349
|
+
content_tag = content_tag_string(name, content, options, escape)
|
350
|
+
block_is_within_action_view?(block) ? concat(content_tag, block.binding) : content_tag
|
351
|
+
else
|
352
|
+
content = content_or_options_with_block
|
353
|
+
content_tag_string(name, content, options, escape)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def capture_block( *args, &block )
|
358
|
+
block.call(*args)
|
359
|
+
end
|
360
|
+
|
361
|
+
def content_tag_string(name, content, options, escape = true)
|
362
|
+
tag_options = tag_options(options, escape) if options
|
363
|
+
"<#{name}#{tag_options}>#{content}</#{name}>"
|
364
|
+
end
|
365
|
+
|
366
|
+
def block_is_within_action_view?(block)
|
367
|
+
eval("defined? _erbout", block.binding)
|
368
|
+
end
|
369
|
+
|
370
|
+
def escape_chars
|
371
|
+
{ '&' => '&', '"' => '"', '>' => '>', '<' => '<' }
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
data/lib/ziya.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
# BOZO !! Document !!
|
4
|
+
|
5
|
+
# Equivalent to a header guard in C/C++
|
6
|
+
# Used to prevent the class/module from being loaded more than once
|
7
|
+
unless defined? Ziya
|
8
|
+
module Ziya
|
9
|
+
# :stopdoc:
|
10
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
11
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
12
|
+
|
13
|
+
def self.default_configuration
|
14
|
+
{ :themes_dir => File.join( File.dirname(__FILE__), %w[.. charts themes] ),
|
15
|
+
:log_file => $stdout,
|
16
|
+
:log_level => :info }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.initialize( opts={} )
|
20
|
+
puts ">>> No logger specified. Using ZiYa default logger" unless opts[:logger]
|
21
|
+
puts ">>> No themes_dir specified. Using ZiYa default themes" unless opts[:themes_dir]
|
22
|
+
@config = default_configuration.merge( opts )
|
23
|
+
@logger = opts[:logger] if opts[:logger]
|
24
|
+
|
25
|
+
# Verify existance of themes, designs and helper dirs if any
|
26
|
+
if themes_dir
|
27
|
+
raise "Unable to find themes directory `#{themes_dir}" unless File.exists?( themes_dir )
|
28
|
+
end
|
29
|
+
|
30
|
+
if designs_dir
|
31
|
+
raise "Unable to find designs directory `#{designs_dir}" unless File.exists?( designs_dir )
|
32
|
+
end
|
33
|
+
|
34
|
+
if helpers_dir
|
35
|
+
raise "Unable to find helper directory `#{helpers_dir}" unless File.exists?( helpers_dir )
|
36
|
+
end
|
37
|
+
|
38
|
+
# Add the ziya/lib to the ruby path...
|
39
|
+
$: << libpath
|
40
|
+
Ziya.require_all_libs_relative_to __FILE__
|
41
|
+
|
42
|
+
dump if config[:log_level] == :debug
|
43
|
+
end
|
44
|
+
|
45
|
+
# ZiYa configuration
|
46
|
+
def self.config
|
47
|
+
@config
|
48
|
+
end
|
49
|
+
|
50
|
+
# directory location for ziya stylesheet custom helpers
|
51
|
+
def self.helpers_dir
|
52
|
+
config[:helpers_dir]
|
53
|
+
end
|
54
|
+
|
55
|
+
# the themes root directory location
|
56
|
+
def self.themes_dir
|
57
|
+
config[:themes_dir]
|
58
|
+
end
|
59
|
+
|
60
|
+
# the gauges designs root directory location
|
61
|
+
def self.designs_dir
|
62
|
+
config[:designs_dir]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Debug
|
66
|
+
def self.dump #:nodoc:
|
67
|
+
puts ""
|
68
|
+
puts "ZiYa Configuration Landscape"
|
69
|
+
config.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |k|
|
70
|
+
key = k.to_s.rjust(20)
|
71
|
+
value = config[k].to_s.rjust(97,".")
|
72
|
+
puts "#{key} : #{value}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# fetch the framework logger
|
77
|
+
def self.logger
|
78
|
+
# get a hold of a logger.
|
79
|
+
@logger ||= ::Ziya::Logger.new( { :log_file => config[:log_file],
|
80
|
+
:logger_name => "ZiYa",
|
81
|
+
:log_level => config[:log_level],
|
82
|
+
:additive => false } )
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the library path for the module. If any arguments are given,
|
86
|
+
# they will be joined to the end of the libray path using
|
87
|
+
# <tt>File.join</tt>.
|
88
|
+
#
|
89
|
+
def self.libpath( *args ) #:nodoc:
|
90
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the lpath for the module. If any arguments are given,
|
94
|
+
# they will be joined to the end of the path using
|
95
|
+
# <tt>File.join</tt>.
|
96
|
+
#
|
97
|
+
def self.path( *args ) #:nodoc:
|
98
|
+
args.empty? ? PATH : ::File.join(PATH, *args)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Utility method used to require all files ending in .rb that lie in the
|
102
|
+
# directory below this file that has the same name as the filename passed
|
103
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
104
|
+
# the _filename_ does not have to be equivalent to the directory.
|
105
|
+
#
|
106
|
+
def self.require_all_libs_relative_to( fname, dir = nil ) #:nodoc:
|
107
|
+
dir ||= ::File.basename(fname, '.*')
|
108
|
+
search_me = ::File.expand_path( ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
109
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|