Class: UIC::Presentation
- Inherits:
-
Object
- Object
- UIC::Presentation
- Includes:
- XMLFileBacked
- Defined in:
- lib/ruic/presentation.rb
Overview
A Presentation represents a .uip presentation, created and edited by UI Composer Studio.
Direct Known Subclasses
Instance Attribute Summary
Attributes included from XMLFileBacked
Attributes included from FileBacked
Instance Method Summary collapse
-
#aliases ⇒ Array<MetaData::AssetBase>
Array of alias nodes in the presentation.
-
#anchor_points ⇒ Array<MetaData::AssetBase>
Array of path anchor points in the presentation.
-
#asset_by_id(id) ⇒ MetaData::AssetBase
Find an asset in the presentation based on its internal XML identifier.
-
#assets ⇒ Object
Get an array of all assets in the scene graph, in document order.
-
#at(path, root = @graph) ⇒ MetaData::AssetBase
(also: #/)
Find an element or asset in this presentation by scripting path.
-
#attribute_linked?(asset, attribute_name) ⇒ Boolean
True if this asset's attribute is linked on the master slide.
-
#behaviors ⇒ Array<MetaData::AssetBase>
Array of behavior elements in the presentation.
-
#cameras ⇒ Array<MetaData::AssetBase>
Array of cameras in the presentation.
-
#child_assets(parent_asset) ⇒ Array<MetaData::AssetBase>
Array of scene graph children of the specified asset.
-
#components ⇒ Array<MetaData::AssetBase>
Array of components in the presentation (not including the Scene).
-
#effects ⇒ Array<MetaData::AssetBase>
Array of effects in the presentation.
-
#errors ⇒ Array<String>
An array (possibly empty) of all errors in this presentation.
-
#errors? ⇒ Boolean
True if there any errors with the presentation.
-
#find(criteria = {}) {|asset, index| ... } ⇒ Array<MetaData::AssetBase>
Find assets in this presentation matching criteria.
-
#generate_custom_classes ⇒ nil
Scan the .uip for custom classes that will be needed to generate assets.
-
#get_attribute(asset, attr_name, slide_name_or_index) ⇒ Object
Fetch the value of an asset's attribute on a particular slide.
-
#groups ⇒ Array<MetaData::AssetBase>
Array of groups in the presentation.
-
#has_slide?(asset, slide_name_or_index) ⇒ Boolean
True if the asset exists on the supplied slide.
-
#hierarchy(root = scene) ⇒ String
A visual hierarchy under the specified asset.
-
#image_paths ⇒ Array<String>
Array of all image paths referenced by this presentation.
-
#image_usage ⇒ Hash
A mapping of image paths to arrays of the assets referencing them.
-
#images ⇒ Array<MetaData::AssetBase>
Array of image elements in the presentation.
-
#initialize(uip_path = nil) ⇒ Presentation
constructor
Create a new presentation.
-
#layers ⇒ Array<MetaData::AssetBase>
Array of layers in the presentation.
-
#lights ⇒ Array<MetaData::AssetBase>
Array of lights in the presentation.
-
#master?(asset) ⇒ Boolean
trueif the asset is added on the master slide. -
#materials ⇒ Array<MetaData::AssetBase>
Array of materials in the presentation (includes Referenced and Custom Materials).
-
#models ⇒ Array<MetaData::AssetBase>
(also: #meshes)
Array of model nodes in the presentation.
-
#on_doc_loaded ⇒ nil
Load information for the presentation from disk.
-
#owning_component(asset) ⇒ MetaData::AssetBase
The component (or Scene) asset that owns the supplied asset.
-
#parent_asset(child_asset) ⇒ MetaData::AssetBase
The scene graph parent of the child asset, or
nilfor the Scene. -
#path_to(asset, from_asset = nil) ⇒ String
Generate the script path for an asset in the presentation.
-
#paths ⇒ Array<MetaData::AssetBase>
Array of path nodes in the presentation.
-
#rebuild_caches_from_document ⇒ nil
Update the presentation to be in-sync with the document.
-
#referenced_files ⇒ Array<String>
Which files are used by the presentation.
-
#replace_asset(existing_asset, new_type, attributes = {}) ⇒ MetaData::AssetBase
Replace an existing asset with a new kind of asset.
-
#scene ⇒ MetaData::Scene
The root scene asset for the presentation.
-
#set_attribute(asset, property_name, slide_name_or_index, str) ⇒ Object
Set the value of an asset's attribute on a particular slide.
-
#slide_index(asset) ⇒ Integer
The index of the first slide where an asset is added (0 for master, non-zero for non-master).
-
#slides_for(asset) ⇒ SlideCollection
An array-like collection of all slides that the asset is available on.
-
#texts ⇒ Array<MetaData::AssetBase>
Array of text elements in the presentation.
-
#to_xml ⇒ String
The xml representation of this presentation.
-
#unlink_attribute(asset, attribute_name) ⇒ Boolean
Unlinks a master attribute, yielding distinct values on each slide.
Methods included from XMLFileBacked
Methods included from FileBacked
#absolute_path, #file_found?, #filename, #relative_path, #save!, #save_as
Constructor Details
#initialize(uip_path = nil) ⇒ Presentation
Create a new presentation. If you do not specify the uip_path to load from, you must
later set the .file =for the presentation, and then call the #load_from_file method.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruic/presentation.rb', line 8 def initialize( uip_path=nil ) @doc = Nokogiri.XML('<UIP version="3"><Project><Graph><Scene id="Scene"/></Graph><Logic><State name="Master Slide" component="#Scene"/></Logic></Project></UIP>') @graph = @doc.at('Graph') @scene = @graph.at('Scene') @logic = @doc.at('Logic') @missing_classes = [] @asset_by_el = {} # indexed by asset graph element @slides_for = {} # indexed by asset graph element @slides_by_el = {} # indexed by slide state element self.file = uip_path if uip_path end |
Instance Method Details
#aliases ⇒ Array<MetaData::AssetBase>
Returns array of alias nodes in the presentation.
612 |
# File 'lib/ruic/presentation.rb', line 612 def aliases; find _type:'Alias'; end |
#anchor_points ⇒ Array<MetaData::AssetBase>
Returns array of path anchor points in the presentation.
618 |
# File 'lib/ruic/presentation.rb', line 618 def anchor_points; find _type:'PathAnchorPoint'; end |
#asset_by_id(id) ⇒ MetaData::AssetBase
Find an asset in the presentation based on its internal XML identifier.
105 106 107 |
# File 'lib/ruic/presentation.rb', line 105 def asset_by_id( id ) (@graph_by_id[id] && asset_for_el( @graph_by_id[id] )) end |
#assets ⇒ Object
Get an array of all assets in the scene graph, in document order
136 137 138 |
# File 'lib/ruic/presentation.rb', line 136 def assets @graph_by_id.map{ |id,graph_element| asset_for_el(graph_element) } end |
#at(path, root = @graph) ⇒ MetaData::AssetBase Also known as: /
Find an element or asset in this presentation by scripting path.
- If
rootis supplied, the path is resolved relative to that asset. - If
rootis not supplied, the path is resolved as a root-level path.
300 301 302 303 304 305 306 307 308 309 |
# File 'lib/ruic/presentation.rb', line 300 def at(path,root=@graph) name,path = path.split('.',2) root = root.el if root.respond_to?(:el) el = case name when 'parent' then root==@scene ? nil : root.parent when 'Scene' then @scene else root.element_children.find{ |el| asset_for_el(el).name==name } end path ? at(path,el) : asset_for_el(el) if el end |
#attribute_linked?(asset, attribute_name) ⇒ Boolean
Returns true if this asset's attribute is linked on the master slide.
445 446 447 448 |
# File 'lib/ruic/presentation.rb', line 445 def attribute_linked?( asset, attribute_name ) graph_element = asset.el !(@addsets_by_graph[graph_element] && @addsets_by_graph[graph_element][1] && @addsets_by_graph[graph_element][1].key?(attribute_name)) end |
#behaviors ⇒ Array<MetaData::AssetBase>
Returns array of behavior elements in the presentation.
609 |
# File 'lib/ruic/presentation.rb', line 609 def behaviors; find _type:'Behavior'; end |
#cameras ⇒ Array<MetaData::AssetBase>
Returns array of cameras in the presentation.
586 |
# File 'lib/ruic/presentation.rb', line 586 def cameras; find _type:'Camera'; end |
#child_assets(parent_asset) ⇒ Array<MetaData::AssetBase>
Returns array of scene graph children of the specified asset.
131 132 133 |
# File 'lib/ruic/presentation.rb', line 131 def child_assets( parent_asset ) parent_asset.el.element_children.map{ |child| asset_for_el(child) } end |
#components ⇒ Array<MetaData::AssetBase>
Returns array of components in the presentation (not including the Scene).
592 |
# File 'lib/ruic/presentation.rb', line 592 def components; find _type:'Component'; end |
#effects ⇒ Array<MetaData::AssetBase>
Returns array of effects in the presentation.
580 |
# File 'lib/ruic/presentation.rb', line 580 def effects; find _type:'Effect'; end |
#errors ⇒ Array<String>
Returns an array (possibly empty) of all errors in this presentation.
274 275 276 |
# File 'lib/ruic/presentation.rb', line 274 def errors @errors end |
#errors? ⇒ Boolean
Returns true if there any errors with the presentation.
269 270 271 |
# File 'lib/ruic/presentation.rb', line 269 def errors? (!errors.empty?) end |
#find(criteria = {}) {|asset, index| ... } ⇒ Array<MetaData::AssetBase>
Find assets in this presentation matching criteria.
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/ruic/presentation.rb', line 547 def find(criteria={},&block) index = -1 start = criteria.key?(:_under) ? criteria.delete(:_under).el : @graph [].tap do |result| start.xpath('./descendant::*').each do |el| asset = asset_for_el(el) next unless criteria.all? do |att,val| case att when :_type then el.name == val when :_slide then (asset,val) when :_master then master?(asset)==val else if asset.properties[att.to_s] value = asset[att.to_s].value case val when Regexp then val =~ value.to_s when Numeric then (val-value).abs < 0.001 when Array then value.to_a.zip(val).map{ |a,b| !b || (a-b).abs<0.001 }.all? else value == val end end end end yield asset, index+=1 if block_given? result << asset end end end |
#generate_custom_classes ⇒ nil
Scan the .uip for custom classes that will be needed to generate assets. Called once during initial load of the file.
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 |
# File 'lib/ruic/presentation.rb', line 46 def generate_custom_classes # TODO: this method assumes an application to find the metadata on; the metadata should be part of this class instance instead, shared with the app when present parent_class_name = { 'CustomMaterial' => 'MaterialBase', 'Effect' => 'Effect', 'Behavior' => 'Behavior', 'RenderPlugin' => 'RenderPlugin' } @class_by_ref = {} @doc.xpath('/UIP/Project/Classes/*').each do |reference| path = absolute_path( reference['sourcepath'] ) next unless File.exist?( path ) parent_class = app..by_name[ parent_class_name[reference.name] ] raise "Error, unsupported custom class #{reference.name}" unless parent_class parent_props = parent_class.properties new_defaults = Hash[ reference.attributes.map{ |name,attr| [name,attr.value] }.select{ |name,val| parent_props[name] } ] property_el = case reference.name when 'CustomMaterial', 'Effect', 'RenderPlugin' doc = Nokogiri.XML(File.read(path,encoding:'utf-8')) doc.at('/*/MetaData') || doc.at('/*/metadata') # Some render plugins in the wild use lower-case tag name :/ when 'Behavior' lua = File.read(path,encoding:'utf-8') = lua[ /--\[\[(.+?)(?:--)?\]\]/m, 1 ] Nokogiri.XML("<MetaData>#{}</MetaData>").root end @class_by_ref[ "##{reference['id']}" ] = app..create_class( property_el, parent_class, reference.name, new_defaults ) end nil end |
#get_attribute(asset, attr_name, slide_name_or_index) ⇒ Object
Fetch the value of an asset's attribute on a particular slide. Slide 0 is the Master Slide, slide 1 is the first non-master slide.
This method is used internally by assets; accessing attributes directly from the asset is generally more appropriate.
327 328 329 330 331 332 333 334 |
# File 'lib/ruic/presentation.rb', line 327 def get_attribute( asset, attr_name, ) graph_element = asset.el ((addsets=@addsets_by_graph[graph_element]) && ( # State (slide) don't have any addsets ( addsets[] && addsets[][attr_name] ) || # Try for a Set on the specific slide ( addsets[0] && addsets[0][attr_name] ) # …else try the master slide ) || graph_element[attr_name]) # …else try the graph # TODO: handle animation (child of addset) end |
#groups ⇒ Array<MetaData::AssetBase>
Returns array of groups in the presentation.
583 |
# File 'lib/ruic/presentation.rb', line 583 def groups; find _type:'Group'; end |
#has_slide?(asset, slide_name_or_index) ⇒ Boolean
Returns true if the asset exists on the supplied slide.
425 426 427 428 429 430 431 432 433 |
# File 'lib/ruic/presentation.rb', line 425 def ( asset, ) graph_element = asset.el if graph_element == @scene # The scene is never actually added, so we'll treat it just like the first add, which is on the master slide of the scene ( asset_for_el( @addsets_by_graph.first.first ), ) else @addsets_by_graph[graph_element][] || @addsets_by_graph[graph_element][0] end end |
#hierarchy(root = scene) ⇒ String
Returns a visual hierarchy under the specified asset.
625 626 627 628 629 630 631 632 |
# File 'lib/ruic/presentation.rb', line 625 def hierarchy( root=scene ) elide = ->(str){ str.length>64 ? str.sub(/(^.{30}).+?(.{30})$/,'\1...\2') : str } hier = UIC.tree_hierarchy(root){ |e| e.children } cols = hier.map{ |i,a| a ? [ [i,a.name].join, a.type, elide[a.path] ] : [i,"",""] } maxs = cols.transpose.map{ |col| col.map(&:length).max } tmpl = maxs.map{ |n| "%-#{n}s" }.join(' ') cols.map{ |a| tmpl % a }.join("\n").extend(RUIC::SelfInspecting) end |
#image_paths ⇒ Array<String>
Returns array of all image paths referenced by this presentation.
171 172 173 |
# File 'lib/ruic/presentation.rb', line 171 def image_paths image_usage.keys end |
#image_usage ⇒ Hash
Returns a mapping of image paths to arrays of the assets referencing them.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ruic/presentation.rb', line 141 def image_usage # TODO: this returns the same asset multiple times, with no indication of which property is using it; should switch to an Asset/Property pair, or some such. asset_types = app..by_name.values + @class_by_ref.values image_properties_by_type = asset_types.flat_map do |type| type.properties.values .select{ |property| property.type=='Image' || property.type == 'Texture' } .map{ |property| [type,property] } end.group_by(&:first).tap{ |x| x.each{ |t,a| a.map!(&:last) } } Hash[ assets.each_with_object({}) do |asset,usage| if properties = image_properties_by_type[asset.class] properties.each do |property| asset[property.name].values.compact.each do |value| value = value['sourcepath'] if property.type=='Image' unless value.nil? || value.empty? value = value.gsub('\\','/').sub(/^.\//,'') usage[value] ||= [] usage[value] << asset end end end end end.sort_by do |path,assets| parts = path.downcase.split '/' [ parts.length, parts ] end ].tap{ |h| h.extend(UIC::PresentableHash) } end |
#images ⇒ Array<MetaData::AssetBase>
Returns array of image elements in the presentation.
606 |
# File 'lib/ruic/presentation.rb', line 606 def images; find _type:'Image'; end |
#layers ⇒ Array<MetaData::AssetBase>
Returns array of layers in the presentation.
577 |
# File 'lib/ruic/presentation.rb', line 577 def layers; find _type:'Layer'; end |
#lights ⇒ Array<MetaData::AssetBase>
Returns array of lights in the presentation.
589 |
# File 'lib/ruic/presentation.rb', line 589 def lights; find _type:'Light'; end |
#master?(asset) ⇒ Boolean
Returns true if the asset is added on the master slide.
490 491 492 493 |
# File 'lib/ruic/presentation.rb', line 490 def master?(asset) graph_element = asset.el (graph_element == @scene) || !!(@addsets_by_graph[graph_element] && @addsets_by_graph[graph_element][0]) end |
#materials ⇒ Array<MetaData::AssetBase>
Returns array of materials in the presentation (includes Referenced and Custom Materials).
599 600 601 602 603 |
# File 'lib/ruic/presentation.rb', line 599 def materials # Loop through all assets so that the resulting array of multiple sub-classes is in scene graph order material = app..by_name['MaterialBase'] find.select{ |asset| asset.is_a?(material) } end |
#models ⇒ Array<MetaData::AssetBase> Also known as: meshes
Returns array of model nodes in the presentation.
595 |
# File 'lib/ruic/presentation.rb', line 595 def models; find _type:'Model'; end |
#on_doc_loaded ⇒ nil
Load information for the presentation from disk.
If you supply a path to a .uip file when creating the presentation
this method is automatically called.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruic/presentation.rb', line 25 def on_doc_loaded @graph = @doc.at('Graph') @scene = @graph.at('Scene') @logic = @doc.at('Logic') generate_custom_classes rebuild_caches_from_document nil end |
#owning_component(asset) ⇒ MetaData::AssetBase
Returns the component (or Scene) asset that owns the supplied asset.
379 380 381 |
# File 'lib/ruic/presentation.rb', line 379 def owning_component( asset ) asset_for_el( owning_component_element( asset.el ) ) end |
#parent_asset(child_asset) ⇒ MetaData::AssetBase
Returns the scene graph parent of the child asset, or nil for the Scene.
121 122 123 124 125 126 |
# File 'lib/ruic/presentation.rb', line 121 def parent_asset( child_asset ) child_graph_el = child_asset.el unless child_graph_el==@scene || child_graph_el.parent.nil? asset_for_el( child_graph_el.parent ) end end |
#path_to(asset, from_asset = nil) ⇒ String
Generate the script path for an asset in the presentation.
- If
from_assetis supplied the path will be relative to that asset (e.g."parent.parent.Group.Model"). - If
from_assetis omitted the path will be absolute (e.g."Scene.Layer.Group.Model").
This is used internally by MetaData::AssetBase#path and MetaData::AssetBase#path_to; those methods are usually more convenient to use.
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 |
# File 'lib/ruic/presentation.rb', line 240 def path_to( asset, from_asset=nil ) el = asset.el to_parts = if el.ancestors('Graph') [].tap{ |parts| until el==@graph parts.unshift asset_for_el(el).name el = el.parent end } end if from_asset && from_asset.el.ancestors('Graph') from_el = from_asset.el from_parts = [].tap{ |parts| until from_el==@graph parts.unshift asset_for_el(from_el).name from_el = from_el.parent end } until to_parts.empty? || from_parts.empty? || to_parts.first!=from_parts.first to_parts.shift from_parts.shift end to_parts.unshift *(['parent']*from_parts.length) end to_parts.join('.') end |
#paths ⇒ Array<MetaData::AssetBase>
Returns array of path nodes in the presentation.
615 |
# File 'lib/ruic/presentation.rb', line 615 def paths; find _type:'Path'; end |
#rebuild_caches_from_document ⇒ nil
Update the presentation to be in-sync with the document.
Must be called whenever the in-memory representation of the XML document is changed.
Called automatically by all necessary methods; only necessary if script (dangerously)
manipulates the .doc of the presentation directly.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ruic/presentation.rb', line 82 def rebuild_caches_from_document @graph_by_id = {} @scene.traverse{ |x| @graph_by_id[x['id']]=x if x.is_a?(Nokogiri::XML::Element) } @graph_by_addset = {} @addsets_by_graph = {} = {} @logic.xpath('.//Add|.//Set').each do |addset| graph = @graph_by_id[addset['ref'][1..-1]] @graph_by_addset[addset] = graph @addsets_by_graph[graph] ||= {} = addset.parent name = ['name'] index = name == 'Master Slide' ? 0 : ([] ||= (.index('State') + 1)) @addsets_by_graph[graph][name] = addset @addsets_by_graph[graph][index] = addset end nil end |
#referenced_files ⇒ Array<String>
Which files are used by the presentation.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ruic/presentation.rb', line 190 def referenced_files ( [file] + %w[sourcepath importfile].flat_map do |att| find(att=>/./).flat_map do |asset| asset[att].values.compact.map do |path| path.sub!(/#.+/,'') absolute_path(path) unless path.empty? end.compact end end + find.flat_map do |asset| asset.properties.select{ |name,prop| prop.type=='Texture' }.flat_map do |name,prop| asset[name].values.compact.uniq.map{ |path| absolute_path(path) } end end + find(_type:'Text').flat_map do |asset| asset['font'].values.compact.map{ |font| absolute_path(font) } end + @doc.xpath('/UIP/Project/Classes/*/@sourcepath').map{ |att| absolute_path att.value } ).uniq end |
#replace_asset(existing_asset, new_type, attributes = {}) ⇒ MetaData::AssetBase
Replace an existing asset with a new kind of asset.
476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/ruic/presentation.rb', line 476 def replace_asset( existing_asset, new_type, attributes={} ) old_el = existing_asset.el new_el = old_el.replace( "<#{new_type}/>" ).first attributes['id'] = old_el['id'] attributes.each{ |att,val| new_el[att.to_s] = val } asset_for_el( new_el ).tap do |new_asset| unsupported_attributes = ".//*[name()='Add' or name()='Set'][@ref='##{old_el['id']}']/@*[name()!='ref' and #{new_asset.properties.keys.map{|p| "name()!='#{p}'"}.join(' and ')}]" @logic.xpath(unsupported_attributes).remove rebuild_caches_from_document end end |
#scene ⇒ MetaData::Scene
Returns the root scene asset for the presentation.
214 215 216 |
# File 'lib/ruic/presentation.rb', line 214 def scene asset_for_el( @scene ) end |
#set_attribute(asset, property_name, slide_name_or_index, str) ⇒ Object
Set the value of an asset's attribute on a particular slide. Slide 0 is the Master Slide, slide 1 is the first non-master slide.
This method is used internally by assets; accessing attributes directly from the asset is generally more appropriate.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/ruic/presentation.rb', line 354 def set_attribute( asset, property_name, , str ) graph_element = asset.el if attribute_linked?( asset, property_name ) if @addsets_by_graph[graph_element] @addsets_by_graph[graph_element][0][property_name] = str else raise "TODO" end else if @addsets_by_graph[graph_element] if @addsets_by_graph[graph_element][][property_name] = str else master = ( graph_element ) = master.xpath('count(./State)').to_i 0.upto().each{ |idx| set_attribute(asset,property_name,idx,str) } end else raise "TODO" end end end |
#slide_index(asset) ⇒ Integer
Returns the index of the first slide where an asset is added (0 for master, non-zero for non-master).
111 112 113 114 115 116 |
# File 'lib/ruic/presentation.rb', line 111 def (asset) # TODO: probably faster to .find the first @addsets_by_graph id = asset.el['id'] = @logic.at(".//Add[@ref='##{id}']/..") ( ? .xpath('count(ancestor::State) + count(preceding-sibling::State[ancestor::State])').to_i : 0) # the Scene is never added end |
#slides_for(asset) ⇒ SlideCollection
Returns an array-like collection of all slides that the asset is available on.
411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/ruic/presentation.rb', line 411 def ( asset ) graph_element = asset.el @slides_for[graph_element] ||= begin = [] master = ( graph_element ) << [master,0] if graph_element==@scene || (@addsets_by_graph[graph_element] && @addsets_by_graph[graph_element][0]) .concat( master.xpath('./State').map.with_index{ |el,i| [el,i+1] } ) .map!{ |el,idx| @slides_by_el[el] ||= app..new_instance(self,el).tap{ |s| s.index=idx; s.name=el['name'] } } UIC::SlideCollection.new( ) end end |
#texts ⇒ Array<MetaData::AssetBase>
Returns array of text elements in the presentation.
621 |
# File 'lib/ruic/presentation.rb', line 621 def texts; find _type:'Text'; end |
#to_xml ⇒ String
Returns the xml representation of this presentation. Formatted to match UI Composer Studio's formatting as closely as possible (for minimal diffs after update).
37 38 39 40 41 |
# File 'lib/ruic/presentation.rb', line 37 def to_xml doc.to_xml( indent:1, indent_text:"\t" ) .gsub( %r{(<\w+(?: [\w:]+="[^"]*")*)(/?>)}i, '\1 \2' ) .sub('"?>','" ?>') end |
#unlink_attribute(asset, attribute_name) ⇒ Boolean
Unlinks a master attribute, yielding distinct values on each slide. If the asset is not on the master slide, or the attribute is already unlinked, no change occurs.
455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/ruic/presentation.rb', line 455 def unlink_attribute(asset,attribute_name) graph_element = asset.el if master?(asset) && attribute_linked?(asset,attribute_name) master_value = get_attribute( asset, attribute_name, 0 ) ( asset ).to_ary[1..-1].each do || addset = .el.at_xpath( ".//*[@ref='##{graph_element['id']}']" ) || .el.add_child("<Set ref='##{graph_element['id']}'/>").first addset[attribute_name] = master_value end rebuild_caches_from_document true else false end end |