Sha256: 0cfcdb113960e387e5134fd1cec72a7920c3c79577c0d23561506cf416e18100

Contents?: true

Size: 781 Bytes

Versions: 8

Compression:

Stored size: 781 Bytes

Contents

class SCSSBeautifier::Formatters::TrailingZero < SCSSBeautifier::Formatters::Base
  def visit_prop(node)
    check_trailing_zero(node)
    visit_children(node)
  end

  private

  FRACTIONAL_DIGIT_REGEX = /^-?(\d*\.\d+[a-zA-Z]*)/

  def check_trailing_zero(node)
    return unless number = node.value.to_s[FRACTIONAL_DIGIT_REGEX, 1]

    return unless match = /^(\d*\.(?:[0-9]*[1-9]|[1-9])*)0+([a-zA-Z]*)$/.match(number)

    fixed_number = match[1]
    extension = match[2]

    # Handle special case of 0 being the only trailing digit
    fixed_number = fixed_number[0..-2] if fixed_number.end_with?('.')
    fixed_number = 0 if fixed_number.empty? # Handle ".0" -> "0"
    node.instance_variable_set(:@value, Sass::Script::Value::String.new(fixed_number + extension))
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
scss_beautifier-0.1.19 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.18 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.17 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.16 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.15 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.14 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.13 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.12 lib/scss_beautifier/formatters/trailing_zero.rb