<commit_before># encoding: UTF-8

# Author::    <NAME>
# Copyright:: Copyright (c) 2009-2010 <NAME>

begin
	require 'quick_magick'
rescue LoadError
end

class Sofa::Img < Sofa::File

	def self.thumbnail?
		Object.const_defined? :QuickMagick
	end

	def thumbnail
		raise Sofa::Error::Forbidden unless permit? :read

		if ps = my[:persistent_sd]
			@thumbnail ||= ps.storage.val "#{my[:persistent_name]}_small"
		end
		@thumbnail || body
	end

	def errors
		if nil # malformed image
		else
			super
		end
	end

	def commit(type = :temp)
		super
		if type == :temp && @action == :delete
			@thumbnail = nil
		elsif type == :persistent && ps = my[:persistent_sd]
			case @action
				when :create,:update,nil
					ps.storage.store(
						"#{my[:persistent_name]}_small",
						@thumbnail,
						val['basename'][/\.([\w\.]+)$/,1] || 'bin'
					) if @thumbnail && valid?
			end
		end
	end

	private

	def _g_default(arg = {})
		path       = [:read,nil].include?(arg[:action]) ? my[:path] : my[:tmp_path]
		basename   = Rack::Utils.escape_html val['basename'].to_s
		s_basename = basename.sub(/\..+$/,'_small\\&')
		<<_html.chomp unless val.empty?
<span class="img">
	<a href="#{path}/#{basename}"><img src="#{path}/#{s_basename}" /></a>
</span>
_html
	end

	def _thumbnail(tempfile)
		if self.class.thumbnail?
			tempfile.rewind
			img = QuickMagick::Image.read(tempfile.path).first
			img.resize '10x10'
			img.to_blob
		end
	end

	def val_cast(v)
		@thumbnail = _thumbnail(v[:tempfile]) if v && v[:tempfile]
		super
	end

end<commit_msg>Img#_thumbnail see [:width] and [:height] for dimensions of thumbnails.<commit_after># encoding: UTF-8

# Author::    <NAME>
# Copyright:: Copyright (c) 2009-2010 <NAME>

begin
	require 'quick_magick'
rescue LoadError
end

class Sofa::Img < Sofa::File

	def self.thumbnail?
		Object.const_defined? :QuickMagick
	end

	def thumbnail
		raise Sofa::Error::Forbidden unless permit? :read

		if ps = my[:persistent_sd]
			@thumbnail ||= ps.storage.val "#{my[:persistent_name]}_small"
		end
		@thumbnail || body
	end

	def errors
		if nil # malformed image
		else
			super
		end
	end

	def commit(type = :temp)
		super
		if type == :temp && @action == :delete
			@thumbnail = nil
		elsif type == :persistent && ps = my[:persistent_sd]
			case @action
				when :create,:update,nil
					ps.storage.store(
						"#{my[:persistent_name]}_small",
						@thumbnail,
						val['basename'][/\.([\w\.]+)$/,1] || 'bin'
					) if @thumbnail && valid?
			end
		end
	end

	private

	def _g_default(arg = {})
		path       = [:read,nil].include?(arg[:action]) ? my[:path] : my[:tmp_path]
		basename   = Rack::Utils.escape_html val['basename'].to_s
		s_basename = basename.sub(/\..+$/,'_small\\&')
		<<_html.chomp unless val.empty?
<span class="img">
	<a href="#{path}/#{basename}"><img src="#{path}/#{s_basename}" /></a>
</span>
_html
	end

	def _thumbnail(tempfile)
		if self.class.thumbnail?
			tempfile.rewind
			img = QuickMagick::Image.read(tempfile.path).first
			img.resize "#{my[:width]}x#{my[:height]}"
			img.to_blob
		end
	end

	def val_cast(v)
		@thumbnail = _thumbnail(v[:tempfile]) if v && v[:tempfile]
		super
	end

end
{'fraction_non_alphanumeric': 0.1685214626391097, 'fraction_numerical': 0.007631160572337043, 'mean_word_length': 3.6129032258064515, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1732424', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1193, 'n_words': 263}