Class: Lifer::Builder::RSS
- Inherits:
-
Lifer::Builder
- Object
- Lifer::Builder
- Lifer::Builder::RSS
- Defined in:
- lib/lifer/builder/rss.rb
Overview
Builds a simple, UTF-8, RSS 2.0 feed using the Ruby standard library’s RSS features.
The features of the generated feed attempt to follow the recommendations for RSS feeds specified by RSS Board.
The RSS builder can be configured in a number of ways:
-
Boolean
Simply set ‘rss: true` or `rss: false` to enable or disable a feed for a collection. If `true`, an RSS feed will be built to `name-of-collection.xml`
-
Simple
Simply set ‘rss: name-of-output-file.xml` to specify the name of the output XML file.
-
Fine-grained
Provide an object under ‘rss:` for more fine-grained control over configuration. The following sub-settings are supported:
-
‘count:` - The limit of RSS feed items that should be included in the output document. Leave unset or set to `0` to include all entries.
-
‘format:` - The RSS format to build with. Either `rss` or `atom` are supported. `rss` is the default format.
-
‘managing_editor:` - the contents of the `<managingEditor>` node of the RSS document. When unset, Lifer builds a valid `<managingEditor>` value using the collection or root `author` value and a null email address to ensure that RSS feed validators are satisfied.
-
‘url:` - the path to the filename of the output XML file.
-
[1]: www.rssboard.org/rss-specification [2]: www.rssboard.org/rss-profile
Constant Summary collapse
- DEFAULT_MANAGING_EDITOR_EMAIL =
Because Lifer has no reason to have record of anyone’s email address, we provide a non-email address so a <managingEditor> can be set and validated by RSS validators.
Note that ‘.invalid` is a special-use TLD that helps us indicate that the email address is definitely not real.
"[email protected]"
- FORMATS =
All of the available formats that this builder can build. Where the keys are formats accepted as input in configuration files and the values are the formats that the RSS builder will output.
{atom: "atom", rss: "rss2.0"}
- DEFAULT_MAKER_FORMAT_NAME =
The name of the format type, as needed by ‘RSS::Maker`, used by default by this feed builder.
FORMATS[:rss]
Class Method Summary collapse
-
.execute(root:) ⇒ void
Traverses and renders an RSS feed for each feedable collection in the configured output directory for the Lifer project.
Instance Method Summary collapse
-
#execute ⇒ void
Traverses and renders an RSS feed for feedable collection.
- #feed_format(collection) ⇒ Object
Methods inherited from Lifer::Builder
Class Method Details
.execute(root:) ⇒ void
This method returns an undefined value.
Traverses and renders an RSS feed for each feedable collection in the configured output directory for the Lifer project.
86 87 88 89 90 |
# File 'lib/lifer/builder/rss.rb', line 86 def execute(root:) Dir.chdir Lifer.output_directory do new(root: root).execute end end |
Instance Method Details
#execute ⇒ void
This method returns an undefined value.
Traverses and renders an RSS feed for feedable collection.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/lifer/builder/rss.rb', line 104 def execute Lifer::Utilities.parallelized collections_with_feeds do |collection| next unless (filename = output_filename(collection)) FileUtils.mkdir_p File.dirname(filename) File.open filename, "w" do |file| file.puts( rss_feed_for(collection) do |current_feed| max_index = max_feed_items(collection) - 1 collection.entries .select { |entry| entry.feedable? }[0..max_index] .each { |entry| rss_entry current_feed, entry } end.to_feed ) end end end |
#feed_format(collection) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/lifer/builder/rss.rb', line 93 def feed_format(collection) format = Lifer.setting(:rss, :format, collection:)&.to_sym return FORMATS[format] if FORMATS.keys.include? format DEFAULT_MAKER_FORMAT_NAME end |