Sha256: 87957ae7a57fe52f30cdb616a2b2dcafd99d644eb11fa0d2738f8fd74badd918

Contents?: true

Size: 973 Bytes

Versions: 20

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true
module Haml
  class Compiler
    class CommentCompiler
      def compile(node, &block)
        if node.value[:conditional]
          compile_conditional_comment(node, &block)
        else
          compile_html_comment(node, &block)
        end
      end

      private

      def compile_html_comment(node, &block)
        if node.children.empty?
          [:html, :comment, [:static, " #{node.value[:text]} "]]
        else
          [:html, :comment, yield(node)]
        end
      end

      def compile_conditional_comment(node, &block)
        condition = node.value[:conditional]
        if node.value[:conditional] =~ /\A\[(\[*[^\[\]]+\]*)\]/
          condition = $1
        end

        content =
          if node.children.empty?
            [:static, " #{node.value[:text]} "]
          else
            yield(node)
          end
        [:html, :condcomment, condition, content, node.value[:revealed]]
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
haml-6.0.7-java lib/haml/compiler/comment_compiler.rb
haml-6.0.7 lib/haml/compiler/comment_compiler.rb
haml-6.0.6-java lib/haml/compiler/comment_compiler.rb
haml-6.0.6 lib/haml/compiler/comment_compiler.rb
haml-6.0.5-java lib/haml/compiler/comment_compiler.rb
haml-6.0.5 lib/haml/compiler/comment_compiler.rb
haml-6.0.4-java lib/haml/compiler/comment_compiler.rb
haml-6.0.4 lib/haml/compiler/comment_compiler.rb
haml-6.0.3-java lib/haml/compiler/comment_compiler.rb
haml-6.0.3 lib/haml/compiler/comment_compiler.rb
haml-6.0.2-java lib/haml/compiler/comment_compiler.rb
haml-6.0.2 lib/haml/compiler/comment_compiler.rb
haml-6.0.1-java lib/haml/compiler/comment_compiler.rb
haml-6.0.1 lib/haml/compiler/comment_compiler.rb
haml-6.0.0-java lib/haml/compiler/comment_compiler.rb
haml-6.0.0 lib/haml/compiler/comment_compiler.rb
haml-6.0.0.beta.2-java lib/haml/compiler/comment_compiler.rb
haml-6.0.0.beta.2 lib/haml/compiler/comment_compiler.rb
haml-6.0.0.beta.1-java lib/haml/compiler/comment_compiler.rb
haml-6.0.0.beta.1 lib/haml/compiler/comment_compiler.rb