alter_form_images 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 2ebab974d0bc61c094e650f227bd0851dab66201
4
- data.tar.gz: 2311ad38455c6cd624d2a36837a1955901d53f26
3
+ metadata.gz: b217b27c04266f110c91d4fc8d7d3791aedd8686
4
+ data.tar.gz: 211b3c60ba10c89a12e5dd927f82961ee0be15e3
5
5
  SHA512:
6
- metadata.gz: 1c69da6829c0ec391ff74d555d15e4da81d0ce6d6fd08f7d70d60a62c8e2172e4d1ee8d613e2c7c60f70e6172d37a9ab2e3687f7ae74b22c045037e31e1f9735
7
- data.tar.gz: 55b4539f7901b0a0ed9e241b147a13e9ecef5e3bca87f2062ca14d13d39368fb16035904217828fb1d52ba718faf72f12a974acac0c648294d0bdf5c2534a437
6
+ metadata.gz: 8ab26a5e33d8ad252e4198293a9a064ca42e70efe8a0a9d75da7c3f5e17b374a69f1ec314497966e8a8c8506cc3b50c21ad2f2fdd254aecc8dcb6a0b49342943
7
+ data.tar.gz: a116d09007013ba65779f9f52e57670aa8e1165cd2dd22e31f3c662170b6b8e2ba9dc6e3056e0ed1b1ce4beac4caeaa46b2a6402228dd178f73abdf314d320be
@@ -3,28 +3,45 @@ module AlterFormImages
3
3
 
4
4
  def image_fields_for(method, options={})
5
5
  options = default_opts_image_fields options
6
+ render_image_fields method, options
7
+ end
8
+
9
+ private
10
+
11
+ def is_new_record_object?(method)
12
+ @object.new_record? || @object.send(method).nil?
13
+ end
14
+
15
+ def render_image_fields(method, options)
6
16
  @template.content_tag :div, class: 'alter-image-block' do
7
- img_image_fields(options) + input_image_fields(options, method)
17
+ img_image_fields(method, options) + input_image_fields(method, options)
8
18
  end
9
19
  end
10
20
 
11
- private
21
+ def img_image_fields(method, options)
22
+ @template.image_tag(preview_img_url(method, options, is_new_record_object?(method)), class: 'alter-image-preview', style: create_img_styles(options))
23
+ end
12
24
 
13
- def img_image_fields(options)
14
- @template.image_tag(options[:default_image], class: 'alter-image-preview', style: "width: #{options[:width]}px; height: #{options[:height]}px;")
25
+ def preview_img_url(method, options, is_new_record)
26
+ is_new_record ? options[:default_image] : @object.send(method).url(options[:preview_style])
15
27
  end
16
28
 
17
- def input_image_fields(options, method)
29
+ def input_image_fields(method, options)
18
30
  @template.file_field_tag("#{@object_name}[#{method}]", class: 'alter-image-input')
19
31
  end
20
32
 
33
+ def create_img_styles(options)
34
+ "width: #{options[:width]}px; height: #{options[:height]}px;"
35
+ end
36
+
21
37
  def default_opts_image_fields(options)
22
38
  opts = {
23
39
  width: 100,
24
40
  height: 100,
25
- default_image: 'alter_default_image.png'
41
+ default_image: 'alter_default_image.png',
42
+ preview_style: :original
26
43
  }
27
- options.merge(opts)
44
+ opts.merge(options)
28
45
  end
29
46
 
30
47
  end
@@ -1,3 +1,3 @@
1
1
  module AlterFormImages
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alter_form_images
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergio1990
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails