Module: FunHtml::Writer

Included in:
Template
Defined in:
lib/fun_html.rb

Overview

nodoc

Instance Method Summary collapse

Instance Method Details

#attr(&blk) ⇒ Object

rubocop:disable Style/ArgumentsForwarding



27
28
29
# File 'lib/fun_html.rb', line 27

def attr(&blk) # rubocop:disable Style/ArgumentsForwarding
  Attribute.new(&blk) # rubocop:disable Style/ArgumentsForwarding
end

#comment(&elements) ⇒ Object



31
32
33
# File 'lib/fun_html.rb', line 31

def comment(&elements)
  write('<!--', '-->', nil, closing_char: '', closing_void_char: '-->', &elements)
end

#doctypeObject



35
36
37
38
# File 'lib/fun_html.rb', line 35

def doctype
  (@__buffer ||= +'') << '<!DOCTYPE html>'
  self
end

#include(func) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/fun_html.rb', line 12

def include(func)
  begin
    @__buffer << func.render
  # it is faster to error and try than to detect the type and branch
  rescue StandardError
    instance_exec(&func)
  end
  self
end

#renderObject



40
41
42
43
44
45
# File 'lib/fun_html.rb', line 40

def render
  @__buffer
ensure
  # empty the buffer to prevent double rendering
  @__buffer = +''
end

#text(value) ⇒ Object



22
23
24
25
# File 'lib/fun_html.rb', line 22

def text(value)
  (@__buffer ||= +'') << ERB::Escape.html_escape(value)
  self
end