Module: TipTap::HasContent::ClassMethods

Defined in:
lib/tip_tap/has_content.rb

Instance Method Summary collapse

Instance Method Details

#from_json(json) ⇒ Object

Create a new instance from a TipTap JSON object. All nodes are recursively parsed and converted to Ruby objects All nodes must be registered in the registry.

Parameters:

  • json (Hash)

    The JSON object to parse



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tip_tap/has_content.rb', line 52

def from_json(json)
  return new if json.nil?

  json.deep_stringify_keys!

  content = Array(json["content"]).map do |node|
    TipTap.node_for(node["type"]).from_json(node)
  end

  new(content, **Hash(json["attrs"]))
end