1+ # -----------------------------------------------------------------------
2+ # This file is part of MoonScript
3+ #
4+ # MoonSript is free software: you can redistribute it and/or modify
5+ # it under the terms of the GNU General Public License as published by
6+ # the Free Software Foundation, either version 3 of the License, or
7+ # (at your option) any later version.
8+ #
9+ # MoonSript is distributed in the hope that it will be useful,
10+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ # GNU General Public License for more details.
13+ #
14+ # You should have received a copy of the GNU General Public License
15+ # along with MoonSript. If not, see <https://www.gnu.org/licenses/>.
16+ #
17+ # Copyright (C) 2025 Krisna Pranav, MoonScript Developers
18+ # -----------------------------------------------------------------------
19+
20+ module MoonScript
21+ class HtmlBuilder
22+ def self.build (* , optimize: Bool , doctype: Bool = true , & )
23+ html = XML .build_fragment(indent: optimize ? nil : " " ) do |xml |
24+ builder = new(xml)
25+ with builder yield builder
26+ end
27+ end
28+
29+ def initialize (@xml : XML ::Builder )
30+ end
31+
32+ def tag (tag, attributes, & )
33+ @xml .element(tag, attributes) { with self yield }
34+ end
35+
36+ def script (** attributes, & )
37+ @xml .element(" script" , ** attributes) { with self yield }
38+ end
39+
40+ def script (** attributes)
41+ script(** attributes) { text(" " ) }
42+ end
43+
44+ def raw (contents )
45+ @xml .raw(contents)
46+ end
47+ end
48+ end
0 commit comments