Sha256: 1f302755eecf5d2bba2cc2f7731128838605c67d7f9c63357f75561a2817f782

Contents?: true

Size: 945 Bytes

Versions: 5

Compression:

Stored size: 945 Bytes

Contents

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

5 entries across 5 versions & 1 rubygems

Version Path
hamlit-2.12.0-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.12.0 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.11.1 lib/hamlit/compiler/comment_compiler.rb
hamlit-2.11.0-java lib/hamlit/compiler/comment_compiler.rb
hamlit-2.11.0 lib/hamlit/compiler/comment_compiler.rb