image_thread 0.0.1 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 930e6c0b738a5266a59c45cac3d594e51256caee
4
- data.tar.gz: e3035e6bb80b3d4319d5083ac5c3986815f57767
3
+ metadata.gz: f90c1e1d1a9f5ec95b1a5d65055f07407e03db74
4
+ data.tar.gz: d4717ddbc258166a21e054deb9c58eb9d225f49d
5
5
  SHA512:
6
- metadata.gz: cf42af7b93564bfdc34535d0798f2281eb23daf371304471deb5ffd3b3d89b49f34b37b8e4f49f65a6a5a05ab809554051930d1f4f4913875fc2f308f841244b
7
- data.tar.gz: f4cec8f27c0113a48db881e0b25af1f0b23001898a1841f7bfc7fca9e373bcfb9b9ce1417b6195c84da09d75e4e7c1882bbd52cea3a76fb2a9231f0ee9e6d1d9
6
+ metadata.gz: 8d23781fd29e1f8712a166913374d81bf3208ad47516ba6fc47d367c60d6a3e3f73cb0224712367d0fbe37d52b5c3d0533c877eb684e5bea99f5c35d0d791d9b
7
+ data.tar.gz: a0b18330768dfab847a13dd2a8035e9d8160397c4513252b80aeef5162249ffac17d80db491a99d8ecba424f4d30f9728196dfc159d97a6e1b21f79248bc3477
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # ImageThread
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/martsoft/image_thread.png)](https://codeclimate.com/github/martsoft/image_thread)
4
+ [![Gem Version](https://badge.fury.io/rb/image_thread.png)](http://badge.fury.io/rb/image_thread)
5
+
3
6
  Gem for multiply file upload (for backend).
4
7
 
5
8
  One thread (thread of images) have many images. Attach thread to your model and
@@ -17,6 +20,8 @@ Dependencies:
17
20
  5. I18n
18
21
  6. Reorder images in thread
19
22
  7. Placeholder generator for nonexistent files
23
+ 8. Tests!!!
24
+ 9. Cache thumb creation
20
25
 
21
26
  ## Features
22
27
  1. Dynamic thumbs (i.e. thread.image[0].thumb('120x120') or thread.image[0].thumb('300x100!'))
@@ -3,7 +3,13 @@ require 'rails/all'
3
3
  require 'carrierwave'
4
4
  require 'foreigner'
5
5
  require 'migration_comments'
6
+
7
+ # Core
8
+ require 'image_thread/exceptions'
9
+ require 'image_thread/version'
10
+ require 'image_thread/engine'
6
11
  require 'image_thread/patches/form_helper'
12
+ require 'image_thread/uploaders/image_uploader'
7
13
  require 'image_thread/model_methods'
8
14
 
9
15
  module ImageThread
@@ -24,6 +30,5 @@ ActiveSupport.on_load(:active_record) do
24
30
  include ImageThread::ModelMethods
25
31
  end
26
32
 
27
- require 'image_thread/exceptions'
28
- require 'image_thread/version'
29
- require 'image_thread/engine'
33
+ # Extentions
34
+ require 'image_thread/extensions/rails_admin' if defined?(RailsAdmin)
@@ -0,0 +1 @@
1
+ require 'image_thread/extensions/rails_admin/config/fields/types/image_thread'
@@ -0,0 +1,11 @@
1
+ module ImageThread
2
+ module Extentions
3
+ module RailsAdmin
4
+ module Config
5
+ class Fields
6
+
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module ImageThread
2
+ module Extentions
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class ImageThread < ::RailsAdmin::Config::Fields::Base
8
+ ::RailsAdmin::Config::Fields::Types.register(self)
9
+
10
+ def initialize(parent, name, properties)
11
+ super(parent, name, properties)
12
+ end
13
+
14
+ register_instance_option :partial do
15
+ :image_thread
16
+ end
17
+
18
+ register_instance_option :allowed_methods do
19
+ [method_name, [method_name, 'images'].join('_')].compact
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -20,6 +20,8 @@ module ImageThread
20
20
 
21
21
  define_method before_save_method do
22
22
  thread_id = nil
23
+ images = instance_variable_get(:"@#{field}_images")
24
+ return if images.blank?
23
25
  image_ids = instance_variable_get(:"@#{field}_images").map { |i| i[:id] }
24
26
 
25
27
  ImageThread::Image.select('id, thread_id').where(id: image_ids).each do |image|
@@ -34,27 +36,32 @@ module ImageThread
34
36
 
35
37
  transaction do
36
38
  instance_variable_get(:"@#{field}_images").each do |image|
37
- image = ImageThread::Image.find image[:id]
39
+ img = ImageThread::Image.find image[:id]
38
40
 
39
- unless image.blank?
40
- image.update(state: image[:state]) unless image[:state].blank?
41
+ unless img.blank?
42
+ if image[:state] == 'default'
43
+ img.thread.update_attribute(:default_image_id, img.id)
44
+ next
45
+ end
46
+
47
+ img.update(state: image[:state]) unless image[:state].blank?
41
48
 
42
- if state == ImageThread::Image::STATE_DELETED
49
+ if img.state == ImageThread::Image::STATE_DELETED
43
50
  # Remove all files
44
51
  if delete.include?(:files)
45
- dir_name = File.dirname(image.source.path)
46
- file_name = File.basename(image.source.path)
52
+ dir_name = File.dirname(img.source.path)
53
+ file_name = File.basename(img.source.path)
47
54
 
48
55
  Dir.chdir(dir_name)
49
56
  Dir.glob(['*', file_name].join).each do |file|
50
57
  File.delete File.expand_path(file)
51
58
  end
52
59
 
53
- File.expand_path image.source
60
+ File.expand_path img.source
54
61
  end
55
62
 
56
63
  # Remove row from DB
57
- image.destroy if delete.include?(:row) || delete.include?(:files)
64
+ img.destroy if delete.include?(:row) || delete.include?(:files)
58
65
  end
59
66
  end
60
67
 
@@ -65,7 +72,7 @@ module ImageThread
65
72
  instance_variable_set(:"@#{field}_images", [])
66
73
  end
67
74
 
68
- define_method [field, 'images='].join('_') do |images|
75
+ define_method [field, '_', 'images','='].join do |images|
69
76
  res = []
70
77
  images.each do |image|
71
78
  id, state = image.split(':')
@@ -1,3 +1,3 @@
1
1
  module ImageThread
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_thread
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Shcheglov(fc_arny)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-21 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 4.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sass-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: carrierwave
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +149,9 @@ files:
121
149
  - lib/image_thread.rb
122
150
  - lib/image_thread/engine.rb
123
151
  - lib/image_thread/exceptions.rb
152
+ - lib/image_thread/extensions/rails_admin.rb
153
+ - lib/image_thread/extensions/rails_admin/config/fields.rb
154
+ - lib/image_thread/extensions/rails_admin/config/fields/types/image_thread.rb
124
155
  - lib/image_thread/model_methods.rb
125
156
  - lib/image_thread/patches/form_helper.rb
126
157
  - lib/image_thread/uploaders/image_uploader.rb
@@ -150,4 +181,3 @@ signing_key:
150
181
  specification_version: 4
151
182
  summary: Images for models
152
183
  test_files: []
153
- has_rdoc: