Module: Trek::Contentable

Extended by:
ActiveSupport::Concern
Included in:
Fragment, Page
Defined in:
app/models/concerns/trek/contentable.rb

Instance Method Summary collapse

Instance Method Details

#content_textObject



17
18
19
20
21
# File 'app/models/concerns/trek/contentable.rb', line 17

def content_text
  return if content.blank?

  extract_text(parsed_content)
end

#formatted_contentObject



11
12
13
14
15
# File 'app/models/concerns/trek/contentable.rb', line 11

def formatted_content
  return if content.blank?

  Prosemirror.new.format_content(parsed_content)
end

#parsed_contentObject



5
6
7
8
9
# File 'app/models/concerns/trek/contentable.rb', line 5

def parsed_content
  return if content.blank?

  content.is_a?(Hash) ? content : JSON.parse(content)
end

#prosemirror_content?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'app/models/concerns/trek/contentable.rb', line 23

def prosemirror_content?
  case content
  when Hash then content["type"] == "doc"
  when String then content.start_with?('{"type":"doc"')
  else false
  end
end