Sha256: c6f9faafd0e57d9dc4ca11f3edef5a687dc8e0303e753d4ae880539724accb45

Contents?: true

Size: 825 Bytes

Versions: 8

Compression:

Stored size: 825 Bytes

Contents

module Liquidscript
  module ICR

    class ::Array; def to_sexp; Sexp.new(self); end; end

    # @private
    class Sexp

      def initialize(compiler)
        @compiler = compiler
        @depth = 0
      end

      def output
        out(@compiler).strip
      end

      def to_s
        output
      end

      private

      def out(v)
        if v.is_a?(Representable) || v.is_a?(Array)
          @depth += 1
          body = ["\n", " " * @depth, "(",
            v.to_a.map {|d| out(d) }.compact.join(' '),
            ")"].join
          @depth -= 1
          body
        else
          body = v.to_s.gsub(/\"/, "\\\"")

          if body.include? " "
            "\"#{body}\""
          elsif body.length == 0
            nil
          else
            body
          end
        end
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
liquidscript-0.7.12 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.11 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.10 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.9 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.8 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.7 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.6 lib/liquidscript/icr/sexp.rb
liquidscript-0.7.5 lib/liquidscript/icr/sexp.rb