awesome_form_attributes 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 03dcdca6af61dfcf2ddeed50fa6a2d17ab1fe746
4
- data.tar.gz: 820a424b17151ab4019a0885dc916c146e953bad
3
+ metadata.gz: 5632e813156e44e8811d9cead4a4f9785b96f3e2
4
+ data.tar.gz: 90c53920207c261ba49e8a16284edf4b0d7f47d9
5
5
  SHA512:
6
- metadata.gz: e1afd8c08c40bbb2e73461ab621bc032aed75e9aaa12308e15a3a75b1cfe7101f83ec05280698a68175045f692a95eef6c019c0063b50b0e4a786cea40ad0507
7
- data.tar.gz: a827598dbe7aaf69c0465e11c8e5e04d84ef1eab4c13acb202ef9e820df98bec323b6f773896cd6e4c58b03176ab2ff49a90e226e996d6a6a3cb4d8ed5e0b940
6
+ metadata.gz: b9f419b6db6110ff4facfe41db19f2e50ba5b4642512082cf20fcf9334047c1070b48c79be768caa7cc682321eafefea90bf65d89dbc14e9ff67d27de27c8023
7
+ data.tar.gz: c765b8097d2fa7d04a784b10fb954c3fd5806c58d153ce825b426c1bc6f83ca32eef8275316572312ec2b40a90aacddf8e77c6f94601237500ef44c74366752e
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'awesome_form_attributes'
5
- s.version = '1.1.0'
5
+ s.version = '1.2.0'
6
6
  s.authors = ['Zhimeng Sun']
7
7
  s.email = ['zhimengSun@gmail.com']
8
8
  s.homepage = 'https://github.com/zhimengSun/awesome_form_attributes'
@@ -31,16 +31,24 @@ module ActionView
31
31
  end.join
32
32
  raw content
33
33
  end
34
-
35
- def awesome_fileds(a, f, opts = {})
34
+
35
+ def tag_for_attr(att)
36
+ return "select" if att =~ /\_id\Z/
36
37
  cs = AwesomeFormAttributes.config.config
37
38
  text_field = cs.delete(:default_tag)
38
- title = localize_attr(a)
39
+ title = localize_attr(att)
39
40
  cur_tag_hash = cs.select {|k, v| title =~ /#{v.join("|")}/}.presence || {text_field: ""}
40
- cur_tag = cur_tag_hash.keys.first.to_s.gsub("_words", "")
41
+ cur_tag_hash.keys.first.to_s.gsub("_words", "")
42
+ end
43
+
44
+ def awesome_fileds(a, f, opts = {})
45
+ obj = single_obj
46
+ cur_tag = tag_for_attr(a)
41
47
  opts = default_styles_for(cur_tag, opts)
42
48
  return f.send(:check_box, a, opts) if cur_tag == 'boolean'
43
- f.send(cur_tag, a, opts)
49
+ select_tag = cur_tag == "select"
50
+ val = select_tag ? klass.select_values(a, obj) : obj.send(a)
51
+ select_tag ? f.send(cur_tag, a, val, opts[:opts] || {}, opts[:html_opts] || {}) : f.send(cur_tag, a, opts)
44
52
  end
45
53
 
46
54
  def default_styles_for(tag, opts = {})
@@ -48,7 +56,7 @@ module ActionView
48
56
  text_area: {rows: 6, cols: 50},
49
57
  text_field: {},
50
58
  file: {},
51
- select: {},
59
+ select: {opts: {include_blank: true}},
52
60
  check_box: {},
53
61
  boolean: {}
54
62
  }[tag.to_sym].deep_merge(opts) rescue opts
@@ -7,6 +7,14 @@ module UsedAttrColumns
7
7
  I18n.t(self.default_local_path).try(:keys) || []
8
8
  end
9
9
 
10
+ def select_options(tag, obj = nil)
11
+ {}
12
+ end
13
+
14
+ def select_values(tag, obj = nil)
15
+ select_options(tag, obj)[tag.to_s] || []
16
+ end
17
+
10
18
  def short_used_attrs
11
19
  I18n.t(self.displayed_columns_local_path).try(:keys) || used_attrs[0, 5]
12
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_form_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhimeng Sun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-03 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -63,9 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  requirements: []
65
65
  rubyforge_project:
66
- rubygems_version: 2.0.3
66
+ rubygems_version: 2.0.14
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Easy way to write attributes for DB based Object
70
70
  test_files: []
71
- has_rdoc: