Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blank? #16

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
tiptap-ruby (0.9.0)
tiptap-ruby (0.9.1)
actionview (>= 6.0)
activesupport (>= 6.0)

Expand Down
4 changes: 4 additions & 0 deletions lib/tip_tap/has_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tip_tap/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module TipTap
VERSION = "0.9.0"
VERSION = "0.9.1"
end
18 changes: 18 additions & 0 deletions spec/tip_tap/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading