Module: Panda::Editor::Content
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/panda/editor/content.rb
Instance Method Summary collapse
Instance Method Details
#content ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/panda/editor/content.rb', line 25 def content value = super if value.is_a?(String) begin JSON.parse(value) rescue JSON::ParserError value end else value end end |
#content=(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/panda/editor/content.rb', line 17 def content=(value) if value.is_a?(Hash) super(value.to_json) else super end end |
#generate_cached_content ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/panda/editor/content.rb', line 38 def generate_cached_content = { autolink_urls: true } if content.is_a?(String) begin parsed_content = JSON.parse(content) self.cached_content = if parsed_content.is_a?(Hash) && parsed_content['blocks'].present? Panda::Editor::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::Editor::Renderer.new(content, ).render else # For any other case, store as is self.cached_content = content.to_s end end |