class Inkcite::Renderer::Style
Constants
- PREFIXABLE_KEYS
Array of CSS attributes that must be prefixed (e.g. transform and animation)
Public Class Methods
needs_prefixing?(key)
click to toggle source
# File lib/inkcite/facade/style.rb, line 74 def self.needs_prefixing? key PREFIXABLE_KEYS.include?(key.to_sym) end
new(name, ctx, styles={})
click to toggle source
# File lib/inkcite/facade/style.rb, line 5 def initialize name, ctx, styles={} @name = name @ctx = ctx @styles = styles end
Public Instance Methods
[](key)
click to toggle source
# File lib/inkcite/facade/style.rb, line 13 def [] key @styles[key] end
[]=(key, val)
click to toggle source
# File lib/inkcite/facade/style.rb, line 17 def []= key, val @styles[key] = val end
blank?()
click to toggle source
# File lib/inkcite/facade/style.rb, line 21 def blank? @styles.blank? end
to_css(allowed_prefixes=nil)
click to toggle source
# File lib/inkcite/facade/style.rb, line 25 def to_css allowed_prefixes=nil "#{@name} { #{to_inline_css(allowed_prefixes)} }" end
to_inline_css(allowed_prefixes=nil)
click to toggle source
# File lib/inkcite/facade/style.rb, line 29 def to_inline_css allowed_prefixes=nil # Inherit the list of allowed prefixes from the context if # none were provided. Otherwise, make sure we're working # with an array. if allowed_prefixes.nil? allowed_prefixes = @ctx.prefixes else allowed_prefixes = [*allowed_prefixes] end # This will hold a copy of the key and values including # all keys with prefixes. _styles = {} # A reusable array indicating no prefixing is necessary. no_prefixes = [''] @styles.each_pair do |key, val| # Determine which list of prefixes are needed based on the # original key (e.g. :transform) - or use the list of # non-modifying prefixes. prefixes = if Inkcite::Renderer::Style.needs_prefixing?(key) allowed_prefixes else no_prefixes end # Iterate through each prefix and create a hybrid key. Then # add the styles to the temporary list. prefixes.each do |prefix| prefixed_key = "#{prefix}#{key}".to_sym _styles[prefixed_key] = val end end Renderer.render_styles(_styles) end
to_s()
click to toggle source
# File lib/inkcite/facade/style.rb, line 70 def to_s @name.blank? ? to_inline_css : to_css end