Module: HTML5

Defined in:
lib/h5-min.rb,
lib/h5-min/optional.rb

Defined Under Namespace

Modules: OptionalTags

Constant Summary collapse

PRE_TAGS =

Elements in which whitespace is significant, so can’t be normalised

[:pre, :style, :script, :textarea]
FLOW_ELEMENTS =

Elements representing flow content

%w{a abbr address area article aside audio b bdo blockquote br 
 button canvas cite code command datalist del details dfn div 
 dl em embed fieldset figure footer form h1 h2 h3 h4 h5 h6 header 
 hgroup hr i iframe img input ins kbd keygen label link
 map mark math menu meta meter nav noscript object ol output 
 p pre progress q ruby samp script section select small span 
 strong style sub sup svg table textarea time ul var video wbr
}.map(&:to_sym)
BOOL_ATTR =
{
  _: [:itemscope, :hidden],
  audio: [:loop, :autoplay, :controls],
  button: [:formnovalidate, :disabled, :autofocus],
  command: [:disabled, :checked],
  details: [:open],
  fieldset: [:disabled],
  form: [:novalidate],
  iframe: [:seamless],
  img: [:ismap],
  input: [:autocomplete, :autofocus, :defaultchecked, 
          :checked, :disabled, :formnovalidate, :indeterminate,
          :multiple, :readonly, :required],
  keygen: [:disabled, :autofocus],
  optgroup: [:disabled],
  option: [:disabled, :defaultselected, :selected],
  ol: [:reversed],
  select: [:autofocus, :disabled, :multiple],
  script: [:async, :defer],
  style: [:scoped],
  textarea: [:autofocus, :disabled, :readonly, :required],
  time: [:pubdate],
  video: [:loop, :autoplay, :controls],
}

Class Method Summary collapse

Class Method Details

.minify(html) ⇒ Object



174
175
176
177
178
# File 'lib/h5-min.rb', line 174

def self.minify html
  minifier = @minifier.new
  Nokogiri::HTML::SAX::Parser.new(minifier).parse(html)
  OptionalTags.remove minifier.buf.strip
end

.minify_css(text) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/h5-min.rb', line 161

def self.minify_css text
  Tempfile.open('css') do |input|
    input << text
    input.close
    return begin
             `yui-compressor --type css --charset utf-8 #{input.to_path}`
           rescue Errno::ENOENT
             warn "yuicompressor not found; won't minify CSS"
             text
           end
  end  
end