ksk 0.2.6 → 0.2.7

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: 97b5b715bb7af5193329121359012da1cb78ef78
4
- data.tar.gz: 9870ff9f1f46315745574d2922605ed6395c5836
3
+ metadata.gz: 82c20844247dcb3e170f7e950cb872f6bbee3e0c
4
+ data.tar.gz: 0094d8cb022c924de0f0413cec40f17efea16fe8
5
5
  SHA512:
6
- metadata.gz: e09419e0e64ae4f8d42744950b1fb696bfe37f1b32ed8f3fc4014e03933376fabdb1dd8356bf47db0595f9ba6c11015800eb8cef1032c17c34451271c36c0662
7
- data.tar.gz: 861ca03711665305bb055da29870805649a54992c04cf47c34399c6a925aa9fc1deed51a1c182d9055346365dfb08941518935bf2c2a661fc99cb0e457504fea
6
+ metadata.gz: d8c0e9d2fb37eb910c2d6ce82870ccfdf1c6c8a26e0a274ec52f09357c00f4fe13294484a4e51443f0926c3acce0f8a968f00a91b8818c326e365280f6e0b6ea
7
+ data.tar.gz: 6fe69bf7fdaad4da4fff5a42c2952c2c8c906c61db0a1b56186d92fca93f074a1d9066c3ce1d652d3ccb6e34c1c35b1feb00a93a1cc38a56573b091f3410627b
@@ -58,4 +58,35 @@ initHelper(function(scope){
58
58
  }
59
59
  });
60
60
  });
61
+
62
+
63
+ cropImages = scope.getElements('.js_crop_image');
64
+ if (cropImages.length) {
65
+ var cropInit = function(){
66
+ $.noConflict();
67
+ jQuery('.js_crop_image').each(function(){
68
+ var $cropImg = jQuery(this);
69
+ $cropImg.Jcrop({
70
+ onSelect: function(c){
71
+ $cropImg.parent().find('.js_cords_x').val(c.x);
72
+ $cropImg.parent().find('.js_cords_y').val(c.y);
73
+ $cropImg.parent().find('.js_cords_w').val(c.w);
74
+ $cropImg.parent().find('.js_cords_h').val(c.h);
75
+ }
76
+ });
77
+ });
78
+ };
79
+ Asset.css('http://jcrop-cdn.tapmodo.com/v0.9.12/css/jquery.Jcrop.min.css', {
80
+ onLoad: function(){
81
+ Asset.javascript('http://edge1u.tapmodo.com/global/js/jquery.min.js', {
82
+ onLoad: function(){
83
+ Asset.javascript('http://jcrop-cdn.tapmodo.com/v0.9.12/js/jquery.Jcrop.min.js', {
84
+ onLoad: cropInit
85
+ });
86
+ }
87
+ });
88
+ }
89
+ });
90
+ }
91
+
61
92
  });
@@ -9,7 +9,7 @@ class Ksk::NavigationsController < Bhf::ApplicationController
9
9
  def create
10
10
  n = Navigation.new(params_navigation)
11
11
  n.save
12
- render :text => n.id
12
+ render text: n.id
13
13
  end
14
14
 
15
15
  private
@@ -0,0 +1,18 @@
1
+ - return if @quick_edit
2
+ - style = :banner
3
+ - f.object.file.styles.each_pair do |style, meta|
4
+ .node{class: field.form_type}
5
+ .label= f.label "crop_#{style}", f.object.class.human_attribute_name("crop_#{style}")
6
+ .input
7
+
8
+ = image_tag f.object.file.url(:original), class: 'js_crop_image'
9
+
10
+ = f.hidden_field "#{style}_x", class: 'js_cords_x'
11
+ = f.hidden_field "#{style}_y", class: 'js_cords_y'
12
+ = f.hidden_field "#{style}_w", class: 'js_cords_w'
13
+ = f.hidden_field "#{style}_h", class: 'js_cords_h'
14
+
15
+ %div{style: 'margin-top: 30px'}
16
+ = render partial: 'bhf/helper/field_errors', locals: {f: f, field: "crop_#{style}"}
17
+ = image_tag f.object.file.url(style), class: 'uploaded_image'
18
+ = render partial: 'bhf/helper/info', locals: {info: t("bhf.platforms.assets.infos.crop_#{style}", default: '')}
data/lib/actives/asset.rb CHANGED
@@ -11,7 +11,9 @@ module Ksk
11
11
 
12
12
  has_one :preview
13
13
  before_create :set_last_position
14
-
14
+
15
+ after_initialize :resize_attr_accessors
16
+ before_save :crop_thumbs, if: :cropping?
15
17
 
16
18
  #validates_attachment :file, :content_type => { :content_type => IMGTYPE }
17
19
  IMGTYPE = ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/tif', 'image/gif']
@@ -25,7 +27,48 @@ module Ksk
25
27
 
26
28
  before_file_post_process :allow_only_images
27
29
  end
28
-
30
+
31
+ def resize_attr_accessors
32
+ file.styles.each_pair do |style, meta|
33
+ self.class.send(:attr_accessor, "#{style}_x")
34
+ self.class.send(:attr_accessor, "#{style}_y")
35
+ self.class.send(:attr_accessor, "#{style}_w")
36
+ self.class.send(:attr_accessor, "#{style}_h")
37
+ end
38
+ end
39
+
40
+ def cropping?
41
+ needs_crop = false
42
+ file.styles.each_pair do |style, meta|
43
+ if !needs_crop
44
+ needs_crop = cords_set?(style)
45
+ end
46
+ end
47
+ needs_crop
48
+ end
49
+
50
+ def cords_set?(style)
51
+ !send("#{style}_x").blank? && !send("#{style}_y").blank? && !send("#{style}_w").blank? && !send("#{style}_h").blank?
52
+ end
53
+
54
+ def crop_thumbs
55
+ file.styles.each_pair do |style, meta|
56
+ if cords_set?(style)
57
+ resize_banner style, [send("#{style}_x"), send("#{style}_y"), send("#{style}_w"), send("#{style}_h")], meta.attachment.options[:styles][style][0]
58
+ send("#{style}_x=", false)
59
+ end
60
+ end
61
+ file.save
62
+ file.instance.save
63
+ end
64
+
65
+ def resize_banner(name, cords, resize)
66
+ file.queued_for_write[name] = Paperclip.processor(:ksk_crop).make(file, cords, file)
67
+ style = Paperclip::Style.new(name, [resize, :jpg], file)
68
+ file.queued_for_write[name] = Paperclip.processor(:thumbnail).make(file.queued_for_write[name], style.processor_options, file.queued_for_write[name])
69
+ file.queued_for_write[name] = Paperclip.io_adapters.for(file.queued_for_write[name])
70
+ end
71
+
29
72
 
30
73
  def allow_only_images
31
74
  if !(file.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$})
data/lib/ksk.rb CHANGED
@@ -25,3 +25,4 @@ require 'actives/navigation_type'
25
25
  require 'actives/post'
26
26
  require 'actives/preview'
27
27
  require 'actives/static'
28
+ require 'paperclip_processors/ksk_crop'
@@ -0,0 +1,30 @@
1
+ module Paperclip
2
+
3
+ class KskCrop < Processor
4
+
5
+ def initialize file, options = {}, attachment = nil
6
+ super
7
+ @crop = options
8
+ @format = File.extname(@file.path)
9
+ @basename = File.basename(@file.path, @format)
10
+ end
11
+
12
+ def make
13
+ src = @file
14
+ dst = Tempfile.new([@basename, @format])
15
+ dst.binmode
16
+
17
+ parameters = []
18
+ parameters << ":source"
19
+ parameters << "-crop '#{@crop[2]}x#{@crop[3]}+#{@crop[0]}+#{@crop[1]}'"
20
+ parameters << ":dest"
21
+
22
+ parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
23
+
24
+ success = Paperclip.run("convert", parameters, :source => "#{File.expand_path(src.path)}[0]", :dest => File.expand_path(dst.path))
25
+
26
+ dst
27
+ end
28
+
29
+ end
30
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ksk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Pawlik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bhf
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.6.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.6.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: stringex
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: paperclip
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
41
55
  description: Fast and friendly
42
56
  email: anton.pawlik@gmail.com
43
57
  executables: []
@@ -45,11 +59,13 @@ extensions: []
45
59
  extra_rdoc_files:
46
60
  - README.md
47
61
  files:
62
+ - README.md
48
63
  - app/assets/javascripts/ksk/application.js
49
64
  - app/assets/javascripts/ksk/classes/NaviAdmin.js
50
65
  - app/assets/stylesheets/ksk/application.css.sass
51
66
  - app/controllers/ksk/navigations_controller.rb
52
67
  - app/helpers/ksk/frontend_helper.rb
68
+ - app/views/bhf/entries/form/column/_crop_thumbs.html.haml
53
69
  - app/views/bhf/entries/form/column/_file.html.haml
54
70
  - app/views/bhf/entries/form/column/_select_file_assets.html.haml
55
71
  - app/views/bhf/entries/form/has_many/_assets.html.haml
@@ -69,8 +85,8 @@ files:
69
85
  - lib/actives/static.rb
70
86
  - lib/apdown.rb
71
87
  - lib/ksk.rb
88
+ - lib/paperclip_processors/ksk_crop.rb
72
89
  - lib/rails/generators/ksk/templates/initializer.rb
73
- - README.md
74
90
  homepage: http://github.com/antpaw/ksk
75
91
  licenses:
76
92
  - MIT
@@ -81,17 +97,17 @@ require_paths:
81
97
  - lib
82
98
  required_ruby_version: !ruby/object:Gem::Requirement
83
99
  requirements:
84
- - - '>='
100
+ - - ">="
85
101
  - !ruby/object:Gem::Version
86
102
  version: '0'
87
103
  required_rubygems_version: !ruby/object:Gem::Requirement
88
104
  requirements:
89
- - - '>='
105
+ - - ">="
90
106
  - !ruby/object:Gem::Version
91
107
  version: '0'
92
108
  requirements: []
93
109
  rubyforge_project: nowarning
94
- rubygems_version: 2.0.3
110
+ rubygems_version: 2.2.1
95
111
  signing_key:
96
112
  specification_version: 4
97
113
  summary: CMS for bhf