From 03fc04009a4e707661bdb1f3324de755e9d5e91e Mon Sep 17 00:00:00 2001 From: Camillo Visini Date: Thu, 19 Sep 2024 14:44:28 +0200 Subject: [PATCH] Add `ordered_list` to `TipTap::Document` (#30) --- lib/tip_tap/document.rb | 6 ++++++ spec/tip_tap/document_spec.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/tip_tap/document.rb b/lib/tip_tap/document.rb index e0d7589..91c507b 100644 --- a/lib/tip_tap/document.rb +++ b/lib/tip_tap/document.rb @@ -32,6 +32,12 @@ def bullet_list(&block) add_content(Nodes::BulletList.new(&block)) end + def ordered_list(&block) + raise ArgumentError, "Block required" if block.nil? + + add_content(Nodes::OrderedList.new(&block)) + end + def image(src:) add_content(Nodes::Image.new(src: src)) end diff --git a/spec/tip_tap/document_spec.rb b/spec/tip_tap/document_spec.rb index e73e4f9..d927f24 100644 --- a/spec/tip_tap/document_spec.rb +++ b/spec/tip_tap/document_spec.rb @@ -219,6 +219,22 @@ end end + describe "ordered_list" do + it "adds an ordered list node" do + document = TipTap::Document.new do |document| + document.ordered_list do |ol| + ol.list_item do |li| + li.paragraph do |para| + para.text("Hello World!") + end + end + end + end + + expect(document.content.first).to be_a(TipTap::Nodes::OrderedList) + end + end + describe "blockquote" do it "adds a blockquote node" do document = TipTap::Document.new do |document|