ksk 0.4.0 → 0.4.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: 2cc3c547d2aacadccf428677a7d4e22e2db5a855
4
- data.tar.gz: 71d29e1440ece753f8625399c62a5fe9db41d65e
3
+ metadata.gz: 193d5f9ed9d086c53469c338aa19251871b095d6
4
+ data.tar.gz: 06b4468a591b944e2c62ae509c1832b049090573
5
5
  SHA512:
6
- metadata.gz: 36882cb6a3852af87bfc9c9f1bca8fc438b3ed9110b4fea9bb8369c24bfca97183cfc1a762537f6bbd18acb2900b0d0d2e0d2230fe75dd2c8d14f515d0fc6090
7
- data.tar.gz: 7e6a326165db77b746f85272c9e6e8702f87737674e8c2ed3220995762af35072a07303b7b46eb8190bcdb40c2aa6d5b22d5a9e8995c083f74425c38ad30baa7
6
+ metadata.gz: 4f4ea30f5539f4d680ffe29396923a404427d92e3d893f349ff7bfc53bcfdedaf1127d55feaf566c5501fd19ea67e133eb700a618fe09f4d43f3313a47fe116c
7
+ data.tar.gz: e2350618d867fa41bcaa43488c8333617c7dc1b167039aaff8e732b454046e84425c6936b737b31aae8ba2d867f53a4a71535d5e966a90ab3b51cc9208ace720
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (4.1.1)
5
- actionpack (= 4.1.1)
6
- actionview (= 4.1.1)
4
+ actionmailer (4.1.4)
5
+ actionpack (= 4.1.4)
6
+ actionview (= 4.1.4)
7
7
  mail (~> 2.5.4)
8
- actionpack (4.1.1)
9
- actionview (= 4.1.1)
10
- activesupport (= 4.1.1)
8
+ actionpack (4.1.4)
9
+ actionview (= 4.1.4)
10
+ activesupport (= 4.1.4)
11
11
  rack (~> 1.5.2)
12
12
  rack-test (~> 0.6.2)
13
- actionview (4.1.1)
14
- activesupport (= 4.1.1)
13
+ actionview (4.1.4)
14
+ activesupport (= 4.1.4)
15
15
  builder (~> 3.1)
16
16
  erubis (~> 2.7.0)
17
- activemodel (4.1.1)
18
- activesupport (= 4.1.1)
17
+ activemodel (4.1.4)
18
+ activesupport (= 4.1.4)
19
19
  builder (~> 3.1)
20
- activerecord (4.1.1)
21
- activemodel (= 4.1.1)
22
- activesupport (= 4.1.1)
20
+ activerecord (4.1.4)
21
+ activemodel (= 4.1.4)
22
+ activesupport (= 4.1.4)
23
23
  arel (~> 5.0.0)
24
- activesupport (4.1.1)
24
+ activesupport (4.1.4)
25
25
  i18n (~> 0.6, >= 0.6.9)
26
26
  json (~> 1.7, >= 1.7.7)
27
27
  minitest (~> 5.1)
@@ -29,9 +29,9 @@ GEM
29
29
  tzinfo (~> 1.1)
30
30
  addressable (2.3.6)
31
31
  arel (5.0.1.20140414130214)
32
- bhf (0.9.0)
32
+ bhf (0.9.4)
33
33
  haml-rails (~> 0.4)
34
- kaminari (~> 0.15)
34
+ kaminari (~> 0.16)
35
35
  rails (~> 4)
36
36
  sass-rails (~> 4.0)
37
37
  turbolinks (~> 2.1)
@@ -43,13 +43,13 @@ GEM
43
43
  coffee-rails (4.0.1)
44
44
  coffee-script (>= 2.2.0)
45
45
  railties (>= 4.0.0, < 5.0)
46
- coffee-script (2.2.0)
46
+ coffee-script (2.3.0)
47
47
  coffee-script-source
48
48
  execjs
49
- coffee-script-source (1.7.0)
49
+ coffee-script-source (1.7.1)
50
50
  descendants_tracker (0.0.4)
51
51
  thread_safe (~> 0.3, >= 0.3.1)
52
- docile (1.1.3)
52
+ docile (1.1.5)
53
53
  erubis (2.7.0)
54
54
  execjs (2.2.1)
55
55
  faraday (0.9.0)
@@ -70,10 +70,10 @@ GEM
70
70
  activesupport (>= 4.0.1)
71
71
  haml (>= 3.1, < 5.0)
72
72
  railties (>= 4.0.1)
73
- hashie (3.0.0)
73
+ hashie (3.2.0)
74
74
  highline (1.6.21)
75
75
  hike (1.2.3)
76
- i18n (0.6.9)
76
+ i18n (0.6.11)
77
77
  jeweler (2.0.1)
78
78
  builder
79
79
  bundler (>= 1.0)
@@ -93,19 +93,19 @@ GEM
93
93
  treetop (~> 1.4.8)
94
94
  mime-types (1.25.1)
95
95
  mini_portile (0.6.0)
96
- minitest (5.3.4)
96
+ minitest (5.4.0)
97
97
  multi_json (1.10.1)
98
98
  multi_xml (0.5.5)
99
99
  multipart-post (2.0.0)
100
100
  nokogiri (1.6.2.1)
101
101
  mini_portile (= 0.6.0)
102
- oauth2 (0.9.4)
102
+ oauth2 (1.0.0)
103
103
  faraday (>= 0.8, < 0.10)
104
104
  jwt (~> 1.0)
105
105
  multi_json (~> 1.3)
106
106
  multi_xml (~> 0.5)
107
107
  rack (~> 1.2)
108
- paperclip (4.1.1)
108
+ paperclip (4.2.0)
109
109
  activemodel (>= 3.0.0)
110
110
  activesupport (>= 3.0.0)
111
111
  cocaine (~> 0.5.3)
@@ -114,19 +114,19 @@ GEM
114
114
  rack (1.5.2)
115
115
  rack-test (0.6.2)
116
116
  rack (>= 1.0)
117
- rails (4.1.1)
118
- actionmailer (= 4.1.1)
119
- actionpack (= 4.1.1)
120
- actionview (= 4.1.1)
121
- activemodel (= 4.1.1)
122
- activerecord (= 4.1.1)
123
- activesupport (= 4.1.1)
117
+ rails (4.1.4)
118
+ actionmailer (= 4.1.4)
119
+ actionpack (= 4.1.4)
120
+ actionview (= 4.1.4)
121
+ activemodel (= 4.1.4)
122
+ activerecord (= 4.1.4)
123
+ activesupport (= 4.1.4)
124
124
  bundler (>= 1.3.0, < 2.0)
125
- railties (= 4.1.1)
125
+ railties (= 4.1.4)
126
126
  sprockets-rails (~> 2.0)
127
- railties (4.1.1)
128
- actionpack (= 4.1.1)
129
- activesupport (= 4.1.1)
127
+ railties (4.1.4)
128
+ actionpack (= 4.1.4)
129
+ activesupport (= 4.1.4)
130
130
  rake (>= 0.8.7)
131
131
  thor (>= 0.18.1, < 2.0)
132
132
  rake (10.3.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -12,7 +12,6 @@ window.addEvent('bhfDomChunkReady', function(scope){
12
12
  parent_id: parentId
13
13
  };
14
14
  queryParams[this.getNaviName()] = this.getIdPositions();
15
-
16
15
  new Request({
17
16
  url: elem.get('data-update-url')
18
17
  }).post(queryParams);
@@ -24,7 +23,6 @@ window.addEvent('bhfDomChunkReady', function(scope){
24
23
  var tmpl = platform.getElement('.template_data');
25
24
  var name = prompt(tmpl.get('data-prompt-question'), '');
26
25
  if ( ! name) { return; }
27
-
28
26
  var naviName = naviA.getNaviName();
29
27
  var queryParams = {};
30
28
  queryParams[naviName] = {
@@ -50,10 +48,23 @@ window.addEvent('bhfDomChunkReady', function(scope){
50
48
  $.noConflict();
51
49
  jQuery('.js_crop_image').each(function(){
52
50
  var $cropImg = jQuery(this);
51
+ var minWidth, minHeight;
52
+ var styleGeo = $cropImg.attr('data-crop-style') || '';
53
+ var styleGeoArray = styleGeo.split('x');
54
+ if (styleGeoArray.length === 2) {
55
+ if ( ! styleGeo.match('<') && ! styleGeo.match('>')) {
56
+ minWidth = parseInt(styleGeoArray[0], 10);
57
+ minHeight = parseInt(styleGeoArray[1], 10);
58
+ }
59
+ }
60
+ var hasSize = minWidth && minHeight;
61
+
53
62
  $cropImg.Jcrop({
54
- boxWidth: 800,
55
- boxHeight: 800,
56
- onSelect: function(c){
63
+ // minSize: (hasSize ? [minWidth, minHeight] : undefined),
64
+ aspectRatio: (hasSize ? (minWidth / minHeight) : undefined),
65
+ boxWidth: 800,
66
+ boxHeight: 800,
67
+ onSelect: function(c){
57
68
  $cropImg.parent().find('.js_cords_x').val(c.x);
58
69
  $cropImg.parent().find('.js_cords_y').val(c.y);
59
70
  $cropImg.parent().find('.js_cords_w').val(c.w);
@@ -4,15 +4,14 @@ module Ksk::Asset
4
4
  included do
5
5
  belongs_to :fileable, polymorphic: true
6
6
 
7
- default_scope -> {order 'position ASC, created_at DESC'}
7
+ default_scope -> { order('position ASC, created_at DESC') }
8
8
 
9
9
  has_one :preview
10
10
  before_create :set_last_position
11
11
 
12
- after_initialize :resize_attr_accessors
13
- before_save :crop_thumbs, if: :cropping?
14
-
15
12
  do_not_validate_attachment_file_type :file
13
+ before_file_post_process :is_image?
14
+ include Ksk::PaperclipCrop
16
15
 
17
16
  scope :only_images, -> {where(file_content_type: Bhf.configuration.paperclip_image_types)}
18
17
  scope :first_image, -> {only_images.limit(1)}
@@ -20,55 +19,13 @@ module Ksk::Asset
20
19
 
21
20
  scope :only_data_files, -> {where('file_content_type not in (?)', Bhf.configuration.paperclip_image_types)}
22
21
  scope :first_data_files, -> {only_data_files.limit(1)}
23
-
24
- before_file_post_process :is_image?
25
- end
26
-
27
- def resize_attr_accessors
28
- file.styles.each_pair do |style, meta|
29
- self.class.send(:attr_accessor, "#{style}_x")
30
- self.class.send(:attr_accessor, "#{style}_y")
31
- self.class.send(:attr_accessor, "#{style}_w")
32
- self.class.send(:attr_accessor, "#{style}_h")
33
- end
34
- end
35
-
36
- def cropping?
37
- needs_crop = false
38
- file.styles.each_pair do |style, meta|
39
- if !needs_crop
40
- needs_crop = cords_set?(style)
41
- end
42
- end
43
- needs_crop
44
- end
45
-
46
- def cords_set?(style)
47
- !send("#{style}_x").blank? && !send("#{style}_y").blank? && !send("#{style}_w").blank? && !send("#{style}_h").blank?
48
- end
49
-
50
- def crop_thumbs
51
- file.styles.each_pair do |style, meta|
52
- if cords_set?(style)
53
- resize_banner style, [send("#{style}_x"), send("#{style}_y"), send("#{style}_w"), send("#{style}_h")], meta.attachment.options[:styles][style][0]
54
- send("#{style}_x=", false)
55
- end
56
- end
57
- file.save
58
- file.instance.save
59
- end
60
-
61
- def resize_banner(name, cords, resize)
62
- file.queued_for_write[name] = Paperclip.processor(:ksk_crop).make(file, cords, file)
63
- style = Paperclip::Style.new(name, [resize, :jpg], file)
64
- file.queued_for_write[name] = Paperclip.processor(:thumbnail).make(file.queued_for_write[name], style.processor_options, file.queued_for_write[name])
65
- file.queued_for_write[name] = Paperclip.io_adapters.for(file.queued_for_write[name])
66
22
  end
67
23
 
68
24
  def is_image?
69
25
  Bhf.configuration.paperclip_image_types.include?(file.content_type)
70
26
  end
71
-
27
+
28
+
72
29
  def has_preview?
73
30
  preview && (preview.assets.any? || !preview.name.blank?)
74
31
  end
@@ -91,4 +48,8 @@ module Ksk::Asset
91
48
  self.position = self.class.where(fileable_id: self.fileable_id).count + 1
92
49
  end
93
50
 
94
- end
51
+ def ksk_images_for_crop
52
+ { file: [] }
53
+ end
54
+
55
+ end
@@ -0,0 +1,60 @@
1
+ module Ksk::PaperclipCrop
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ after_initialize :resize_attr_accessors
6
+ before_save :crop_thumbs, if: :cropping?
7
+ end
8
+
9
+ def resize_attr_accessors
10
+ ksk_images_for_crop.each_pair do |image_name, style_names|
11
+ send(image_name).styles.each_pair do |style, meta|
12
+ self.class.send(:attr_accessor, "#{image_name}_#{style}_x")
13
+ self.class.send(:attr_accessor, "#{image_name}_#{style}_y")
14
+ self.class.send(:attr_accessor, "#{image_name}_#{style}_w")
15
+ self.class.send(:attr_accessor, "#{image_name}_#{style}_h")
16
+ end
17
+ end
18
+ end
19
+
20
+ def cropping?
21
+ needs_crop = false
22
+ ksk_images_for_crop.each_pair do |image_name, style_names|
23
+ send(image_name).styles.each_pair do |style, meta|
24
+ unless needs_crop
25
+ needs_crop = cords_set?(image_name, style)
26
+ end
27
+ end
28
+ end
29
+ needs_crop
30
+ end
31
+
32
+ def cords_set?(image_name, style)
33
+ !send("#{image_name}_#{style}_x").blank? && !send("#{image_name}_#{style}_y").blank? && !send("#{image_name}_#{style}_w").blank? && !send("#{image_name}_#{style}_h").blank?
34
+ end
35
+
36
+ def crop_thumbs
37
+ ksk_images_for_crop.each_pair do |image_name, style_names|
38
+ image = send(image_name)
39
+ image.styles.each_pair do |style, meta|
40
+ if cords_set?(image_name, style)
41
+ resize_banner style, [send("#{image_name}_#{style}_x"), send("#{image_name}_#{style}_y"), send("#{image_name}_#{style}_w"), send("#{image_name}_#{style}_h")], meta.attachment.options[:styles][style][0]
42
+ send("#{image_name}_#{style}_x=", false)
43
+ end
44
+ end
45
+ image.save
46
+ image.instance.save
47
+ end
48
+ end
49
+
50
+ def resize_banner(name, cords, resize)
51
+ ksk_images_for_crop.each_pair do |image_name, style_names|
52
+ image = send(image_name)
53
+ image.queued_for_write[name] = Paperclip.processor(:ksk_crop).make(image, cords, image)
54
+ style = Paperclip::Style.new(name, [resize, :jpg], image)
55
+ image.queued_for_write[name] = Paperclip.processor(:thumbnail).make(image.queued_for_write[name], style.processor_options, image.queued_for_write[name])
56
+ image.queued_for_write[name] = Paperclip.io_adapters.for(image.queued_for_write[name])
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,18 @@
1
+ - style_name = "#{meta.attachment.name}_#{style}"
2
+ - image = f.object.send(meta.attachment.name)
3
+ - if image.exists?
4
+ .node{class: field.form_type}
5
+ .label= f.label "#{style_name}_crop", f.object.class.human_attribute_name("#{style_name}_crop")
6
+ .input
7
+ = image_tag image.url(:original), class: 'js_crop_image', data: {crop_style: meta.geometry}
8
+
9
+ = f.hidden_field "#{style_name}_x", class: 'js_cords_x'
10
+ = f.hidden_field "#{style_name}_y", class: 'js_cords_y'
11
+ = f.hidden_field "#{style_name}_w", class: 'js_cords_w'
12
+ = f.hidden_field "#{style_name}_h", class: 'js_cords_h'
13
+
14
+ - if image.exists?(style)
15
+ %div{style: 'margin-top: 30px'}
16
+ = render partial: 'bhf/helper/field_errors', locals: {f: f, field: "#{style_name}_crop"}
17
+ = image_tag image.url(style), class: 'uploaded_image'
18
+ = render partial: 'bhf/helper/info', locals: {info: t("bhf.platforms.assets.infos.#{style_name}_crop", default: '')}
@@ -1,17 +1,6 @@
1
1
  - return if @quick_edit
2
- - f.object.file.styles.each_pair do |style, meta|
3
- .node{class: field.form_type}
4
- .label= f.label "crop_#{style}", f.object.class.human_attribute_name("crop_#{style}")
5
- .input
6
-
7
- = image_tag f.object.file.url(:original), class: 'js_crop_image'
8
-
9
- = f.hidden_field "#{style}_x", class: 'js_cords_x'
10
- = f.hidden_field "#{style}_y", class: 'js_cords_y'
11
- = f.hidden_field "#{style}_w", class: 'js_cords_w'
12
- = f.hidden_field "#{style}_h", class: 'js_cords_h'
13
-
14
- %div{style: 'margin-top: 30px'}
15
- = render partial: 'bhf/helper/field_errors', locals: {f: f, field: "crop_#{style}"}
16
- = image_tag f.object.file.url(style), class: 'uploaded_image'
17
- = render partial: 'bhf/helper/info', locals: {info: t("bhf.platforms.assets.infos.crop_#{style}", default: '')}
2
+ - f.object.ksk_images_for_crop.each_pair do |image_name, style_names|
3
+ - f.object.send(image_name).styles.each_pair do |style, meta|
4
+ - if style_names.any?
5
+ - next unless style_names.include?(style)
6
+ = render partial: 'bhf/form/column/crop_style', locals: {style: style, meta: meta, f: f, field: field}
data/ksk.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: ksk 0.4.0 ruby lib
5
+ # stub: ksk 0.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "ksk"
9
- s.version = "0.4.0"
9
+ s.version = "0.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Anton Pawlik"]
14
- s.date = "2014-07-07"
14
+ s.date = "2014-07-13"
15
15
  s.description = "Fast and friendly"
16
16
  s.email = "anton.pawlik@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -35,9 +35,11 @@ Gem::Specification.new do |s|
35
35
  "app/models/concerns/ksk/markdown.rb",
36
36
  "app/models/concerns/ksk/navigation.rb",
37
37
  "app/models/concerns/ksk/navigation_type.rb",
38
+ "app/models/concerns/ksk/paperclip_crop.rb",
38
39
  "app/models/concerns/ksk/post.rb",
39
40
  "app/models/concerns/ksk/preview.rb",
40
41
  "app/models/concerns/ksk/static.rb",
42
+ "app/views/bhf/form/column/_crop_style.haml",
41
43
  "app/views/bhf/form/column/_crop_thumbs.html.haml",
42
44
  "app/views/bhf/form/column/_file.html.haml",
43
45
  "app/views/bhf/form/column/_select_file_assets.html.haml",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ksk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Pawlik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-07 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bhf
@@ -146,9 +146,11 @@ files:
146
146
  - app/models/concerns/ksk/markdown.rb
147
147
  - app/models/concerns/ksk/navigation.rb
148
148
  - app/models/concerns/ksk/navigation_type.rb
149
+ - app/models/concerns/ksk/paperclip_crop.rb
149
150
  - app/models/concerns/ksk/post.rb
150
151
  - app/models/concerns/ksk/preview.rb
151
152
  - app/models/concerns/ksk/static.rb
153
+ - app/views/bhf/form/column/_crop_style.haml
152
154
  - app/views/bhf/form/column/_crop_thumbs.html.haml
153
155
  - app/views/bhf/form/column/_file.html.haml
154
156
  - app/views/bhf/form/column/_select_file_assets.html.haml