File: doctype_compiler.rb

package info (click to toggle)
ruby-hamlit 2.15.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,996 kB
  • sloc: ruby: 10,548; ansic: 536; sh: 23; makefile: 8
file content (46 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
module Hamlit
  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