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 +4 -4
- data/lib/alter_form_images/form_builder_methods.rb +24 -7
- data/lib/alter_form_images/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b217b27c04266f110c91d4fc8d7d3791aedd8686
|
4
|
+
data.tar.gz: 211b3c60ba10c89a12e5dd927f82961ee0be15e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
17
|
+
img_image_fields(method, options) + input_image_fields(method, options)
|
8
18
|
end
|
9
19
|
end
|
10
20
|
|
11
|
-
|
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
|
14
|
-
|
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(
|
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
|
-
|
44
|
+
opts.merge(options)
|
28
45
|
end
|
29
46
|
|
30
47
|
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.
|
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-
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|