about summary refs log tree commit diff
path: root/app/lib/rss/element.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-05-11 09:37:48 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-05-11 09:37:48 +0200
commit5fd8780b1429acd2bea908695e13c41375d189d7 (patch)
treec870d368c2a9d0bfd2176057c0b99dad48338248 /app/lib/rss/element.rb
parente8b8ac8908c6623f0fd7ffccc7de3882a773b72f (diff)
parent95555f15b55291b97477465f8d8a7eba526d6522 (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/element.rb')
-rw-r--r--app/lib/rss/element.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/lib/rss/element.rb b/app/lib/rss/element.rb
new file mode 100644
index 000000000..7142fa039
--- /dev/null
+++ b/app/lib/rss/element.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class RSS::Element
+  def self.with(*args, &block)
+    new(*args).tap(&block).to_element
+  end
+
+  def create_element(name, content = nil)
+    Ox::Element.new(name).tap do |element|
+      yield element if block_given?
+      element << content if content.present?
+    end
+  end
+
+  def append_element(name, content = nil)
+    @root << create_element(name, content).tap do |element|
+      yield element if block_given?
+    end
+  end
+
+  def to_element
+    @root
+  end
+end