seo_attachment 0.0.1 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seo_attachment.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrey
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/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+ module SeoAttachment
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def seo_attachment(options = {})
9
+ before_create :interpolates_file_names
10
+ before_update :interpolates_file_names
11
+
12
+ Paperclip.interpolates :normally_file_name do |data, style|
13
+ data.instance.normally_file_name
14
+ end
15
+
16
+ class_attribute :seo_attachment_options
17
+ self.seo_attachment_options = {
18
+ :data_name => (options[:data_name] || :data),
19
+ :normally_method => (options[:normally_method] || :slug)
20
+ }
21
+
22
+ include SeoAttachment::InstanceMethods
23
+ end
24
+ end
25
+
26
+ module InstanceMethods
27
+ def directory
28
+ data_name = seo_attachment_options[:data_name]
29
+ return if self.send(data_name).path.nil?
30
+ data_files = self.send(data_name).path.split("/")
31
+ data_files.delete_at(data_files.size-1)
32
+ data_files.push("*.*").join('/')
33
+ end
34
+
35
+ def interpolates_file_names
36
+ data_name = seo_attachment_options[:data_name]
37
+ return if self.send("#{data_name}_file_size").blank?
38
+ normally_file_name = self.send(seo_attachment_options[:normally_method].to_s)
39
+ extension = File.extname(self.send("#{data_name}_file_name")).downcase rescue nil
40
+ old_file = self.send("#{data_name}_file_name")
41
+ new_file = "#{normally_file_name}#{extension}"
42
+ self.send(data_name).instance_write(:file_name, new_file)
43
+ files = Dir[directory]
44
+ files.each do |file|
45
+ dir_array = file.split("/")
46
+ dir_array.pop
47
+ dir = dir_array.join('/')
48
+ prefix = file.split("/").last.split("-")[0]
49
+ was = File.join(dir, "#{prefix}-#{old_file}")
50
+ build = File.join(dir, "#{prefix}-#{new_file}")
51
+ if File.exist?(was) && was != build
52
+ FileUtils.mv was, build
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ class String
3
+ def remove_extension
4
+ File.basename(self, '.*')
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module SeoAttachment
2
+ VERSION = "0.0.11"
3
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ require "seo_attachment/seo_attachment"
3
+ require "seo_attachment/string"
4
+ require "seo_attachment/version"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seo_attachment/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "seo_attachment"
8
+ gem.version = SeoAttachment::VERSION
9
+ gem.authors = ["Andrey"]
10
+ gem.email = ["railscode@gmail.com"]
11
+ gem.description = "Seo-оптимизированные аттачменты (Paperclip)"
12
+ gem.summary = "Кого?"
13
+ gem.homepage = "https://github.com/vav/seo_attachment"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seo_attachment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,8 +19,16 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
22
24
  - README.md
23
- homepage: ''
25
+ - Rakefile
26
+ - lib/seo_attachment.rb
27
+ - lib/seo_attachment/seo_attachment.rb
28
+ - lib/seo_attachment/string.rb
29
+ - lib/seo_attachment/version.rb
30
+ - seo_attachment.gemspec
31
+ homepage: https://github.com/vav/seo_attachment
24
32
  licenses: []
25
33
  post_install_message:
26
34
  rdoc_options: []