Sha256: a00c44190934298c95d287b61f1aab4fa19034581e522e748e2b39f54ffba58c

Contents?: true

Size: 975 Bytes

Versions: 40

Compression:

Stored size: 975 Bytes

Contents

# frozen_string_literal: true
module Hamlit
  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

40 entries across 40 versions & 1 rubygems

Version Path
hamlit-3.0.3-java lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.3 lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.2-java lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.2 lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.1-java lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.1 lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.0-java lib/hamlit/compiler/comment_compiler.rb
hamlit-3.0.0 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.16.2-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.16.2 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.16.1-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.16.1 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.16.0-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.16.0 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.15.2-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.15.2 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.15.1-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.15.1 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.15.0-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.15.0 lib/hamlit/compiler/comment_compiler.rb