Sha256: 7a4cb5490b31e12a17aacaea91ce6feb1028f108da3e635d7e99fc9d8b98a43f

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module Archetype::SassExtensions::Util::Hacks

  #
  # parse a CSS content string and format it for injection into innerText
  #
  # *Parameters*:
  # - <tt>$content</tt> {String} the CSS content string
  # *Returns*:
  # - {String} the processed string
  #
  def _ie_pseudo_content(content)
    content = helpers.to_str(content)
    # convert char codes (e.g. `\2079` -> `\u2079`)
    content.gsub!(/\\([\da-fA-F]{4})\s?/, ['\1'.hex].pack('U*'))
    # cleanup quotes
    content.gsub!(/\A"|"\Z/, '').gsub!(/\"/, '\\"')
    return identifier(content)
  end

  #
  # given a string of styles, convert it into a map
  #
  # *Parameters*:
  # - <tt>$string</tt> {String} the string to convert
  # *Returns*:
  # - {Map} the converted map of styles
  #
  def _style_string_to_map(string = '')
    # convert to string and strip all comments
    string = helpers.to_str(string, ' ').gsub(/\/\*(?!\*\/)*\*\//, '')
    # then split it on each rule and for each rule break it into it's key-value pairs
    styles = string.split(';').map do |rule|
      k, v = rule.split(':')
      [identifier(k), identifier(v)]
    end
    # then recompose the map
    return Sass::Script::Value::Map.new(Sass::Util.to_hash(styles))
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
archetype-1.0.0.alpha.5 lib/archetype/sass_extensions/functions/util/hacks.rb
archetype-1.0.0.alpha.4 lib/archetype/sass_extensions/functions/util/hacks.rb
archetype-1.0.0.alpha.3 lib/archetype/sass_extensions/functions/util/hacks.rb