attribute_imagifiable 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/attribute_imagifiable.gemspec +18 -0
- data/lib/attribute_imagifiable.rb +43 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Akos Toth
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# AttributeImagifiable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Using paperclip to generate images from sensible attributes like e-mails and telephone numbers, in order to reduce crawler's success
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
gem 'attribute_imagifiable'
|
|
11
|
+
|
|
12
|
+
And then execute:
|
|
13
|
+
|
|
14
|
+
$ bundle
|
|
15
|
+
|
|
16
|
+
Or install it yourself as:
|
|
17
|
+
|
|
18
|
+
$ gem install attribute_imagifiable
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
include and use in your Models:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
|
|
26
|
+
class Person < ActiveRecord::Base
|
|
27
|
+
...
|
|
28
|
+
|
|
29
|
+
has_attached_file :telephone_image,
|
|
30
|
+
styles: {small: "150x105>"},
|
|
31
|
+
url: '/system/:class/:attachment/:id/:style/:filename'
|
|
32
|
+
has_attached_file :mail_image,
|
|
33
|
+
styles: {small: "150x105>"},
|
|
34
|
+
url: '/system/:class/:attachment/:id/:style/:filename'
|
|
35
|
+
include AttributeImagifiable
|
|
36
|
+
attribute_imagifiable :telefon, as: :telephone_image
|
|
37
|
+
attribute_imagifiable :email, as: :mail_image
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
This will automatically generate an image for the "telefon" and "email" attribute before each update, if that attribute changed.
|
|
41
|
+
|
|
42
|
+
IMPORTANT: Use and generate paperclip attachments and attributes before
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = "attribute_imagifiable"
|
|
7
|
+
gem.version = "0.0.2"
|
|
8
|
+
gem.authors = ["Stefan Wienert", "Akos Toth"]
|
|
9
|
+
gem.email = ["stefan.wienert@pludoni.de"]
|
|
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}
|
|
11
|
+
gem.summary = gem.description
|
|
12
|
+
gem.homepage = ""
|
|
13
|
+
|
|
14
|
+
gem.files = `git ls-files`.split($/)
|
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
17
|
+
gem.require_paths = ["lib"]
|
|
18
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module AttributeImagifiable
|
|
2
|
+
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
after_validation :generate_image
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module ClassMethods
|
|
11
|
+
def attribute_imagifiable(attribute, options={})
|
|
12
|
+
raise ArgumentError.new("No :as given") if options[:as].nil?
|
|
13
|
+
@_imagifiable_attributes ||= {}
|
|
14
|
+
@_imagifiable_attributes[attribute] = options[:as]
|
|
15
|
+
|
|
16
|
+
if (not column_names.include? "#{options[:as]}_file_name") or !self.instance_methods.include?(options[:as])
|
|
17
|
+
raise ArgumentError.new "Add #{options[:as]} Paperclip attribute before using attribute_imagifiable"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
def generate_image
|
|
24
|
+
attributes = self.class.instance_variable_get("@_imagifiable_attributes")
|
|
25
|
+
attributes.each do |attribute, as|
|
|
26
|
+
value = send(attribute)
|
|
27
|
+
if send "#{attribute}_changed?"
|
|
28
|
+
if value.present?
|
|
29
|
+
arg = Shellwords.escape(value)
|
|
30
|
+
tmp_name = Rails.root.join("tmp/#{as}-#{SecureRandom.hex(10)}.jpg")
|
|
31
|
+
cmd = "convert -fill black -gravity center -size x40 label:#{arg} #{tmp_name}"
|
|
32
|
+
unless system(cmd)
|
|
33
|
+
raise RuntimeError.new "Image generation of #{attribute} failed. #{tmp_name}"
|
|
34
|
+
end
|
|
35
|
+
self.send("#{as}=", File.open(tmp_name))
|
|
36
|
+
File.delete tmp_name
|
|
37
|
+
else
|
|
38
|
+
self.send("#{as}=", nil)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: attribute_imagifiable
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Stefan Wienert
|
|
9
|
+
- Akos Toth
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2012-10-08 00:00:00.000000000 Z
|
|
14
|
+
dependencies: []
|
|
15
|
+
description: Using paperclip to generate images from sensible attributes like e-mails
|
|
16
|
+
and telephone numbers, in order to reduce crawler's success
|
|
17
|
+
email:
|
|
18
|
+
- stefan.wienert@pludoni.de
|
|
19
|
+
executables: []
|
|
20
|
+
extensions: []
|
|
21
|
+
extra_rdoc_files: []
|
|
22
|
+
files:
|
|
23
|
+
- .gitignore
|
|
24
|
+
- Gemfile
|
|
25
|
+
- LICENSE.txt
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- attribute_imagifiable.gemspec
|
|
29
|
+
- lib/attribute_imagifiable.rb
|
|
30
|
+
homepage: ''
|
|
31
|
+
licenses: []
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
none: false
|
|
38
|
+
requirements:
|
|
39
|
+
- - ! '>='
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
none: false
|
|
44
|
+
requirements:
|
|
45
|
+
- - ! '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
requirements: []
|
|
49
|
+
rubyforge_project:
|
|
50
|
+
rubygems_version: 1.8.24
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 3
|
|
53
|
+
summary: Using paperclip to generate images from sensible attributes like e-mails
|
|
54
|
+
and telephone numbers, in order to reduce crawler's success
|
|
55
|
+
test_files: []
|
|
56
|
+
has_rdoc:
|