attribute_imagifiable 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "attribute_imagifiable"
7
- gem.version = "0.0.5"
7
+ gem.version = "0.0.6"
8
8
  gem.authors = ["Stefan Wienert", "Akos Toth"]
9
9
  gem.email = ["stefan.wienert@pludoni.de"]
10
10
  gem.description = %q{Using paperclip to generate images from sensible attributes like e-mails and telephone numbers, in order to reduce crawler's success}
@@ -8,10 +8,14 @@ module AttributeImagifiable
8
8
 
9
9
 
10
10
  module ClassMethods
11
+ # options:
12
+ # :as => :paperclip_attribute
13
+ # :font => which system font to use
11
14
  def attribute_imagifiable(attribute, options={})
12
15
  raise ArgumentError.new("No :as given") if options[:as].nil?
13
- @_imagifiable_attributes ||= {}
14
- @_imagifiable_attributes[attribute] = options[:as]
16
+ @_imagifiable_attributes ||= []
17
+ font = options[:font] || "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf"
18
+ @_imagifiable_attributes << [attribute, options[:as], font]
15
19
 
16
20
  if (not column_names.include? "#{options[:as]}_file_name") or !self.instance_methods.include?(options[:as])
17
21
  $stderr.puts "Add #{options[:as]} Paperclip attribute before using attribute_imagifiable"
@@ -22,13 +26,13 @@ module AttributeImagifiable
22
26
  private
23
27
  def generate_image
24
28
  attributes = self.class.instance_variable_get("@_imagifiable_attributes")
25
- attributes.each do |attribute, as|
29
+ attributes.each do |attribute, as, font|
26
30
  value = send(attribute)
27
31
  if send("#{attribute}_changed?") || !send(as).exists?
28
32
  if value.present?
29
33
  arg = Shellwords.escape(value)
30
34
  tmp_name = Rails.root.join("tmp/#{as}-#{SecureRandom.hex(10)}.jpg")
31
- cmd = "convert -fill black -gravity center -size x40 label:#{arg} #{tmp_name}"
35
+ cmd = "convert -fill black -font #{font} -gravity center -size x40 label:#{arg} #{tmp_name}"
32
36
  unless system(cmd)
33
37
  raise RuntimeError.new "Image generation of #{attribute} failed. #{tmp_name}"
34
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribute_imagifiable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-08 00:00:00.000000000 Z
13
+ date: 2012-10-09 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Using paperclip to generate images from sensible attributes like e-mails
16
16
  and telephone numbers, in order to reduce crawler's success