Sha256: fda66fe394dc5ec9f870b03d6dec2c8c5f55947fe7802e648554ff51657fe270

Contents?: true

Size: 959 Bytes

Versions: 43

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true
module Haml
  class Compiler
    class DoctypeCompiler
      def initialize(options = {})
        @format = options[:format]
      end

      def compile(node)
        case node.value[:type]
        when 'xml'
          xml_doctype
        when ''
          html_doctype(node)
        else
          [:html, :doctype, node.value[:type]]
        end
      end

      private

      def html_doctype(node)
        version = node.value[:version] || :transitional
        case @format
        when :xhtml
          [:html, :doctype, version]
        when :html4
          [:html, :doctype, :transitional]
        when :html5
          [:html, :doctype, :html]
        else
          [:html, :doctype, @format]
        end
      end

      def xml_doctype
        case @format
        when :xhtml
          [:static, "<?xml version='1.0' encoding='utf-8' ?>\n"]
        else
          [:multi]
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
haml-6.2.2 lib/haml/compiler/doctype_compiler.rb
haml-6.2.1 lib/haml/compiler/doctype_compiler.rb
haml-6.2.0 lib/haml/compiler/doctype_compiler.rb
haml-6.1.4-java lib/haml/compiler/doctype_compiler.rb
haml-6.1.4 lib/haml/compiler/doctype_compiler.rb
haml-6.1.3-java lib/haml/compiler/doctype_compiler.rb
haml-6.1.3 lib/haml/compiler/doctype_compiler.rb
haml-6.1.2-java lib/haml/compiler/doctype_compiler.rb
haml-6.1.2 lib/haml/compiler/doctype_compiler.rb
haml-6.1.1-java lib/haml/compiler/doctype_compiler.rb
haml-6.1.1 lib/haml/compiler/doctype_compiler.rb
haml-6.1.0-java lib/haml/compiler/doctype_compiler.rb
haml-6.1.0 lib/haml/compiler/doctype_compiler.rb
haml-6.0.12-java lib/haml/compiler/doctype_compiler.rb
haml-6.0.12 lib/haml/compiler/doctype_compiler.rb
haml-6.0.11-java lib/haml/compiler/doctype_compiler.rb
haml-6.0.11 lib/haml/compiler/doctype_compiler.rb
haml-6.0.10-java lib/haml/compiler/doctype_compiler.rb
haml-6.0.10 lib/haml/compiler/doctype_compiler.rb
haml-6.0.9-java lib/haml/compiler/doctype_compiler.rb