Sha256: a7e4a1c512355fd03c557d819f63ad40405859f23961bbc845be9cb24297cb3f

Contents?: true

Size: 1.22 KB

Versions: 22

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
    extend self

    def handle_interpolation(str)
      scan = StringScanner.new(str)
      yield scan while scan.scan(/(.*?)(\\*)\#\{/)
      scan.rest
    end

    def 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 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

22 entries across 22 versions & 2 rubygems

Version Path
gohanlonllc-haml-2.1.0.20080513000000 lib/haml/shared.rb
gohanlonllc-haml-2.1.0 lib/haml/shared.rb
haml-edge-2.1.11 lib/haml/shared.rb
haml-edge-2.1.10 lib/haml/shared.rb
haml-edge-2.1.12 lib/haml/shared.rb
haml-edge-2.1.4 lib/haml/shared.rb
haml-edge-2.1.14 lib/haml/shared.rb
haml-edge-2.1.13 lib/haml/shared.rb
haml-edge-2.1.15 lib/haml/shared.rb
haml-edge-2.1.16 lib/haml/shared.rb
haml-edge-2.1.17 lib/haml/shared.rb
haml-edge-2.1.18 lib/haml/shared.rb
haml-edge-2.1.19 lib/haml/shared.rb
haml-edge-2.1.2 lib/haml/shared.rb
haml-edge-2.1.20 lib/haml/shared.rb
haml-edge-2.1.21 lib/haml/shared.rb
haml-edge-2.1.3 lib/haml/shared.rb
haml-edge-2.1.5 lib/haml/shared.rb
haml-edge-2.1.6 lib/haml/shared.rb
haml-edge-2.1.7 lib/haml/shared.rb