kamelopard 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/kamelopard/classes.rb +107 -1
  2. metadata +21 -42
@@ -15,6 +15,35 @@ module Kamelopard
15
15
 
16
16
  @@sequence = 0
17
17
  @@id_prefix = ''
18
+ @@logger = nil
19
+ LogLevels = {
20
+ :debug => 0,
21
+ :info => 1,
22
+ :notice => 2,
23
+ :warn => 3,
24
+ :error => 4,
25
+ :fatal => 5
26
+ }
27
+
28
+ @@log_level = LogLevels[:notice]
29
+
30
+ # Sets a logging callback function. This function should expect three
31
+ # arguments. The first will be a log level (:debug, :info, :notice, :warn,
32
+ # :error, or :fatal); the second will be a module, categorizing the log
33
+ # entries generally; and the third will be the message
34
+ def Kamelopard.set_logger(l)
35
+ @@logger = l
36
+ end
37
+
38
+ def Kamelopard.set_log_level(lev)
39
+ raise "Unknown log level #{lev}" unless LogLevels.has_key? lev
40
+ @@log_level = LogLevels[lev]
41
+ end
42
+
43
+ def Kamelopard.log(level, mod, msg)
44
+ raise "Unknown log level #{level} for error message #{msg}" unless LogLevels.has_key? level
45
+ @@logger.call(level, mod, msg) unless @@logger.nil? or @@log_level > LogLevels[level]
46
+ end
18
47
 
19
48
  def Kamelopard.get_document
20
49
  DocumentHolder.instance.current_document
@@ -128,6 +157,12 @@ module Kamelopard
128
157
  attr_accessor :kml_id
129
158
  attr_reader :comment
130
159
 
160
+ # The master_only attribute determines whether this Object should be
161
+ # included in slave mode KML files, or not. It defaults to false,
162
+ # indicating the Object should be included in KML files of all types.
163
+ # Set it to true to ensure it shows up only in slave mode.
164
+ attr_reader :master_only
165
+
131
166
  # This constructor looks for values in the options hash that match
132
167
  # class attributes, and sets those attributes to the values in the
133
168
  # hash. So a class with an attribute called :when can be set via the
@@ -135,6 +170,7 @@ module Kamelopard
135
170
  # argument to the constructor.
136
171
  def initialize(options = {})
137
172
  @kml_id = "#{Kamelopard.id_prefix}#{self.class.name.gsub('Kamelopard::', '')}_#{ Kamelopard.get_next_id }"
173
+ @master_only = false
138
174
 
139
175
  options.each do |k, v|
140
176
  method = "#{k}=".to_sym
@@ -146,6 +182,64 @@ module Kamelopard
146
182
  end
147
183
  end
148
184
 
185
+ # If this is a master-only object, this function gets called internally
186
+ # in place of the object's original to_kml method
187
+ def _alternate_to_kml(*a)
188
+ if @master_only and DocumentHolder.instance.current_document.master_mode
189
+ Kamelopard.log(:info, 'master/slave', "Because this object is master_only, and we're in slave mode, we're not including object #{self.inspect}")
190
+ return ''
191
+ end
192
+
193
+ # XXX There must be a better way to do this, but I don't know what
194
+ # it is. Running "@original_to_kml_method.call(a)" when the
195
+ # original method expects multiple arguments interprets the
196
+ # argument as an array, not as a list of arguments. This of course
197
+ # makes sense, but I don't know how to get around it.
198
+ case @original_to_kml_method.parameters.size
199
+ when 0
200
+ return @original_to_kml_method.call
201
+ when 1
202
+ # XXX This bothers me, and I'm unconvinced the calls to
203
+ # functions with more than one parameter actually work. Why
204
+ # should I have to pass a[0][0] here and just a[0], a[1], etc.
205
+ # for larger numbers of parameters, if this were all correct?
206
+ return @original_to_kml_method.call(a[0][0])
207
+ when 2
208
+ return @original_to_kml_method.call(a[0], a[1])
209
+ when 3
210
+ return @original_to_kml_method.call(a[0], a[1], a[2])
211
+ else
212
+ raise "Unsupported number of arguments (#{@original_to_kml_method.arity}) in to_kml function #{@original_to_kml_method}. This is a bug"
213
+ end
214
+ end
215
+
216
+ # Changes whether this object is available in master style documents
217
+ # only, or in slave documents as well.
218
+ #
219
+ # More specifically, this method replaces the object's to_kml method
220
+ # with something that checks whether this object should be included in
221
+ # the KML output, based on whether it's master-only or not, and whether
222
+ # the document is in master or slave mode.
223
+ def master_only=(a)
224
+ # If this object is a master_only object, and we're printing in
225
+ # slave mode, this object shouldn't be included at all (to_kml
226
+ # should return an empty string)
227
+ if a != @master_only
228
+ @master_only = a
229
+ if a then
230
+ @original_to_kml_method = public_method(:to_kml)
231
+ define_singleton_method :to_kml, lambda { |*a| self._alternate_to_kml(a) }
232
+ else
233
+ define_singleton_method :to_kml, @original_to_kml_method
234
+ end
235
+ end
236
+ end
237
+
238
+ # This just makes the Ruby-ism question mark suffix work
239
+ def master_only?
240
+ return @master_only
241
+ end
242
+
149
243
  # Adds an XML comment to this node. Handles HTML escaping the comment
150
244
  # if needed
151
245
  def comment=(cmnt)
@@ -573,8 +667,8 @@ module Kamelopard
573
667
  w = XML::Node.new 'end'
574
668
  w << @end
575
669
  k << w
576
- elem << k unless elem.nil?
577
670
  end
671
+ elem << k unless elem.nil?
578
672
  k
579
673
  end
580
674
  end
@@ -777,6 +871,7 @@ module Kamelopard
777
871
  end
778
872
 
779
873
  def styles_to_kml(elem)
874
+ raise "done here" if elem.class == Array
780
875
  @styles.each do |a|
781
876
  a.to_kml(elem) unless a.attached?
782
877
  end
@@ -866,10 +961,17 @@ module Kamelopard
866
961
  class Document < Container
867
962
  attr_accessor :flyto_mode, :folders, :tours, :uses_xal, :vsr_actions
868
963
 
964
+ # Is this KML destined for a master LG node, or a slave? True if this
965
+ # is a master node. This defaults to true, so tours that don't need
966
+ # this function, and tours for non-LG targets, work normally.
967
+ attr_accessor :master_mode
968
+
869
969
  def initialize(options = {})
870
970
  @tours = []
871
971
  @folders = []
872
972
  @vsr_actions = []
973
+ @master_mode = false
974
+ Kamelopard.log(:info, 'Document', "Adding myself to the document holder")
873
975
  DocumentHolder.instance << self
874
976
  super
875
977
  end
@@ -995,11 +1097,14 @@ module Kamelopard
995
1097
  attr_reader :documents
996
1098
 
997
1099
  def initialize(doc = nil)
1100
+ Kamelopard.log :debug, 'DocumentHolder', "document holder constructor"
998
1101
  @documents = []
999
1102
  @document_index = -1
1000
1103
  if ! doc.nil?
1104
+ Kamelopard.log :info, 'DocumentHolder', "Constructor called with a doc. Adding it."
1001
1105
  self.documents << doc
1002
1106
  end
1107
+ Kamelopard.log :debug, 'DocumentHolder', "document holder constructor finished"
1003
1108
  end
1004
1109
 
1005
1110
  def document_index
@@ -1013,6 +1118,7 @@ module Kamelopard
1013
1118
  def current_document
1014
1119
  # Automatically create a Document if we don't already have one
1015
1120
  if @documents.size <= 0
1121
+ Kamelopard.log :info, 'Document', "Doc doesn't exist... adding new one"
1016
1122
  Document.new
1017
1123
  @document_index = 0
1018
1124
  end
metadata CHANGED
@@ -1,74 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: kamelopard
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 8
10
- version: 0.0.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Joshua Tolley
14
9
  - Szymon Guz
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2013-02-11 00:00:00 -07:00
20
- default_executable:
13
+ date: 2013-02-11 00:00:00.000000000 Z
21
14
  dependencies: []
22
-
23
- description: Various classes and functions used to ease development of KML files, in particular for development of Google Earth tours
24
- email:
15
+ description: Various classes and functions used to ease development of KML files,
16
+ in particular for development of Google Earth tours
17
+ email:
25
18
  - josh@endpoint.com
26
19
  - szymon@endpoint.com
27
20
  executables: []
28
-
29
21
  extensions: []
30
-
31
22
  extra_rdoc_files: []
32
-
33
- files:
23
+ files:
34
24
  - lib/kamelopard/geocode.rb
35
25
  - lib/kamelopard/classes.rb
36
26
  - lib/kamelopard/functions.rb
37
27
  - lib/kamelopard/pointlist.rb
38
28
  - lib/kamelopard.rb
39
- has_rdoc: true
40
29
  homepage: http://www.endpoint.com/services/liquid_galaxy
41
30
  licenses: []
42
-
43
31
  post_install_message:
44
32
  rdoc_options: []
45
-
46
- require_paths:
33
+ require_paths:
47
34
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
35
+ required_ruby_version: !ruby/object:Gem::Requirement
49
36
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
42
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
66
47
  requirements: []
67
-
68
48
  rubyforge_project:
69
- rubygems_version: 1.5.3
49
+ rubygems_version: 1.8.25
70
50
  signing_key:
71
51
  specification_version: 3
72
52
  summary: Tools for building KML
73
53
  test_files: []
74
-