Sha256: e3fc9a27a354000ac808f64373a8a9d421b52811bade3d0f18d92d9906b84eee

Contents?: true

Size: 775 Bytes

Versions: 11

Compression:

Stored size: 775 Bytes

Contents

class SCSSBeautifier::Formatters::TrailingZero < Sass::Tree::Visitors::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

11 entries across 11 versions & 1 rubygems

Version Path
scss_beautifier-0.1.11 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.10 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.8 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.7 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.6 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.5 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.4 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.3 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.2 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.1 lib/scss_beautifier/formatters/trailing_zero.rb
scss_beautifier-0.1.0 lib/scss_beautifier/formatters/trailing_zero.rb