Class: Perron::Feeds

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/perron/feeds.rb

Instance Method Summary collapse

Instance Method Details

#render(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/perron/feeds.rb', line 7

def render(options = {})
  html_tags = []

  Rails.application.routes.url_helpers.with_options(Perron.configuration.default_url_options) do |url|
    Perron::Site.collections.each do |collection|
      collection_name = collection.name.to_s

      next if options[:only]&.map(&:to_s)&.exclude?(collection_name)
      next if options[:except]&.map(&:to_s)&.include?(collection_name)
      next if collection.configuration.blank?

      collection.configuration.feeds.each do |type, feed|
        next unless feed.enabled && feed.path && MIME_TYPES.key?(type)

        absolute_url = URI.join(url.root_url, feed.path).to_s
        title = "#{collection.name.humanize} #{type.to_s.upcase} Feed"

        html_tags << tag(:link, rel: "alternate", type: MIME_TYPES[type], title: title, href: absolute_url)
      end
    end
  end

  safe_join(html_tags, "\n")
end