diff --git a/Gemfile.lock b/Gemfile.lock index 262bc67..fffbce8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - tiptap-ruby (0.9.0) + tiptap-ruby (0.9.1) actionview (>= 6.0) activesupport (>= 6.0) diff --git a/lib/tip_tap/has_content.rb b/lib/tip_tap/has_content.rb index 48e45fd..0ad51fb 100644 --- a/lib/tip_tap/has_content.rb +++ b/lib/tip_tap/has_content.rb @@ -40,6 +40,10 @@ def size content.size end + def blank? + content&.all?(&:blank?) + end + module ClassMethods # Create a new instance from a TipTap JSON object. # All nodes are recursively parsed and converted to Ruby objects diff --git a/lib/tip_tap/version.rb b/lib/tip_tap/version.rb index f1b0900..e8a0c4a 100644 --- a/lib/tip_tap/version.rb +++ b/lib/tip_tap/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module TipTap - VERSION = "0.9.0" + VERSION = "0.9.1" end diff --git a/spec/tip_tap/document_spec.rb b/spec/tip_tap/document_spec.rb index 0329625..a79f429 100644 --- a/spec/tip_tap/document_spec.rb +++ b/spec/tip_tap/document_spec.rb @@ -244,4 +244,22 @@ expect(document.content.first).to be_a(TipTap::Nodes::Codeblock) end end + + describe "blank?" do + context "when the document is NOT blank" do + it "returns false" do + document = TipTap::Document.new do |document| + document.paragraph { |p| p.text("Hello World!") } + end + expect(document.blank?).to eq(false) + end + end + + context "when the document is blank" do + it "returns true" do + document = TipTap::Document.new.tap(&:paragraph) + expect(document.blank?).to eq(true) + end + end + end end