module Papercraft::HTML

HTML Markup extensions

Constants

S_HTML5_DOCTYPE

Public Instance Methods

emit_markdown(markdown, **opts) click to toggle source

Converts and emits the given markdown. Papercraft uses [Kramdown](github.com/gettalong/kramdown/) to do the Markdown to HTML conversion. Optional Kramdown settings can be provided in order to control the conversion. Those are merged with the default Kramdown settings, which can be controlled using ‘Papercraft::HTML.kramdown_options`.

@param markdown [String] Markdown content @param **opts [Hash] Kramdown options @return [void]

# File lib/papercraft/html.rb, line 85
def emit_markdown(markdown, **opts)
  emit Papercraft.markdown(markdown, **opts)
end
html5(&block) click to toggle source

Emits an HTML5 doctype tag and an html tag with the given block.

@param block [Proc] nested HTML block @return [void]

# File lib/papercraft/html.rb, line 26
def html5(&block)
  @buffer << S_HTML5_DOCTYPE
  self.html(&block)
end
p(text = nil, **props, &block) click to toggle source

Emits the p tag (overrides Object#p)

@param text [String] text content of tag @param props [Hash] tag attributes @para block [Proc] nested HTML block @return [void]

# File lib/papercraft/html.rb, line 16
def p(text = nil, **props, &block)
  method_missing(:p, text, **props, &block)
end
script(js = nil, **props, &block) click to toggle source

Emits an inline JS script element.

@param js [String, nil] Javascript code @param **props [Hash] optional element attributes @return [void]

# File lib/papercraft/html.rb, line 64
def script(js = nil, **props, &block)
  @buffer << '<script'
  emit_props(props) unless props.empty?

  if js
    @buffer << '>' << js << '</script>'
  else
    @buffer << '></script>'
  end
end
style(css, **props, &block) click to toggle source

Emits an inline CSS style element.

@param css [String] CSS code @param **props [Hash] optional element attributes @return [void]

# File lib/papercraft/html.rb, line 52
def style(css, **props, &block)
  @buffer << '<style'
  emit_props(props) unless props.empty?

  @buffer << '>' << css << '</style>'
end

Private Instance Methods

att_repr(att) click to toggle source

Converts an attribute to its string representation. Underscores will be converted to dashes.

@param att [Symbol, String] attribute @return [String] attribute string

# File lib/papercraft/html.rb, line 113
def att_repr(att)
  att.to_s.tr('_', '-')
end
escape_text(text) click to toggle source

Escapes the given text using HTML entities.

@param text [String] text @return [String] escaped text

# File lib/papercraft/html.rb, line 95
def escape_text(text)
  EscapeUtils.escape_html(text.to_s)
end
tag_repr(tag) click to toggle source

Converts a tag to its string representation. Underscores will be converted to dashes.

@param tag [Symbol, String] tag @return [String] tag string

# File lib/papercraft/html.rb, line 104
def tag_repr(tag)
  tag.to_s.tr('_', '-')
end