Class: Mill::Resource::Feed

Inherits:
Mill::Resource show all
Includes:
HTMLHelpers
Defined in:
lib/mill/resources/feed.rb

Constant Summary

Constants included from HTMLHelpers

HTMLHelpers::LinkElementsXPath

Constants inherited from Mill::Resource

FileTypes

Instance Attribute Summary

Attributes inherited from Mill::Resource

#content, #date, #input_file, #output_file, #public, #site, #type

Instance Method Summary collapse

Methods included from HTMLHelpers

#amazon_button, #check_errors, #find_link_elements, #google_analytics, #html_document, #html_fragment, #link_if, #parse_html, #parse_html_fragment, #paypal_button, #replace_element

Methods inherited from Mill::Resource

#absolute_uri, #change_frequency, #final_content, #find_sibling_resources, #initialize, #inspect, #load, #parent_uri, #public?, #save, #tag_uri, #uri

Constructor Details

This class inherits a constructor from Mill::Resource

Instance Method Details

#buildObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mill/resources/feed.rb', line 11

def build
  resources = @site.feed_resources
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.feed(xmlns: 'http://www.w3.org/2005/Atom') do
      xml.id(@site.tag_uri)
      # xml.generator(*@site.feed_generator)
      xml.title(@site.site_title) if @site.site_title
      xml.link(rel: 'alternate', type: 'text/html',             href: @site.home_resource.uri) if @site.home_resource
      xml.link(rel: 'self',      type: 'application/atom+xml',  href: uri)
      xml.author do
        xml.name(@site.feed_author_name) if @site.feed_author_name
        xml.uri(@site.feed_author_uri) if @site.feed_author_uri
        xml.email(@site.feed_author_email) if @site.feed_author_email
      end
      xml.updated(resources.last.date.iso8601) unless resources.empty?
      resources.each do |resource|
        xml.entry do
          xml.title(resource.title) if resource.title
          xml.link(rel: 'alternate', href: resource.uri)
          xml.id(resource.tag_uri)
          xml.updated(resource.date.iso8601)
          xml.published(resource.date.iso8601)
          if (html = resource.feed_content)
            xml.content(type: 'html') { xml.cdata(html.to_html) }
          end
        end
      end
    end
  end
  @content = builder.doc
  super
end


44
45
46
47
48
# File 'lib/mill/resources/feed.rb', line 44

def link_html
  html_fragment do |html|
    html.link(href: uri, rel: 'alternate', type: 'application/atom+xml')
  end
end