Sha256: 56f4182339f0d49a1c8ab97ec65a8e040938a71dc8e3bf9a0a34f49766af6040

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

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 -dump -force_html "#{tmpfile.path}"`
		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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
th_simple_content_management-0.2.2 lib/simple_content_management/content_text.rb