Module: Hesburgh::Lib::HtmlScrubber
- Defined in:
- lib/hesburgh/lib/html_scrubber.rb
Overview
TODO:
Extract to the Hesburgh::Lib gem
Exposes a consistent means of scrubbing HTML.
Constant Summary collapse
- ALLOWED_INLINE_TAGS =
%w(abbr acronym b big cit cite code dfn em i mark samp small strong sub sup time tt var).freeze
- ALLOWED_INLINE_WITH_LINK_TAGS =
(%w(a) + ALLOWED_INLINE_TAGS).freeze
- ALLOWED_INLINE_ATTRIBUTES =
%w(datetime title href rel dir).freeze
- ALLOWED_BLOCK_ATTRIBUTES =
ALLOWED_INLINE_ATTRIBUTES
Class Method Summary collapse
-
.build_block_scrubber ⇒ Object
We are allowing multiple lines of content.
-
.build_inline_scrubber(tags: ALLOWED_INLINE_TAGS, attributes: ALLOWED_INLINE_ATTRIBUTES) ⇒ Object
We expect a single line of content.
-
.build_inline_with_link_scrubber(tags: ALLOWED_INLINE_WITH_LINK_TAGS, attributes: ALLOWED_INLINE_ATTRIBUTES) ⇒ Object
We expect a single line of content but are allowing links (A-tags) to be included.
-
.build_meta_tag_scrubber(tags: [], attributes: :fallback) ⇒ Object
We want to render this information as part of the metadata of a page.
Class Method Details
.build_block_scrubber ⇒ Object
We are allowing multiple lines of content. Examples include an “abstract” of an item
32 33 34 |
# File 'lib/hesburgh/lib/html_scrubber.rb', line 32 def self.build_block_scrubber AllowedTagsScrubber.new(tags: AllowedTagsScrubber::FALLBACK, attributes: ALLOWED_BLOCK_ATTRIBUTES) end |
.build_inline_scrubber(tags: ALLOWED_INLINE_TAGS, attributes: ALLOWED_INLINE_ATTRIBUTES) ⇒ Object
We expect a single line of content. Examples include a “title” of an item
22 23 24 |
# File 'lib/hesburgh/lib/html_scrubber.rb', line 22 def self.build_inline_scrubber(tags: ALLOWED_INLINE_TAGS, attributes: ALLOWED_INLINE_ATTRIBUTES) AllowedTagsScrubber.new(tags: , attributes: attributes) end |
.build_inline_with_link_scrubber(tags: ALLOWED_INLINE_WITH_LINK_TAGS, attributes: ALLOWED_INLINE_ATTRIBUTES) ⇒ Object
We expect a single line of content but are allowing links (A-tags) to be included.
27 28 29 |
# File 'lib/hesburgh/lib/html_scrubber.rb', line 27 def self.build_inline_with_link_scrubber(tags: ALLOWED_INLINE_WITH_LINK_TAGS, attributes: ALLOWED_INLINE_ATTRIBUTES) AllowedTagsScrubber.new(tags: , attributes: attributes) end |
.build_meta_tag_scrubber(tags: [], attributes: :fallback) ⇒ Object
We want to render this information as part of the metadata of a page. Examples include the ‘html head title` attribute
17 18 19 |
# File 'lib/hesburgh/lib/html_scrubber.rb', line 17 def self.(tags: [], attributes: :fallback) AllowedTagsScrubber.new(tags: , attributes: attributes) end |