Sha256: 83193a5bb8f0519b9589800da82e695f9848d8327ed8953fc750ede99832a84d

Contents?: true

Size: 688 Bytes

Versions: 9

Compression:

Stored size: 688 Bytes

Contents

##
# Extensions to sass's unit conversion and manipulation 
# functionality. 
# 
module Facades
  module SassExtensions
    module Conversions
      
      ##
      # Removes any unit values (px/em/rem etc)
      # from a number leaving just the numeric
      # representation.
      # 
      # @example Use unitless line heights
      #   line-height:numeric(1em)  #=> line-height:1
      # 
      def numeric(value)
        assert_type value, :Number
        return value if value.unitless?
        value = value.to_s.gsub(value.unit_str, '')
        value = value.to_f.denominator > 1 ? value.to_f : value.to_i
        Sass::Script::Number.new(value)
      end
      
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
facades-1.1.0 lib/facades/sass_extensions/conversions.rb
facades-1.0.9 lib/facades/sass_extensions/conversions.rb
facades-1.0.8 lib/facades/sass_extensions/conversions.rb
facades-1.0.6 lib/facades/sass_extensions/conversions.rb
facades-1.0.4 lib/facades/sass_extensions/conversions.rb
facades-1.0.3 lib/facades/sass_extensions/conversions.rb
facades-1.0.2 lib/facades/sass_extensions/conversions.rb
facades-1.0.1 lib/facades/sass_extensions/conversions.rb
facades-1.0.0 lib/facades/sass_extensions/conversions.rb