diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-05-11 09:37:48 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-05-11 09:37:48 +0200 |
commit | 5fd8780b1429acd2bea908695e13c41375d189d7 (patch) | |
tree | c870d368c2a9d0bfd2176057c0b99dad48338248 /app/lib/rss/builder.rb | |
parent | e8b8ac8908c6623f0fd7ffccc7de3882a773b72f (diff) | |
parent | 95555f15b55291b97477465f8d8a7eba526d6522 (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `package.json`: Not really a conflict, upstream updated a dependency textually adjacent to a glitch-soc-only one. Updated the dependency as upstream did.
Diffstat (limited to 'app/lib/rss/builder.rb')
-rw-r--r-- | app/lib/rss/builder.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/lib/rss/builder.rb b/app/lib/rss/builder.rb new file mode 100644 index 000000000..a9b3f08c5 --- /dev/null +++ b/app/lib/rss/builder.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class RSS::Builder + attr_reader :dsl + + def self.build + new.tap do |builder| + yield builder.dsl + end.to_xml + end + + def initialize + @dsl = RSS::Channel.new + end + + def to_xml + ('<?xml version="1.0" encoding="UTF-8"?>'.dup << Ox.dump(wrap_in_document, effort: :tolerant)).force_encoding('UTF-8') + end + + private + + def wrap_in_document + Ox::Document.new(version: '1.0').tap do |document| + document << Ox::Element.new('rss').tap do |rss| + rss['version'] = '2.0' + rss['xmlns:webfeeds'] = 'http://webfeeds.org/rss/1.0' + rss['xmlns:media'] = 'http://search.yahoo.com/mrss/' + + rss << @dsl.to_element + end + end + end +end |