Sha256: d885669e72e1e4849abd71c8531fa60633d42f1c80c947761ea3c7b931ecd4b2
Contents?: true
Size: 996 Bytes
Versions: 3
Compression:
Stored size: 996 Bytes
Contents
# frozen_string_literal: true module Mako class Article attr_reader :title, :published, :summary, :url def initialize(args) @title = args.fetch(:title, '') @published = args.fetch(:published) @summary = sanitize(args.fetch(:summary)) @url = args.fetch(:url) end # Converts published Time object to formatted string # # @return [String] def formatted_published @published.strftime('%A, %d %B %Y at %I:%M %P') end private # @private # Removes img tags (if configured) and transforms h1 tags into # p tags with the class bold # # @param [String] html an html document string # @return [String] a sanitized html document string def sanitize(html) doc = Nokogiri::HTML::DocumentFragment.parse(html) doc.css('img').each(&:remove) if Mako.config.sanitize_images doc.css('h1,h2,h3,h4,h5,h6').each { |n| n.name = 'p'; n.set_attribute('class', 'bold') } doc.to_s end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mako_rss-0.2.1 | lib/mako/article.rb |
mako_rss-0.2.0 | lib/mako/article.rb |
mako_rss-0.1.0 | lib/mako/article.rb |