summaryrefslogtreecommitdiff
path: root/lib/tag.rb
blob: 0144bb09bbc679e6d0a901025219c659c49d3bfd (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Virgil
  module Tag
    class Doctype
      def initialize(&block)
        @tag =  "<!DOCTYPE " +
                self.instance_eval(&block) +
                ">"
      end
      def to_s
        @tag
      end
    end
    class Comment
      def initialize(&block)
        @tag =  "<!--" +
                self.instance_eval(&block) +
                "-->"
      end
      def to_s
        @tag
      end
    end

    class Common
      def initialize(tag, attrs, &block)
        @tag =  "<#{tag}" +
                Utils.unfold(attrs) +
                ">" +
                self.instance_eval(&block) +
                "</#{tag}>"
      end
      def to_s
        @tag
      end
      def subtag(attrs = {})
        Common.new(__callee__, attrs, &Proc.new).to_s
      end
      def subtagsingle(attrs = {})
        Common_Single.new(__callee__, attrs).to_s
      end
    end
    class Common_Single
      def initialize(tag, attrs)
        @tag =  "<#{tag}" +
                Utils.unfold(attrs) +
                ">"
      end
      def to_s
        @tag
      end
    end

    class Map < Common
      alias :area :subtagsingle
    end

    class Head < Common
      alias :link :subtagsingle
      alias :title :subtag
    end
  end
end