Sha256: 5f98ab4098c886bde567f09b1c1ef726b2256c2a2e20507af454dbc961954f44

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

require 'strscan'

# :stopdoc:
module Haml
  # This module contains functionality that's shared across Haml and Sass.
  module Shared
    def self.handle_interpolation(str)
      scan = StringScanner.new(str)
      yield scan while scan.scan(/(.*?)(\\*)\#\{/)
      scan.rest
    end

    def self.balance(scanner, start, finish, count = 0)
      str = ''
      scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
      regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
      while scanner.scan(regexp)
        str << scanner.matched
        count += 1 if scanner.matched[-1] == start
        count -= 1 if scanner.matched[-1] == finish
        return [str.strip, scanner.rest] if count == 0
      end
    end

    def self.human_indentation(indentation, was = false)
      if !indentation.include?(?\t)
        noun = 'space'
      elsif !indentation.include?(?\s)
        noun = 'tab'
      else
        return indentation.inspect + (was ? ' was' : '')
      end

      singular = indentation.length == 1
      if was
        was = singular ? ' was' : ' were'
      else
        was = ''
      end

      "#{indentation.length} #{noun}#{'s' unless singular}#{was}"
    end
  end
end
# :startdoc:

Version data entries

10 entries across 10 versions & 6 rubygems

Version Path
honkster-haml-2.1.0 lib/haml/shared.rb
honkster-haml-2.1.1 lib/haml/shared.rb
jwhitmire-haml-2.1.0.1 lib/haml/shared.rb
jwhitmire-haml-2.1.0.2 lib/haml/shared.rb
jwhitmire-haml-2.1.0.3 lib/haml/shared.rb
wireframe-haml-2.1.0 lib/haml/shared.rb
wireframe-haml-2.1.1 lib/haml/shared.rb
haml-edge-2.1.1 lib/haml/shared.rb
merbjedi-haml-2.1.0 lib/haml/shared.rb
spree-0.8.0 vendor/gems/haml-2.1.0/lib/haml/shared.rb