lib/panda/cms/editor_js_content.rb in panda-cms-0.7.0 vs lib/panda/cms/editor_js_content.rb in panda-cms-0.7.2

- old
+ new

@@ -10,12 +10,25 @@ before_save :generate_cached_content end def generate_cached_content if content.is_a?(String) - self.cached_content = content + begin + parsed_content = JSON.parse(content) + self.cached_content = if parsed_content.is_a?(Hash) && parsed_content["blocks"].present? + Panda::CMS::EditorJs::Renderer.new(parsed_content).render + else + content + end + rescue JSON::ParserError + # If it's not JSON, treat it as plain text + self.cached_content = content + end elsif content.is_a?(Hash) && content["blocks"].present? # Process EditorJS content self.cached_content = Panda::CMS::EditorJs::Renderer.new(content).render + else + # For any other case, store as is + self.cached_content = content.to_s end end end