neofiles 1.3.2 → 2.0.0

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
- SHA256:
3
- metadata.gz: 6ba1967358a294458fc392576803ec6077f407fffddb810a62306a9b1f2210c8
4
- data.tar.gz: deca6eecbca33cf4cba1a10e526e1ca6f5317bccde69c2b4f0f375cc6e0fe4d2
2
+ SHA1:
3
+ metadata.gz: f6c91e9f6a9903c58776d7c916f8adda41c2694d
4
+ data.tar.gz: df2ede8d0562a3be9d2af8b3992eb4b662f9eb68
5
5
  SHA512:
6
- metadata.gz: 6563c6d3a5a9b1df3e8e83e6c8a6f6972592766b862422799fb32b08dca00408d2b268bf3958b0826fc5225272610eea894006e5fbd1b1fe54338b6e0cb4c1c2
7
- data.tar.gz: a8d71310a664db68c229a295537cee6d1b9caed2178156831e5ddb20e94315ab907e815db482932c3925399e51974ed9571c28cf3812f4e5a6466140727faa17
6
+ metadata.gz: 9fafa7bbe4b172169631d83597b46348b8726d6a4d411ca9091b59412ee5810d5e9c249cdd30c08c1296f86107bd3e4a6550647e74d740683072bfa143011246
7
+ data.tar.gz: d34b9056fb7dad7faa2e1a1a94b0a90733718b4db25925b43fc9b85547ef0bc583c3ffd7a705e78f5fd7c02e9a1c76f50fb50162e49c8d1535c5aa938b09a920
data/README.md CHANGED
@@ -403,17 +403,6 @@ config.neofiles.image_max_crop_height = 2000 # users can request resizing only u
403
403
  config.neofiles.watermarker = ->(image, no_watermark: false, watermark_width:, watermark_height:) do
404
404
  ...
405
405
  end
406
-
407
- # picture when added is displayed on the right or left
408
- # also affects the order of displaying pictures
409
- config.neofiles.album_append_create_side = :left
410
-
411
- # Amazon S3 settings
412
- config.neofiles.amazon_s3_region = 'us-east'
413
- config.neofiles.amazon_s3_api = 'KEY_ID'
414
- config.neofiles.amazon_s3_secret = 'KEY_SECRET'
415
- config.neofiles.amazon_s3_bucket = 'neofiles_prod'
416
- config.neofiles.amazon_s3_endpoint = 'https://some-s3-provider.com' # optional
417
406
  ```
418
407
 
419
408
  Roadmap, TODOs
@@ -9,7 +9,7 @@
9
9
  class Neofiles::AdminController < ApplicationController
10
10
 
11
11
  # TODO: remove this! it should be controlled on application side
12
- skip_before_filter :verify_authenticity_token
12
+ skip_before_action :verify_authenticity_token
13
13
 
14
14
  # Build AJAX edit/upload form for a single file in compact way: small file thumbnail + misc buttons, like "delete",
15
15
  # "change options" etc.
@@ -107,15 +107,14 @@ class Neofiles::AdminController < ApplicationController
107
107
 
108
108
  result = []
109
109
  file_objects.each_with_index do |file, i|
110
- append_create_position = Rails.application.config.neofiles.album_append_create_side == :left ? i == 0 : i == file_objects.count - 1
111
- result << file_compact(data.merge(id: file.id, widget_id: "#{data[:widget_id]}_ap_#{i}", append_create: append_create_position && !old_file && data[:append_create] == '1' ? '1' : '0'))
110
+ result << file_compact(data.merge(id: file.id, widget_id: "#{data[:widget_id]}_ap_#{i}", append_create: i == file_objects.count - 1 && !old_file && data[:append_create] == '1' ? '1' : '0'))
112
111
  end
113
112
 
114
113
  if result.empty?
115
114
  raise ArgumentError.new(last_exception || (errors.empty? ? I18n.t('neofiles.file_not_passed') : errors.join("\n")))
116
115
  end
117
116
 
118
- render text: result.join, layout: false
117
+ render plain: result.join, layout: false
119
118
  end
120
119
 
121
120
  # As we don't actually delete anything, this method only marks file as deleted.
@@ -129,7 +128,7 @@ class Neofiles::AdminController < ApplicationController
129
128
  file.is_deleted = true
130
129
  file.save!
131
130
 
132
- return render text: '' if data[:clean_remove].present? && data[:clean_remove] != '0'
131
+ return render plain: '' if data[:clean_remove].present? && data[:clean_remove] != '0'
133
132
 
134
133
  redirect_to neofiles_file_compact_path(data.merge(id: nil))
135
134
  end
@@ -141,7 +140,7 @@ class Neofiles::AdminController < ApplicationController
141
140
  def file_update
142
141
  file, data = find_file_and_data
143
142
  file.update data.slice(:description, :no_wm)
144
- render text: '', layout: false
143
+ render plain: '', layout: false
145
144
  end
146
145
 
147
146
  # Neofiles knows how to play with Redactor.js and this method persists files uploaded via this WYSIWYG editor.
@@ -7,7 +7,6 @@ class Neofiles::ImagesController < ActionController::Metal
7
7
  class NotAdminException < Exception; end
8
8
 
9
9
  include ActionController::DataStreaming
10
- include ActionController::RackDelegation
11
10
  include Neofiles::NotFound
12
11
 
13
12
  if defined?(Devise)
@@ -2,7 +2,6 @@
2
2
  # If you want to work with amazon s3 you need set values for the following parameters in your config file
3
3
  # amazon_s3_region - the AWS region to connect to. The region is used to construct the client endpoint.
4
4
  # amazon_s3_api, amazon_s3_secret - used to set credentials statically
5
- # amazon_s3_endpoint - change if using another S3-compatible provider
6
5
  # bucket_name - storage name in amazon_s3. Bucket must have a name that conforms to the naming requirements for non-US Standard regions.
7
6
  # http://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html
8
7
  # File will be named as id of the Neofiles::File object
@@ -82,23 +81,15 @@ class Neofiles::DataStore::AmazonS3
82
81
  end
83
82
 
84
83
  def client
85
- @client ||= Aws::S3::Client.new(client_params)
84
+ @client ||= Aws::S3::Client.new(
85
+ region: Rails.application.config.neofiles.amazon_s3_region,
86
+ credentials: Aws::Credentials.new(
87
+ Rails.application.config.neofiles.amazon_s3_api,
88
+ Rails.application.config.neofiles.amazon_s3_secret
89
+ )
90
+ )
86
91
  rescue Aws::S3::Errors::ServiceError
87
92
  nil
88
93
  end
89
94
 
90
- def client_params
91
- {
92
- region: Rails.application.config.neofiles.amazon_s3_region,
93
- credentials: Aws::Credentials.new(
94
- Rails.application.config.neofiles.amazon_s3_api,
95
- Rails.application.config.neofiles.amazon_s3_secret
96
- )
97
- }.tap do |result|
98
- if Rails.application.config.neofiles.amazon_s3_endpoint
99
- result[:endpoint] = Rails.application.config.neofiles.amazon_s3_endpoint
100
- end
101
- end
102
- end
103
-
104
95
  end
@@ -2,10 +2,6 @@
2
2
  - desc = file.try(:description).try(:to_s).try!(:strip).try!(:truncate, 15).presence
3
3
  - empty_desc = t 'neofiles.views.no_description'
4
4
 
5
- - if Rails.application.config.neofiles.album_append_create_side == :left
6
- - if append_create && file
7
- = render partial: 'file_compact', locals: {file: nil, input_name: input_name, widget_id: widget_id + '_ap', clean_remove: clean_remove, append_create: true, error: nil, disabled: disabled, multiple: multiple, with_desc: with_desc, no_wm: no_wm}
8
-
9
5
  - classes = []
10
6
  - classes << 'neofiles-image-compact-empty' unless file
11
7
  - classes << 'neofiles-image-compact-with-description' if file && with_desc
@@ -26,7 +22,7 @@
26
22
  - if file.description.present?
27
23
  %p= file.description
28
24
 
29
- %p= t 'neofiles.views.created_at', local_date: l(file.created_at, format: t('neofiles.views.local_date_format'))
25
+ %p= raw t 'neofiles.views.created_at', local_date: l(file.created_at, format: t('neofiles.views.local_date_format'))
30
26
 
31
27
  - file_options = []
32
28
  - if file.respond_to? :dimensions
@@ -44,7 +40,7 @@
44
40
  = check_box_tag uniq_name, '1', file.no_wm, class: 'neofiles-image-compact-nowm', data: {update_url: neofiles_file_update_path}
45
41
  = t 'neofiles.views.no_wm'
46
42
 
47
- %a(href="#" tabindex="0" class="neofiles-image-compact-options" data-toggle="popover" data-trigger="click" data-placement="top" data-html="true" data-animation="false" data-title="#{file.filename}" data-content=options_form)
43
+ %a(href="#" tabindex="0" class="neofiles-image-compact-options" data-toggle="popover" data-trigger="click" data-placement="top" data-html="true" data-animation="false" data-title="#{file.filename}" data-content="#{options_form}")
48
44
  %i.icon-wrench.glyphicon.glyphicon-wrench
49
45
 
50
46
  - if with_desc
@@ -86,6 +82,6 @@
86
82
  $("##{widget_id}").image();
87
83
  });
88
84
 
89
- - if Rails.application.config.neofiles.album_append_create_side == :right
90
- - if append_create && file
91
- = render partial: 'file_compact', locals: {file: nil, input_name: input_name, widget_id: widget_id + '_ap', clean_remove: clean_remove, append_create: true, error: nil, disabled: disabled, multiple: multiple, with_desc: with_desc, no_wm: no_wm}
85
+ - if append_create and file
86
+ = render partial: 'file_compact', locals: {file: nil, input_name: input_name, widget_id: widget_id + '_ap', clean_remove: clean_remove, append_create: true, error: nil, disabled: disabled, multiple: multiple, with_desc: with_desc, no_wm: no_wm}
87
+
@@ -16,20 +16,23 @@ module Neofiles
16
16
  config.neofiles.image_max_crop_width = 2000 # users can request resizing only up to this width
17
17
  config.neofiles.image_max_crop_height = 2000 # users can request resizing only up to this height
18
18
 
19
- config.neofiles.album_append_create_side = :right # picture when added is displayed on the right
19
+ # default storage
20
+ config.neofiles.write_data_stores = 'mongo'
21
+ config.neofiles.read_data_stores = 'mongo'
20
22
 
21
23
  # default watermarker — redefine to set special watermarking logic
22
24
  # by default, watermark only images larger than 300x300 with watermark at the bottom center, taken from file
23
25
  # /app/assets/images/neofiles/watermark.png
24
- config.neofiles.watermarker = ->(image, no_watermark: false, watermark_width:, watermark_height:){
25
- if watermark_width < 300 || watermark_height < 300 || no_watermark
26
- return image.to_blob
27
- end
26
+ config.neofiles.watermarker = ->(convert, _image, width, height) {
27
+ return if width < 300 || height < 300
28
28
 
29
- image.composite(MiniMagick::Image.open(Rails.root.join('app', 'assets', 'images', 'neofiles', 'watermark.png'))) do |c|
30
- c.gravity 'south'
31
- c.geometry '200x+0+20'
32
- end.to_blob
29
+ wm_path = Rails.root.join('app', 'assets', 'images', 'neofiles', 'watermark.png')
30
+ return unless ::File.exists?(wm_path)
31
+
32
+ convert << wm_path
33
+ convert.gravity 'south'
34
+ convert.geometry '200x+0+20'
35
+ convert.composite
33
36
  }
34
37
  end
35
38
  end
@@ -1,3 +1,3 @@
1
1
  module Neofiles
2
- VERSION = '1.3.2'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/neofiles.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'neofiles/engine'
2
- require 'aspect_ratio'
3
2
 
4
3
  module Neofiles
5
4
  # Attach Neofiles specific routes in your routes.rb file:
@@ -35,6 +34,8 @@ module Neofiles
35
34
  # width, height - max width and height after resize
36
35
  # resize_options - {crop: '1'/'0'}, @see Neofiles::ImagesController#show
37
36
  #
37
+ # Can call ImageMagick.
38
+ #
38
39
  def resized_image_dimensions(image_file, width, height, resize_options)
39
40
  # dimensions are equal to requested ones if cropping
40
41
  return width, height if crop_requested? resize_options
@@ -57,20 +58,17 @@ module Neofiles
57
58
  # image fits into requested dimensions, no resizing will occur
58
59
  return image_file_width, image_file_height if image_file_width <= width && image_file_height <= height
59
60
 
60
- in_aspect = 1.0 * image_file_width / image_file_height
61
- out_aspect = 1.0 * width / height
62
-
63
- if in_aspect > out_aspect
64
- # If image is more "flat", the output width will always be equal to the requested width,
65
- # and the output height will be less than the requested height
66
- height = nil
67
- else
68
- # If input image is more "stretched" vertically or its aspect ratio is equal to output aspect ratio,
69
- # the output height will be equal to the requested height, and the output width will be less than or equal to the requested width
70
- width = nil
71
- end
72
-
73
- AspectRatio.resize(image_file_width, image_file_height, width, height).map(&:to_i)
61
+ # ... construct request ...
62
+ command = MiniMagick::CommandBuilder.new(:convert) # convert input file...
63
+ command.size([image_file_width, image_file_height].join 'x') # with the given dimensions...
64
+ command.xc('white') # and filled with whites...
65
+ command.resize([width, height].join 'x') # to fit in the given rectangle...
66
+ command.push('info:-') # return info about the resulting file
67
+
68
+ # ... and send it to ImageMagick
69
+ # the result will be: xc:white XC 54x100 54x100+0+0 16-bit DirectClass 0.070u 0:00.119
70
+ # extract dimensions and return them as array of integers
71
+ MiniMagick::Image.new(nil, nil).run(command).match(/ (\d+)x(\d+) /).values_at(1, 2).map(&:to_i)
74
72
 
75
73
  rescue
76
74
  nil
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neofiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konanykhin Ilya
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2018-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: 4.0.0
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
- version: '4.0'
26
+ version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongoid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: 5.0.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
- version: '5.0'
40
+ version: 5.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-imagespec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,28 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3'
89
+ version: '2'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3'
97
- - !ruby/object:Gem::Dependency
98
- name: aspect_ratio
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: '2'
111
97
  description: 'Library for managing files: creating & storing, linking to file owners,
112
98
  serving files from MongoDB'
113
99
  email:
@@ -155,7 +141,7 @@ homepage: http://neoweb.kz
155
141
  licenses:
156
142
  - MIT
157
143
  metadata: {}
158
- post_install_message:
144
+ post_install_message:
159
145
  rdoc_options: []
160
146
  require_paths:
161
147
  - lib
@@ -170,8 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
156
  - !ruby/object:Gem::Version
171
157
  version: '0'
172
158
  requirements: []
173
- rubygems_version: 3.0.9
174
- signing_key:
159
+ rubyforge_project:
160
+ rubygems_version: 2.6.12
161
+ signing_key:
175
162
  specification_version: 4
176
163
  summary: Serves and manages files & images.
177
164
  test_files: []