class Inkcite::Renderer::SpecialEffect::EffectContext
A convenience class for accessing the attributes that are common to special effects like snow and sparkle.
Attributes
Expose the opt and ctx attributes
Expose the opt and ctx attributes
Public Class Methods
# File lib/inkcite/renderer/special_effect.rb, line 20 def initialize tag, opt, ctx, defaults={} @tag = tag # Merge the provided opts over the defaults to ensure the values # provided by the developer take precedence. @opt = defaults.merge(opt) @ctx = ctx # Request a unique ID for this special effect which will be used # to uniquely identify the classes and animations associated with # this special effect. @uuid = ctx.unique_id(:sfx) # Will hold all of the Animations while the children are # assembled and then added to the styles array at the end # so that all keyframes are together in the source. @animations = [] end
Public Instance Methods
# File lib/inkcite/renderer/special_effect.rb, line 41 def all_children_class_name obfuscate_class_names? ? "sfx#{@uuid}c" : "#{@tag}#{@uuid}-children" end
# File lib/inkcite/renderer/special_effect.rb, line 45 def animation_class_name child_index, suffix=nil base = obfuscate_class_names? ? "#{@tag}#{@uuid}-anim#{child_index + 1}" : "sfx#{@uuid}a#{child_index + 1}" unless suffix.blank? base << '-' base << (obfuscate_class_names? ? suffix[0] : suffix) end base end
# File lib/inkcite/renderer/special_effect.rb, line 56 def child_class_name child_index obfuscate_class_names? ? "sfx#{@uuid}c#{child_index + 1}" : "#{@tag}#{@uuid}-child#{child_index + 1}" end
# File lib/inkcite/renderer/special_effect.rb, line 60 def color Renderer.hex(@opt[:color]) end
Returns the number of children in the special effects - e.g. the number of snowflakes or sparkles in the animation. :flakes and :sparks are technically deprecated.
# File lib/inkcite/renderer/special_effect.rb, line 67 def count @opt[:count].to_i end
# File lib/inkcite/renderer/special_effect.rb, line 71 def equal_distribution range, qty # Space the children generally equally across the width of the # container div. Random distribution sometimes ends up with # children clumped at one edge or the other. spacing = (range.last - range.first) / qty.to_f # Now build up a pool of equally-spaced starting positions. # TODO: This is probably a perfect spot to use inject() start_left = range.first + (spacing / 2.0) # This array will hold all of the positions positions = [start_left] # Now, for the remaining positions needed, adjust by the # spacing and push onto the list. (qty - 1).times { |f| positions << start_left += spacing } positions.collect { |p| p.round(0) } end
# File lib/inkcite/renderer/special_effect.rb, line 92 def height @opt[:height].to_i end
# File lib/inkcite/renderer/special_effect.rb, line 96 def insets @opt[:insets].to_i end
# File lib/inkcite/renderer/special_effect.rb, line 100 def max_opacity @opt[OPACITY_MAX].to_f end
# File lib/inkcite/renderer/special_effect.rb, line 104 def max_size @opt[SIZE_MAX].to_i end
# File lib/inkcite/renderer/special_effect.rb, line 112 def max_speed @opt[SPEED_MAX].to_f end
# File lib/inkcite/renderer/special_effect.rb, line 108 def min_opacity @opt[OPACITY_MIN].to_f end
# File lib/inkcite/renderer/special_effect.rb, line 116 def min_size @opt[SIZE_MIN].to_i end
# File lib/inkcite/renderer/special_effect.rb, line 120 def min_speed @opt[SPEED_MIN].to_f end
# File lib/inkcite/renderer/special_effect.rb, line 124 def obfuscate_class_names? @ctx.production? end
# File lib/inkcite/renderer/special_effect.rb, line 128 def opacity_range (min_opacity..max_opacity) end
# File lib/inkcite/renderer/special_effect.rb, line 181 def position_range min = POSITION_FLOOR + insets max = POSITION_CEIL - insets (min..max) end
Creates a permanent list of positions (as percentages of the wrap container's total width) which can be used for starting or ending position to equally space animated elements.
# File lib/inkcite/renderer/special_effect.rb, line 190 def positions_x @positions_x ||= equal_distribution(position_range, count) end
Creates a permanent list of positions (as percentages of the wrap container's total height) which can be used for starting or ending position to equally space animated elements.
# File lib/inkcite/renderer/special_effect.rb, line 197 def positions_y @positions_y ||= equal_distribution(position_range, count) end
# File lib/inkcite/renderer/special_effect.rb, line 132 def rand_opacity rand(opacity_range).round(1) end
# File lib/inkcite/renderer/special_effect.rb, line 136 def rand_rotation rand(rotation_range).round(1) end
# File lib/inkcite/renderer/special_effect.rb, line 140 def rand_size rand(size_range).round(0) end
# File lib/inkcite/renderer/special_effect.rb, line 144 def rand_speed rand(speed_range).round(1) end
# File lib/inkcite/renderer/special_effect.rb, line 148 def rotation? @opt[:rotate] || @opt[:rotation] end
# File lib/inkcite/renderer/special_effect.rb, line 152 def rotation_range (-270..270) end
# File lib/inkcite/renderer/special_effect.rb, line 156 def same_size? min_size == max_size end
# File lib/inkcite/renderer/special_effect.rb, line 160 def size_range (min_size..max_size) end
# File lib/inkcite/renderer/special_effect.rb, line 164 def speed_range (min_speed..max_speed) end
An array of source images to be applied to the children or an empty array if there are none.
# File lib/inkcite/renderer/special_effect.rb, line 170 def src @src ||= begin # Check to see if a source image has been specified for the snowflakes. # Split on a comma to treat the source listing as an array. Then verify # that each of the referenced images exists @opt[:src].to_s.split(',').select { |img| @ctx.assert_image_exists(img) } end end
# File lib/inkcite/renderer/special_effect.rb, line 201 def start_time child_index ((time / count) * child_index).round(1) end
# File lib/inkcite/renderer/special_effect.rb, line 205 def time @opt[:time].to_f end
Amount of time between each child starting its animation to create a even but varied distribution.
# File lib/inkcite/renderer/special_effect.rb, line 211 def time_interval time / count.to_f end
Returns true if CSS animations should be limited to webkit- powered email clients.
# File lib/inkcite/renderer/special_effect.rb, line 217 def webkit_only? !(@ctx.development? || @ctx.browser?) end
# File lib/inkcite/renderer/special_effect.rb, line 221 def wrap_class_name obfuscate_class_names? ? "sfx#{@uuid}w" : "#{@tag}#{@uuid}-wrap" end