Sha256: 7a4a1bf6d1f0ae38e21c696f8fb198cb1c58d4653ad114ce0962e44d41429869
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
require 'nokogiri' module Gara HTML5_TAGS = [ :a, :abbr, :address, :area, :article, :aside, :audio, :b, :base, :bdi, :bdo, :blockquote, :body, :br, :button, :canvas, :caption, :cite, :code, :col, :colgroup, :data, :datalist, :dd, :del, :details, :dfn, :div, :dl, :dt, :em, :embed, :fieldset, :figcaption, :figure, :footer, :form, :h1, :h2, :h3, :h4, :h5, :h6, :head, :header, :hr, :html, :i, :iframe, :img, :input, :ins, :kbd, :keygen, :label, :legend, :li, :link, :main, :map, :mark, :math, :menu, :menuitem, :meta, :meter, :nav, :noscript, :object, :ol, :optgroup, :option, :output, :p, :param, :pre, :progress, :q, :rp, :rt, :ruby, :s, :samp, :script, :section, :select, :small, :source, :span, :strong, :style, :sub, :sup, :summary, :svg, :table, :tbody, :td, :textarea, :tfoot, :th, :thead, :time, :title, :tr, :track, :u, :ul, :var, :video, :wbr, :<<] class Html5Emitter module TagMethods Gara::HTML5_TAGS.each do |tag| Gara::Delegator.define_delegate tag, on: self end end attr_accessor :target def initialize @doc = Nokogiri::HTML::DocumentFragment.parse("") @gara_delegate = Nokogiri::HTML::Builder.with(@doc) extend TagMethods end def registered_methods return TagMethods end def emit nodes = @doc.children if nodes.length.eql?(1) && nodes.first.name.eql?("html") # necessary to include doctype - TODO: avoid calling to_html twice Nokogiri::HTML::Document.parse( @doc.to_html ).to_xhtml(indent: 2) else @doc.to_html end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gara-0.1.5 | lib/gara/html5_emitter.rb |