Class: AnimateIt::AnimationSet
- Inherits:
-
Object
- Object
- AnimateIt::AnimationSet
- Defined in:
- lib/animate_it/animation.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #add(name, builder_block) ⇒ Object
-
#css_rules ⇒ Object
Emit
<style>block content with[data-anim="name"] { … }rules. -
#initialize ⇒ AnimationSet
constructor
A new instance of AnimationSet.
-
#vars_for(scene) ⇒ Object
Compute the per-frame CSS variable hash for the entire set, given the current local_frame plus a beats registry to resolve symbolic ranges.
Constructor Details
#initialize ⇒ AnimationSet
Returns a new instance of AnimationSet.
20 21 22 |
# File 'lib/animate_it/animation.rb', line 20 def initialize @elements = {} end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
18 19 20 |
# File 'lib/animate_it/animation.rb', line 18 def elements @elements end |
Instance Method Details
#add(name, builder_block) ⇒ Object
24 25 26 27 28 |
# File 'lib/animate_it/animation.rb', line 24 def add(name, builder_block) builder = AnimatableBuilder.new(name) builder.instance_eval(&builder_block) if builder_block @elements[name.to_sym] = AnimatableElement.new(name: name.to_sym, properties: builder.properties) end |
#css_rules ⇒ Object
Emit <style> block content with [data-anim="name"] { … } rules.
Generated once per AnimationSet (memoized).
45 46 47 |
# File 'lib/animate_it/animation.rb', line 45 def css_rules @css_rules ||= @elements.values.map { |element| rules_for(element) }.join("\n") end |
#vars_for(scene) ⇒ Object
Compute the per-frame CSS variable hash for the entire set, given the current local_frame plus a beats registry to resolve symbolic ranges.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/animate_it/animation.rb', line 32 def vars_for(scene) vars = {} @elements.each_value do |element| element.properties.each do |prop| value = compute_value(prop, scene) vars[var_key(element.name, prop.var_suffix)] = format_value(value, prop.unit) end end vars end |