Sha256: a9976a4b4b55107aff5f31ca711f4219ab79c04192e34dc3bb31b4f6516004fe

Contents?: true

Size: 733 Bytes

Versions: 21

Compression:

Stored size: 733 Bytes

Contents

module Liquidscript
  module ICR

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

    # @private
    class Sexp

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

      def output
        out(@compiler).strip
      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 }.join(' '),
            ")"].join
          @depth -= 1
          body
        else
          body = v.to_s.gsub(/\"/, "\\\"")

          if body.include? " "
            "\"#{body}\""
          else
            body
          end
        end
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
liquidscript-0.6.5 lib/liquidscript/icr/sexp.rb
liquidscript-0.6.4 lib/liquidscript/icr/sexp.rb
liquidscript-0.6.3 lib/liquidscript/icr/sexp.rb
liquidscript-0.6.2 lib/liquidscript/icr/sexp.rb
liquidscript-0.6.1 lib/liquidscript/icr/sexp.rb
liquidscript-0.6.0 lib/liquidscript/icr/sexp.rb
liquidscript-0.5.1 lib/liquidscript/icr/sexp.rb
liquidscript-0.5.0 lib/liquidscript/icr/sexp.rb
liquidscript-0.4.1 lib/liquidscript/icr/sexp.rb
liquidscript-0.4.0 lib/liquidscript/icr/sexp.rb
liquidscript-0.3.1 lib/liquidscript/icr/sexp.rb
liquidscript-0.3.0 lib/liquidscript/icr/sexp.rb
liquidscript-0.2.1 lib/liquidscript/icr/sexp.rb
liquidscript-0.2.0 lib/liquidscript/icr/sexp.rb
liquidscript-0.1.5 lib/liquidscript/icr/sexp.rb
liquidscript-0.1.4 lib/liquidscript/icr/sexp.rb
liquidscript-0.1.3 lib/liquidscript/icr/sexp.rb
liquidscript-0.1.2 lib/liquidscript/icr/sexp.rb
liquidscript-0.1.1 lib/liquidscript/icr/sexp.rb
liquidscript-0.1.0 lib/liquidscript/icr/sexp.rb