RUIC 0.4.3 → 0.4.4
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.
- checksums.yaml +4 -4
- data/lib/ruic/assets.rb +119 -10
- data/lib/ruic/presentation.rb +38 -6
- data/lib/ruic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cd982f65f8cae25edc67f0619f9a5f11d36fd89
|
4
|
+
data.tar.gz: 5600614882179d970952c0d67bc428a8e7f8ee73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa749d218b876a2a13261063989ca02ee57dace463b291f80328673d7207622b49bd5e93ceb21c010f7b443230d0f31079e6d85779f41e2d8ba0d2bcd5aaaf7
|
7
|
+
data.tar.gz: 97fdefc32b8356d2c8ca48d40c1cc19a3fc954564810677e64d331151077a1e3f66cce981d19ae26179a10ab578f4c4f53e3602793b1ed28564bf9642c6416d4
|
data/lib/ruic/assets.rb
CHANGED
@@ -47,76 +47,164 @@ class UIC::MetaData
|
|
47
47
|
end
|
48
48
|
alias_method :/, :at
|
49
49
|
|
50
|
-
|
50
|
+
# @return [Presentation] the presentation that this asset is part of.
|
51
|
+
attr_accessor :presentation
|
52
|
+
|
53
|
+
# @return [Nokogiri::XML::Element] the internal XML element in the scene graph of the presentation.
|
54
|
+
attr_accessor :el
|
55
|
+
|
56
|
+
# Create a new asset. This is called for you automatically; you likely should not be using it.
|
57
|
+
# @param presentation [Presentation] the presentation owning this asset.
|
58
|
+
# @param element [Nokogiri::XML::Element] the internal XML element in the scene graph of the presentation.
|
51
59
|
def initialize( presentation, element )
|
52
60
|
@presentation = presentation
|
53
61
|
@el = element
|
54
62
|
end
|
55
63
|
|
64
|
+
# @return [String] the type of this asset. For example: `"Model"`, `"Material"`, `"ReferencedMaterial"`, `"PathAnchorPoint"`, etc.
|
56
65
|
def type
|
57
66
|
self.class.name
|
58
|
-
# self.class.name.split('::').last
|
59
67
|
end
|
60
68
|
|
69
|
+
# @return [AssetBase] the parent of this asset in the scene graph.
|
70
|
+
# @see Presentation#parent_asset
|
61
71
|
def parent
|
62
72
|
presentation.parent_asset(self)
|
63
73
|
end
|
64
74
|
|
75
|
+
# @return [Array<AssetBase>] array of child assets in the scene graph. Children are in scene graph order.
|
76
|
+
# @see Presentation#child_assets
|
65
77
|
def children
|
66
78
|
presentation.child_assets(self)
|
67
79
|
end
|
68
80
|
|
81
|
+
# Find descendant assets matching criteria.
|
82
|
+
# This method is the same as (but more convenient than) {Presentation#find} using the `:_under` criteria.
|
83
|
+
# See that method for documentation of the `criteria`.
|
84
|
+
#
|
85
|
+
# @example
|
86
|
+
# preso = app.main
|
87
|
+
# group = preso/"Scene.Layer.Vehicle"
|
88
|
+
# tires = group.find name:/^Tire/
|
89
|
+
#
|
90
|
+
# # alternative
|
91
|
+
# tires = preso.find name:/^Tire/, _under:group
|
92
|
+
#
|
93
|
+
# @return [Array<AssetBase>]
|
94
|
+
#
|
95
|
+
# @see Presentation#find
|
69
96
|
def find(criteria={},&block)
|
70
97
|
criteria[:_under] ||= self
|
71
98
|
presentation.find(criteria,&block)
|
72
99
|
end
|
73
100
|
|
74
|
-
#
|
101
|
+
# @return [AssetBase] the component or scene that owns this asset.
|
102
|
+
# If this asset is a component, does not return itself.
|
103
|
+
# @see Presentation#owning_component
|
75
104
|
def component
|
76
105
|
presentation.owning_component(self)
|
77
106
|
end
|
78
107
|
|
108
|
+
# @return [Boolean] `true` if this asset is a component or Scene.
|
79
109
|
def component?
|
80
|
-
@el.name
|
110
|
+
@el.name=='Component' || @el.name=='Scene'
|
81
111
|
end
|
82
112
|
|
113
|
+
# @return [Boolean] `true` if this asset is on the master slide.
|
114
|
+
# @see Presentation#master?
|
83
115
|
def master?
|
84
116
|
presentation.master?(self)
|
85
117
|
end
|
86
118
|
|
119
|
+
# @return [Boolean] `true` if this asset is a Slide.
|
87
120
|
def slide?
|
88
121
|
false
|
89
122
|
end
|
90
123
|
|
124
|
+
# @param slide_name_or_index [Integer,String] the slide number of name to check for presence on.
|
125
|
+
# @return [Boolean] `true` if this asset is present on the specified slide.
|
126
|
+
# @see Presentation#has_slide?
|
91
127
|
def has_slide?(slide_name_or_index)
|
92
128
|
presentation.has_slide?(self,slide_name_or_index)
|
93
129
|
end
|
94
130
|
|
131
|
+
# @return [SlideCollection] an array-like collection of all slides that the asset is available on.
|
132
|
+
# @see Presentation#slides_for
|
95
133
|
def slides
|
96
134
|
presentation.slides_for(self)
|
97
135
|
end
|
98
136
|
|
137
|
+
# @example
|
138
|
+
# logo = app/"main:Scene.UI.Logo"
|
139
|
+
# assert logo.master? # It's a master object
|
140
|
+
#
|
141
|
+
# show logo['endtime'].values #=> [10000,500,1000,750]
|
142
|
+
# show logo['opacity'].values #=> [100,0,0,100]
|
143
|
+
# logo1 = logo.on_slide(1)
|
144
|
+
# logo2 = logo.on_slide(2)
|
145
|
+
# show logo1['endtime'] #=> 500
|
146
|
+
# show logo2['endtime'] #=> 1000
|
147
|
+
# show logo1['opacity'] #=> 0
|
148
|
+
# show logo2['opacity'] #=> 0
|
149
|
+
#
|
150
|
+
# logo2['opacity'] = 66
|
151
|
+
# show logo['opacity'].values #=> [100,0,66,100]
|
152
|
+
#
|
153
|
+
# @param slide_name_or_index [Integer,String] the slide number or name to create the proxy for.
|
154
|
+
# @return [SlideValues] a proxy that yields attribute values for a specific slide.
|
99
155
|
def on_slide(slide_name_or_index)
|
100
156
|
if has_slide?(slide_name_or_index)
|
101
157
|
UIC::SlideValues.new( self, slide_name_or_index )
|
102
158
|
end
|
103
159
|
end
|
104
160
|
|
161
|
+
# @return [String] the script path to this asset.
|
162
|
+
# @see #path_to
|
163
|
+
# @see Presentation#path_to
|
105
164
|
def path
|
106
165
|
@path ||= @presentation.path_to(self)
|
107
166
|
end
|
108
167
|
|
168
|
+
# @param other_asset [AssetBase] the asset to find the relative path to.
|
169
|
+
# @return [String] the script path to another asset, relative to this one.
|
170
|
+
# @see #path
|
171
|
+
# @see Presentation#path_to
|
172
|
+
def path_to(other_asset)
|
173
|
+
@presentation.path_to(other_asset,self)
|
174
|
+
end
|
175
|
+
|
176
|
+
# @return [String] the name of this asset in the scene graph.
|
109
177
|
def name
|
110
178
|
properties['name'].get( self, presentation.slide_index(self) )
|
111
179
|
end
|
112
180
|
|
181
|
+
# Change the name of the asset in the scene graph.
|
182
|
+
# @param new_name [String] the new name for this asset.
|
183
|
+
# @return [String] the new name.
|
113
184
|
def name=( new_name )
|
185
|
+
@path = nil # invalidate the memoization
|
114
186
|
properties['name'].set( self, new_name, presentation.slide_index(self) )
|
115
187
|
end
|
116
188
|
|
117
|
-
# Get the value(s) of an attribute
|
189
|
+
# Get the value(s) of an attribute.
|
190
|
+
# If `slide_name_or_index` is omitted, creates a ValuesPerSlide proxy for the specified attribute.
|
191
|
+
# @example
|
192
|
+
# logo = app/"main:Scene.UI.Logo"
|
193
|
+
# show logo.master? #=> true (it's a master object)
|
194
|
+
# show logo['endtime'].linked? #=> false (the endtime property is unlinked)
|
195
|
+
# show logo['endtime'].values #=> [10000,500,1000,750]
|
196
|
+
# show logo['endtime',0] #=> 10000 (the master slide value)
|
197
|
+
# show logo['endtime',"Slide 1"] #=> 500
|
198
|
+
# show logo['endtime',2] #=> 1000
|
199
|
+
#
|
200
|
+
# @param attribute_name [String,Symbol] the name of the attribute.
|
201
|
+
# @param slide_name_or_index [Integer,String] the slide number or name to find the value on.
|
202
|
+
# @return [Object] the value of the property on the given slide.
|
203
|
+
# @return [ValuesPerSlide] if no slide is specified.
|
204
|
+
# @see #on_slide
|
205
|
+
# @see Presentation#get_attribute
|
118
206
|
def [](attribute_name, slide_name_or_index=nil)
|
119
|
-
if property = properties[attribute_name]
|
207
|
+
if property = properties[attribute_name.to_s]
|
120
208
|
if slide_name_or_index
|
121
209
|
property.get( self, slide_name_or_index ) if has_slide?(slide_name_or_index)
|
122
210
|
else
|
@@ -125,26 +213,47 @@ class UIC::MetaData
|
|
125
213
|
end
|
126
214
|
end
|
127
215
|
|
128
|
-
# Set the value of an attribute, either across all slides, or on a particular slide
|
129
|
-
#
|
130
|
-
#
|
216
|
+
# Set the value of an attribute, either across all slides, or on a particular slide.
|
217
|
+
#
|
218
|
+
# @example
|
219
|
+
# logo = app/"main:Scene.UI.Logo"
|
220
|
+
# show logo.master? #=> true (it's a master object)
|
221
|
+
# show logo['endtime'].linked? #=> false (the endtime property is unlinked)
|
222
|
+
# show logo['endtime'].values #=> [10000,500,1000,750]
|
223
|
+
#
|
224
|
+
# logo['endtime',1] = 99
|
225
|
+
# show logo['endtime'].values #=> [10000,99,1000,750]
|
226
|
+
#
|
227
|
+
# logo['endtime'] = 42
|
228
|
+
# show logo['endtime'].values #=> [42,42,42,42]
|
229
|
+
# show logo['endtime'].linked? #=> false (the endtime property is still unlinked)
|
230
|
+
#
|
231
|
+
# @param attribute_name [String,Symbol] the name of the attribute.
|
232
|
+
# @param slide_name_or_index [Integer,String] the slide number or name to set the value on.
|
233
|
+
# @param new_value [Numeric,String] the new value for the attribute.
|
234
|
+
# @see Presentation#set_attribute
|
131
235
|
def []=( attribute_name, slide_name_or_index=nil, new_value )
|
132
|
-
if property = properties[attribute_name] then
|
236
|
+
if property = properties[attribute_name.to_s] then
|
133
237
|
property.set(self,new_value,slide_name_or_index)
|
134
238
|
end
|
135
239
|
end
|
136
240
|
|
241
|
+
# @return [String] the XML representation of the scene graph element.
|
137
242
|
def to_xml
|
138
243
|
@el.to_xml
|
139
244
|
end
|
245
|
+
|
246
|
+
# @private no need to document this
|
140
247
|
def inspect
|
141
248
|
"<asset #{@el.name}##{@el['id']}>"
|
142
249
|
end
|
143
250
|
|
251
|
+
# @private no need to document this
|
144
252
|
def to_s
|
145
253
|
"<#{type} #{path}>"
|
146
254
|
end
|
147
255
|
|
256
|
+
# @private no need to document this
|
148
257
|
def ==(other)
|
149
258
|
(self.class==other.class) && (el==other.el)
|
150
259
|
end
|
data/lib/ruic/presentation.rb
CHANGED
@@ -103,6 +103,7 @@ class UIC::Presentation
|
|
103
103
|
|
104
104
|
# @param child_asset [MetaData::AssetBase] an asset in the presentation.
|
105
105
|
# @return [MetaData::AssetBase] the scene graph parent of the child asset, or `nil` for the Scene.
|
106
|
+
# @see MetaData::AssetBase#parent
|
106
107
|
def parent_asset( child_asset )
|
107
108
|
child_graph_el = child_asset.el
|
108
109
|
unless child_graph_el==@scene || child_graph_el.parent.nil?
|
@@ -112,6 +113,7 @@ class UIC::Presentation
|
|
112
113
|
|
113
114
|
# @param parent_asset [MetaData::AssetBase] an asset in the presentation.
|
114
115
|
# @return [Array<MetaData::AssetBase>] array of scene graph children of the specified asset.
|
116
|
+
# @see MetaData::AssetBase#children
|
115
117
|
def child_assets( parent_asset )
|
116
118
|
parent_asset.el.element_children.map{ |child| asset_for_el(child) }
|
117
119
|
end
|
@@ -181,9 +183,23 @@ class UIC::Presentation
|
|
181
183
|
# * If `from_asset` is supplied the path will be relative to that asset (e.g. `"parent.parent.Group.Model"`).
|
182
184
|
# * If `from_asset` is omitted the path will be absolute (e.g. `"Scene.Layer.Group.Model"`).
|
183
185
|
#
|
186
|
+
# This is used internally by {MetaData::AssetBase#path} and {MetaData::AssetBase#path_to};
|
187
|
+
# those methods are usually more convenient to use.
|
188
|
+
#
|
189
|
+
# @example
|
190
|
+
# preso = app.main
|
191
|
+
# preso.scene.children.each{ |child| show preso.path_to(child) }
|
192
|
+
# #=> "main:Scene.MyAppBehavior"
|
193
|
+
# #=> "main:Scene.UILayer"
|
194
|
+
# #=> "main:Scene.ContentLayer"
|
195
|
+
# #=> "main:Scene.BGLayer"
|
196
|
+
#
|
184
197
|
# @param asset [MetaData::AssetBase] the asset to find the path to.
|
185
198
|
# @param from_asset [MetaData::AssetBase] the asset to find the path relative to.
|
186
199
|
# @return [String] the script path to the element.
|
200
|
+
#
|
201
|
+
# @see MetaData::AssetBase#path
|
202
|
+
# @see MetaData::AssetBase#path_to
|
187
203
|
def path_to( asset, from_asset=nil )
|
188
204
|
el = asset.el
|
189
205
|
|
@@ -269,6 +285,8 @@ class UIC::Presentation
|
|
269
285
|
# @param asset [MetaData::AssetBase] the asset to fetch the attribute for.
|
270
286
|
# @param attr_name [String] the name of the attribute to get the value of.
|
271
287
|
# @param slide_name_or_index [String,Integer] the string name or integer index of the slide.
|
288
|
+
# @return [Object] the value of the asset on the slide
|
289
|
+
# @see MetaData::AssetBase#[]
|
272
290
|
def get_attribute( asset, attr_name, slide_name_or_index )
|
273
291
|
graph_element = asset.el
|
274
292
|
((addsets=@addsets_by_graph[graph_element]) && ( # State (slide) don't have any addsets
|
@@ -295,6 +313,7 @@ class UIC::Presentation
|
|
295
313
|
# @param asset [MetaData::AssetBase] the asset to fetch the attribute for.
|
296
314
|
# @param attr_name [String] the name of the attribute to get the value of.
|
297
315
|
# @param slide_name_or_index [String,Integer] the string name or integer index of the slide.
|
316
|
+
# @see MetaData::AssetBase#[]=
|
298
317
|
def set_attribute( asset, property_name, slide_name_or_index, str )
|
299
318
|
graph_element = asset.el
|
300
319
|
if attribute_linked?( asset, property_name )
|
@@ -325,13 +344,18 @@ class UIC::Presentation
|
|
325
344
|
end
|
326
345
|
|
327
346
|
# @return [MetaData::AssetBase] the component asset that owns the supplied asset.
|
328
|
-
#
|
347
|
+
# If the graph_element **is** a component this will return its parent component or Scene.
|
348
|
+
# @see owning_or_self_component_element
|
349
|
+
# @api private
|
329
350
|
def owning_component_element( graph_element )
|
330
351
|
graph_element.at_xpath('(ancestor::Component[1] | ancestor::Scene[1])[last()]')
|
331
352
|
end
|
332
353
|
private :owning_component_element
|
333
354
|
|
334
355
|
# @return [Nokogiri::XML::Element] the "time context" scene graph element that owns the supplied element.
|
356
|
+
# If the graph_element **is** a component this will return the element itself.
|
357
|
+
# @see owning_component_element
|
358
|
+
# @api private
|
335
359
|
def owning_or_self_component_element( graph_element )
|
336
360
|
graph_element.at_xpath('(ancestor-or-self::Component[1] | ancestor-or-self::Scene[1])[last()]')
|
337
361
|
end
|
@@ -425,6 +449,7 @@ class UIC::Presentation
|
|
425
449
|
end
|
426
450
|
|
427
451
|
# @return [Boolean] `true` if the asset is added on the master slide.
|
452
|
+
# @see MetaData::AssetBase#master?
|
428
453
|
def master?(asset)
|
429
454
|
graph_element = asset.el
|
430
455
|
(graph_element == @scene) || !!(@addsets_by_graph[graph_element] && @addsets_by_graph[graph_element][0])
|
@@ -517,16 +542,20 @@ class UIC::Presentation
|
|
517
542
|
end
|
518
543
|
end
|
519
544
|
|
520
|
-
|
545
|
+
# @param uip_path [String] Path to the `.uip` presentation file on disk to load.
|
546
|
+
# @return [Presentation] Shortcut for `UIC::Presentation.new`
|
547
|
+
def UIC.Presentation( uip_path=nil )
|
521
548
|
UIC::Presentation.new( uip_path )
|
522
549
|
end
|
523
550
|
|
551
|
+
# An {Application::Presentation} is a {Presentation} that is associated with a specific `.uia` application.
|
552
|
+
# In addition to normal {Presentation} methods it has additional methods related to its presense in the application.
|
524
553
|
class UIC::Application::Presentation < UIC::Presentation
|
525
554
|
include UIC::ElementBacked
|
526
555
|
# @!parse extend UIC::ElementBacked::ClassMethods
|
527
556
|
|
528
557
|
# @!attribute [rw] id
|
529
|
-
# @return [String] the id of the presentation asset
|
558
|
+
# @return [String] the id of the presentation asset in the `.uia`
|
530
559
|
xmlattribute :id do |new_id|
|
531
560
|
main_preso = app.main_presentation
|
532
561
|
super(new_id)
|
@@ -538,11 +567,13 @@ class UIC::Application::Presentation < UIC::Presentation
|
|
538
567
|
xmlattribute :src
|
539
568
|
|
540
569
|
# @!attribute active
|
541
|
-
# @return [Boolean]
|
542
|
-
xmlattribute :active, ->(val){ val=="True" } do |new_val|
|
570
|
+
# @return [Boolean] Is the presentation initially active in the application?
|
571
|
+
xmlattribute :active, ->(val){ val=="True" || val=="" } do |new_val|
|
543
572
|
new_val ? 'True' : 'False'
|
544
573
|
end
|
545
574
|
|
575
|
+
# @param application [Application] the {Application} object owning this presentation.
|
576
|
+
# @param el [Nokogiri::XML::Element] the XML element in the `.uia` representing this presentation.
|
546
577
|
def initialize(application,el)
|
547
578
|
self.owner = application
|
548
579
|
self.el = el
|
@@ -550,8 +581,9 @@ class UIC::Application::Presentation < UIC::Presentation
|
|
550
581
|
end
|
551
582
|
alias_method :app, :owner
|
552
583
|
|
584
|
+
# Overrides {UIC::Presentation#path_to} to prefix all absolute paths with the {#id}
|
553
585
|
def path_to( el, from=nil )
|
554
|
-
"#{id}:#{super}"
|
586
|
+
from ? super : "#{id}:#{super}"
|
555
587
|
end
|
556
588
|
end
|
557
589
|
|
data/lib/ruic/version.rb
CHANGED