module Papercraft::HTML
HTML
Markup extensions
Constants
- S_HTML5_DOCTYPE
Public Instance Methods
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
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
Emits a link element with a stylesheet.
@param href [String] stylesheet URL @param custom_attributes [Hash] optional custom attributes for the link element @return [void]
# File lib/papercraft/html.rb, line 36 def link_stylesheet(href, custom_attributes = nil) attributes = { rel: 'stylesheet', href: href } if custom_attributes attributes = custom_attributes.merge(attributes) end link(**attributes) end
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
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
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
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
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
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