module SimpleContentManagement::ContentText extend ActiveSupport::Concern included do before_save :update_content_text, if: :content_html_changed? end def update_content_text! update_content_text save end def update_content_text tmpfile = Tempfile.new "content-text" begin tmpfile.write self.content_html tmpfile.flush self.content_text = `lynx -assume_charset=utf-8 -display_charset=utf-8 -dump -force_html #{tmpfile.path}` Rails.logger.info self.content_text ensure tmpfile.close true # `true` also deletes (unlinks) the file end end end Rails.logger.warn("lynx not present. lynx is required for html-to-text conversion used by the search engine.") unless `lynx -version` =~ /^lynx version [\d+\.a-z]+ \(\d+ [a-z]+ \d+\)/i