dynamic_scaffold 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b1f7eae38be3f6ea66d41d1b0e3f090d11d419f693370e164d96114a5635e63
4
- data.tar.gz: '0508b88786934bc56da9393bba1702651640c6a7a98f1d2bed09c823a747f4d3'
3
+ metadata.gz: 74a0f8f30faba7f43c94890c5e27a9dbdfe411fc1c0251f64aae80adbf04e47a
4
+ data.tar.gz: 41b6ef7eb1339343dbedead999fa2977036388c541633efd59827929cafc9227
5
5
  SHA512:
6
- metadata.gz: eee62a94e9a70e626013f30cc7f5ef4cf7f8a7297d634170b3e355865c4860908b7fe952acd3441fc9a479b3dc506ed361a7ae6f15d2d6f2b540c56b747c80a4
7
- data.tar.gz: 68386b6084d07c100b441d788182fa6af7d03c770056cbcdbba5db49a8e7cef1d1f1fcf9bbce12449dda687f9e6514a4620e5a5deba1c92e65e0f7e384674107
6
+ metadata.gz: 508a0b9f5cbc4d006db7e3ab9748034c96d9ab7bd377aed9ae052f5b323980eff1106a2ff2afb463fe6389a6939a6747b35360a0979c0959f2dc00b4ffa26ff3
7
+ data.tar.gz: 80cfaac150327d5251cffbe01d7add2ae92d8c4e354f46f1793d26b5b6b99b223019a2ca7e940d47d749310ef82b6b7edd36488bf4479d0c56b5923fd8cb3ab9
data/README.md CHANGED
@@ -290,6 +290,8 @@ class ShopController < ApplicationController
290
290
  end
291
291
  ```
292
292
 
293
+ `carrierwave_image` supports [cropper](https://github.com/fengyuanchen/cropperjs). For details, please read [Crop the image](https://github.com/gomo/dynamic_scaffold/wiki/Crop-the-image).
294
+
293
295
  ### Sorting
294
296
 
295
297
  You can sort records having integer column for order in the list page.
@@ -5,6 +5,7 @@ document.addEventListener('dynamic_scaffold:load', function (){
5
5
  const wrapper = input.closest('.js-ds-image-wrapper')
6
6
  const preview = wrapper.querySelector('.js-ds-image-preview')
7
7
  const img = preview.querySelector('img')
8
+ const cropper_input = wrapper.querySelector('.js-ds-image-cropper')
8
9
 
9
10
  // init preview display
10
11
  preview.style.display = 'inline-block'
@@ -32,6 +33,14 @@ document.addEventListener('dynamic_scaffold:load', function (){
32
33
  const reader = new FileReader();
33
34
  reader.onload = function (e) {
34
35
  img.src = e.target.result
36
+ if(cropper_input){
37
+ const options = JSON.parse(cropper_input.getAttribute('data-options'))
38
+ options.crop = function(event){
39
+ cropper_input.value = JSON.stringify(event.detail)
40
+ }
41
+ const cropper = new Cropper(img, options)
42
+ }
43
+
35
44
  preview.style.display = 'inline-block'
36
45
  if(flag) flag.disabled = true
37
46
  }
@@ -30,6 +30,9 @@
30
30
  <% elsif elem.type? :carrierwave_image %>
31
31
  <%- image = form.object.public_send(elem.name) -%>
32
32
  <div class="js-ds-image-wrapper">
33
+ <%- if elem.cropper.present? -%>
34
+ <%= form.hidden_field "cropper_#{elem.name}", class: "js-ds-image-cropper", data:{options: elem.cropper.to_json} %>
35
+ <%- end -%>
33
36
  <div class="js-ds-image-preview panel panel-default card mb-1">
34
37
  <% if elem.options[:removable] %>
35
38
  <div class="text-right panel-heading card-header">
@@ -9,6 +9,12 @@ module DynamicScaffold
9
9
  @options[:removable] = true if @options[:removable].nil?
10
10
  end
11
11
 
12
+ def cropper
13
+ return nil unless @options.key? :cropper
14
+ return {} if @options[:cropper] == true
15
+ @options[:cropper]
16
+ end
17
+
12
18
  def preview_image_style
13
19
  max_size = @options[:preview_max_size]
14
20
  return '' unless max_size
@@ -25,7 +31,10 @@ module DynamicScaffold
25
31
  end
26
32
 
27
33
  def strong_parameter
28
- params = [@name, "#{@name}_cache"]
34
+ params = []
35
+ # If you do not permit before the image body you can not use cropper value in uploader.
36
+ params << "cropper_#{@name}" unless cropper.nil?
37
+ params.concat([@name, "#{@name}_cache"])
29
38
  params << "remove_#{@name}" if @options[:removable]
30
39
  params
31
40
  end
@@ -1,3 +1,3 @@
1
1
  module DynamicScaffold
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-02 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: classnames-rails-view