Sha256: 0d3e29f17453577dc69054ad1828b4201460858d17a58508cca4bbaf6b7848d3

Contents?: true

Size: 788 Bytes

Versions: 2

Compression:

Stored size: 788 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
			# IO.popen for safe execution of commands within JRuby. backticks + utf8 = error
			self.content_text = IO.popen(%{lynx -dump -force_html "#{tmpfile.path}"}, "rb").read
		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

2 entries across 2 versions & 1 rubygems

Version Path
th_simple_content_management-0.2.4 lib/simple_content_management/content_text.rb
th_simple_content_management-0.2.3 lib/simple_content_management/content_text.rb