Module: Ziya

Defined in:
lib/ziya.rb,
lib/ziya/version.rb,
lib/ziya/utils/logger.rb,
lib/ziya/html_helpers/base.rb,
lib/ziya/yaml_helpers/base.rb,
lib/ziya/yaml_helpers/charts.rb

Defined Under Namespace

Modules: Charts, Gauges, HtmlHelpers, Maps, Version, YamlHelpers Classes: Logger

Constant Summary collapse

LIBPATH =

:stopdoc:

::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR

Class Method Summary collapse

Class Method Details

.configObject

ZiYa configuration



50
51
52
# File 'lib/ziya.rb', line 50

def self.config
  @config
end

.default_configurationObject



9
10
11
12
13
14
15
# File 'lib/ziya.rb', line 9

def self.default_configuration
  { 
    :themes_dir => File.join( File.dirname(__FILE__), %w[.. charts themes] ),
    :log_file   => $stdout,
    :log_level  => :info 
  }
end

.designs_dirObject

the gauges designs root directory location



70
71
72
# File 'lib/ziya.rb', line 70

def self.designs_dir
  config[:designs_dir]
end

.dumpObject

Debug



75
76
77
78
79
80
81
82
83
# File 'lib/ziya.rb', line 75

def self.dump #:nodoc:
  puts "" 
  puts "ZiYa Configuration Landscape"    
  config.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |k| 
    key   = k.to_s.rjust(20)
    value = config[k].to_s.rjust(97,".")
    puts "#{key} : #{value}"
  end
end

.helpers_dirObject

directory location for ziya stylesheet custom helpers



55
56
57
# File 'lib/ziya.rb', line 55

def self.helpers_dir
  config[:helpers_dir]
end

.initialize(opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ziya.rb', line 17

def self.initialize( opts={} )
  if opts[:log_level] == :debug
    puts ">>> No logger specified. Using ZiYa default logger" unless opts[:logger]
    puts ">>> No themes_dir specified. Using ZiYa default themes" unless opts[:themes_dir]      
  end
  @config = default_configuration.merge( opts )
  @logger = opts[:logger] if opts[:logger]

  # Verify existence of themes, designs and helper dirs if any
  if themes_dir
    raise "Unable to find themes directory `#{themes_dir}" unless File.exists?( themes_dir )
  end

  if map_themes_dir
    raise "Unable to find map themes directory `#{map_themes_dir}" unless File.exists?( map_themes_dir )
  end

  if designs_dir
    raise "Unable to find designs directory `#{designs_dir}" unless File.exists?( designs_dir )
  end
  
  if helpers_dir
    raise "Unable to find helper directory `#{helpers_dir}" unless File.exists?( helpers_dir )
  end
  
  # Add the ziya/lib to the ruby path...
  $: << libpath
  Ziya.require_all_libs_relative_to __FILE__
  
  dump if config[:log_level] == :debug
end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



98
99
100
# File 'lib/ziya.rb', line 98

def self.libpath( *args ) #:nodoc:
  args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
end

.loggerObject

fetch the framework logger



86
87
88
89
90
91
92
# File 'lib/ziya.rb', line 86

def self.logger
  # get a hold of a logger.
  @logger ||= ::Ziya::Logger.new( { :log_file          => config[:log_file], 
                                    :logger_name       => "ZiYa",
                                    :log_level         => config[:log_level],
                                    :additive          => false } )
end

.map_themes_dirObject

the map themes root directory location



65
66
67
# File 'lib/ziya.rb', line 65

def self.map_themes_dir
  config[:map_themes_dir]
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



106
107
108
# File 'lib/ziya.rb', line 106

def self.path( *args ) #:nodoc:
  args.empty? ? PATH : ::File.join(PATH, *args)
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



115
116
117
118
119
# File 'lib/ziya.rb', line 115

def self.require_all_libs_relative_to( fname, dir = nil ) #:nodoc:
  dir       ||= ::File.basename(fname, '.*')
  search_me   = ::File.expand_path( ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
  Dir.glob(search_me).sort.each {|rb| require rb}
end

.themes_dirObject

the themes root directory location



60
61
62
# File 'lib/ziya.rb', line 60

def self.themes_dir
  config[:themes_dir]
end