actionview-helpers-auto_tag_helper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/actionview-helpers-auto_tag_helper.gemspec +37 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/action_view/helpers/auto_tag_helper.rb +154 -0
- data/lib/action_view/helpers/auto_tag_helper/display_types.rb +51 -0
- data/lib/action_view/helpers/auto_tag_helper/display_types/google_map.rb +17 -0
- data/lib/action_view/helpers/auto_tag_helper/form_info.rb +123 -0
- data/lib/action_view/helpers/auto_tag_helper/version.rb +7 -0
- data/lib/actionview/helpers/auto_tag_helper.rb +1 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 585f0409fcd000b13a8767e354a078abb007e9f5
|
4
|
+
data.tar.gz: 5d991c15e9d5435000178bc7579abf1b6cfbd98f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c5139d0b9bac2b6551ae94c095167824aa62a758a4bf6295454c9d156cffbf2afbc13a2dbbc77011c4b1cd10e7cc337de6485a367f11f71de5cdacb713df744
|
7
|
+
data.tar.gz: fdc7f1cf9fbbbead528e83fbe9c1fa67ddcd2d865b264c42c481ff95b9e82d37565c3db38bc3850b4804b55b4e1d14d5f6be96e822b7b257a81183d660111d82
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 baseball-bridge
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Shinjiro Itagaki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# ActionView::Helpers::AutoTagHelper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/actionview/helpers/auto_tag_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'actionview-helpers-auto_tag_helper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install actionview-helpers-auto_tag_helper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/actionview-helpers-auto_tag_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'action_view/helpers/auto_tag_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "actionview-helpers-auto_tag_helper"
|
8
|
+
spec.version = ActionView::Helpers::AutoTagHelper::VERSION
|
9
|
+
spec.authors = ["Shinjiro Itagaki"]
|
10
|
+
spec.email = ["ishinjiroster@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Helper for generate input tags automatically"
|
13
|
+
spec.description = "Helper for generate input tags automatically by detect column info"
|
14
|
+
spec.homepage = "https://github.com/baseball-bridge/actionview-helpers-auto_tag_helper"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "activerecord"
|
34
|
+
spec.add_development_dependency 'sqlite3'
|
35
|
+
spec.add_dependency "actionview"
|
36
|
+
spec.add_dependency 'activesupport', '>= 4.2.3'
|
37
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "actionview/helpers/auto_tag_helper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require "action_view"
|
2
|
+
require "action_view/helpers"
|
3
|
+
require "action_view/helpers/auto_tag_helper/version"
|
4
|
+
require "action_view/helpers/auto_tag_helper/form_info"
|
5
|
+
require "action_view/helpers/auto_tag_helper/display_types"
|
6
|
+
|
7
|
+
module ActionView
|
8
|
+
module Helpers
|
9
|
+
module AutoTagHelper
|
10
|
+
|
11
|
+
# == Parameters:
|
12
|
+
# method_name::
|
13
|
+
# called method name
|
14
|
+
# rec::
|
15
|
+
# object which is called method
|
16
|
+
# html_options::
|
17
|
+
# html options , ex: {style: "width: 100px; height: 100px; color: #ff0000;" placeholder: 'your name'}
|
18
|
+
#
|
19
|
+
def display_tag(method_name,rec,html_options={})
|
20
|
+
# if rec.class.respond_to? :reflections
|
21
|
+
# rec.class.reflections.each do |reflname,refl|
|
22
|
+
# if refl.association_foreign_key.to_sym == method_name && refl.macro == :belongs_to
|
23
|
+
# method_name = reflname
|
24
|
+
# break
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
v = rec.__send__(method_name)
|
29
|
+
display_tag_with_display_options(v,rec,method_name,html_options) || ( v.respond_to?(:__display__) ? v.__display__ : v.to_s )
|
30
|
+
end
|
31
|
+
|
32
|
+
def display_tag_with_display_options(v,rec,method_name,html_options={})
|
33
|
+
if !rec.class.respond_to? :display_options
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
|
37
|
+
opts = (rec.class.display_options(method_name) || {}).symbolize_keys
|
38
|
+
opt_type = opts[:type]
|
39
|
+
opt_method = opts[:method]
|
40
|
+
display_type = ActionView::Helpers::AutoTagHelper::DisplayTypes[opt_type]
|
41
|
+
|
42
|
+
if !(opt_method || display_type)
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
args = (opts[:args] || [v])
|
47
|
+
|
48
|
+
if args.kind_of? Proc
|
49
|
+
args = args.call(v,rec)
|
50
|
+
end
|
51
|
+
|
52
|
+
if !args.kind_of? Array
|
53
|
+
args = [args]
|
54
|
+
end
|
55
|
+
|
56
|
+
if opt_method
|
57
|
+
@tag_options = html_options
|
58
|
+
r = self.__send__(opt_method,*args)
|
59
|
+
@tag_options = nil
|
60
|
+
r
|
61
|
+
else
|
62
|
+
display_type.display_tag(v,html_options)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def auto_input_tag(sym,model,name,value)
|
67
|
+
column = model.columns_hash[sym.to_s]
|
68
|
+
type = column.type
|
69
|
+
opts = model.input_options(sym) || {}
|
70
|
+
reference_tag(sym,model,name,value) || boolean_tag(type,name,value) || datetime_tag(type,name,value,opts) || number_tag(type,name,value,opts) || text_tag(type,name,value,opts)
|
71
|
+
end
|
72
|
+
|
73
|
+
def reference_tag(sym,model,name,value)
|
74
|
+
if !model.respond_to? :select_list
|
75
|
+
return nil
|
76
|
+
end
|
77
|
+
|
78
|
+
rtn = nil
|
79
|
+
column = model.columns_hash[sym.to_s]
|
80
|
+
if list = model.select_list(sym)
|
81
|
+
rtn = select_tag(name,options_from_collection_for_select(list, :id, :__display__, value.to_s),include_blank: column.null)
|
82
|
+
end
|
83
|
+
rtn
|
84
|
+
end
|
85
|
+
|
86
|
+
def boolean_tag(type,name,value)
|
87
|
+
if type.to_sym == :boolean
|
88
|
+
check_box_tag(name,value="1",value)
|
89
|
+
else
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# type == :integer
|
95
|
+
# [:range :week , :month]
|
96
|
+
def number_tag(type,name,value,opts={})
|
97
|
+
case type.to_sym
|
98
|
+
when :integer
|
99
|
+
opts = opts.stringify_keys
|
100
|
+
case (opts["type"] || type).to_sym
|
101
|
+
when :range
|
102
|
+
range_field_tag(name, value, opts)
|
103
|
+
when :week,:month
|
104
|
+
text_field_tag(name, value, opts)
|
105
|
+
else
|
106
|
+
number_field_tag(name, value, opts)
|
107
|
+
end
|
108
|
+
when :float,:decimal
|
109
|
+
number_field_tag(name, value, opts)
|
110
|
+
else
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# type == :datetime
|
116
|
+
# datetime-local
|
117
|
+
def datetime_tag(type,name,value,opts={})
|
118
|
+
type = type.to_sym
|
119
|
+
case type
|
120
|
+
when :datetime
|
121
|
+
opts = opts.stringify_keys
|
122
|
+
opts["type"] ||= type.to_s
|
123
|
+
text_field_tag(name,value,opts)
|
124
|
+
when :time,:date
|
125
|
+
text_field_tag(name,value,opts.merge(type: type))
|
126
|
+
else
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# type == :string
|
132
|
+
# input_type: [:color, :email, :number, :password, :tel, :url]
|
133
|
+
def text_tag(type,name,value,opts={})
|
134
|
+
case type.to_sym
|
135
|
+
when :text
|
136
|
+
text_area_tag(name,value)
|
137
|
+
when :string
|
138
|
+
text_field_tag(name,value,opts)
|
139
|
+
else
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
include AutoTagHelper
|
145
|
+
include FormTagHelper
|
146
|
+
def tag_options(options, escape = true)
|
147
|
+
if @tag_options.is_a?(Hash)
|
148
|
+
options = options.merge(@tag_options)
|
149
|
+
@tag_options = nil
|
150
|
+
end
|
151
|
+
super(options, escape)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require File.expand_path('display_types/google_map',File.dirname(__FILE__))
|
3
|
+
|
4
|
+
module ActionView
|
5
|
+
module Helpers
|
6
|
+
module AutoTagHelper
|
7
|
+
module DisplayTypes
|
8
|
+
|
9
|
+
@@display_types = {}
|
10
|
+
|
11
|
+
# ==== For examples
|
12
|
+
# module MyGoogleMapByLatLon
|
13
|
+
# def self.display_tag latlon
|
14
|
+
# lat = latlon[:lat]
|
15
|
+
# lon = latlon[:lon]
|
16
|
+
# ...
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# ActionView::Helpers::AutoTagHelper::DisplayTypes.register(:google_map_latlon, MyGoogleMapByLatLon)
|
21
|
+
#
|
22
|
+
# class User < ActiveRecord::Base
|
23
|
+
# set_display_type(:myhome_coodinates, :google_map_latlon)
|
24
|
+
# def myhome_coodinates
|
25
|
+
# {lat: self.lat, lon: self.lon}
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# user = User.find(1)
|
30
|
+
# display_tag(:myhome_coodinates, user, width: 600, height: 350)
|
31
|
+
# # => MyGoogleMapByLatLon.display_tag(user.myhome_coodinates,width: 600, height: 350)
|
32
|
+
def self.register(type_name, obj)
|
33
|
+
@@display_types[type_name.to_sym]=obj
|
34
|
+
end
|
35
|
+
|
36
|
+
# register(:google_map_latlon, GoogleMapByLatLon)
|
37
|
+
# get(:google_map_latlon)
|
38
|
+
# # => GoogleMapByLatLon
|
39
|
+
def self.get(type_name)
|
40
|
+
type_name.present? ? @@display_types[type_name.to_sym] : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.[](type_name)
|
44
|
+
get(type_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
DisplayTypes.register(:google_map_lat_lon, DisplayTypes::GoogleMapLatLon)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module AutoTagHelper
|
4
|
+
module DisplayTypes
|
5
|
+
module GoogleMapLatLon
|
6
|
+
def self.display_tag latlon,html_options
|
7
|
+
lat = latlon[:lat]
|
8
|
+
lon = latlon[:lon]
|
9
|
+
<<RTN
|
10
|
+
<iframe width="600" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.jp/maps?f=q&hl=ja&q=#{lat},#{lon}&t=m&om=0&ie=UTF8&oe=UTF8&ll=#{lat},#{lon}&z=17&output=embed"></iframe>
|
11
|
+
RTN
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require "active_support"
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
module AutoTagHelper
|
5
|
+
module FormInfo
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
class << self
|
9
|
+
def showable_methods
|
10
|
+
@showable_methods || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def display_options(column_name)
|
14
|
+
(@display_options ||= {})[column_name.to_sym]
|
15
|
+
end
|
16
|
+
|
17
|
+
def input_options(column_name)
|
18
|
+
(@input_options ||= {})[column_name.to_sym]
|
19
|
+
end
|
20
|
+
|
21
|
+
def editable_columns
|
22
|
+
@editable_columns || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def select_list(column_name)
|
26
|
+
list = (@select_list ||= {})[column_name.to_sym]
|
27
|
+
list = list.call if list && list.kind_of?(Proc)
|
28
|
+
if !list && self.respond_to?(:reflections)
|
29
|
+
relation = self.reflections[column_name.to_s.gsub(/_id$/,'')]
|
30
|
+
model = relation.klass if relation
|
31
|
+
list = model.all.to_a if model
|
32
|
+
end
|
33
|
+
list
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def set_accessible_attrs(*args)
|
38
|
+
set_showable_methods(*args)
|
39
|
+
set_editable_columns(*args)
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_editable_columns(*args)
|
43
|
+
@editable_columns ||= []
|
44
|
+
if args.present?
|
45
|
+
@editable_columns.concat(args.map(&:to_sym)).uniq!
|
46
|
+
end
|
47
|
+
@editable_columns
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_select_list(column,list=nil,&block)
|
51
|
+
(@select_list ||= {})[column.to_sym] = (block || list)
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_showable_methods(*args)
|
55
|
+
@showable_methods ||= []
|
56
|
+
if args.present?
|
57
|
+
@showable_methods.concat(args.map(&:to_sym)).uniq!
|
58
|
+
end
|
59
|
+
@showable_methods
|
60
|
+
end
|
61
|
+
|
62
|
+
# Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
|
63
|
+
# ActionController::Base#url_for. The method for the form defaults to POST.
|
64
|
+
#
|
65
|
+
# ==== Parameters:
|
66
|
+
# column_name::
|
67
|
+
# Target column name
|
68
|
+
# ==== Options
|
69
|
+
# * <tt>:method</tt> - called method name
|
70
|
+
# * <tt>:type</tt> - display type
|
71
|
+
# * Any other key creates standard HTML attributes for the tag.
|
72
|
+
#
|
73
|
+
# ==== Examples
|
74
|
+
# class User < ActiveRecord::Base
|
75
|
+
# include ActionView::Helpers::AutoTagHelper::FormInfo
|
76
|
+
# set_display_options('my_photo_url',method: :image_tag, args: ->(v,rec){ [v,{ width: 64px, height: 64px }] })
|
77
|
+
# set_display_options('myhome_latlot',type: :latlot}
|
78
|
+
# def myhome_latlot
|
79
|
+
# {lat: self.my_home_lat, lot: self.my_home_lot}
|
80
|
+
# end
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# module LatLon
|
84
|
+
# def self.display_tag latlon,html_options
|
85
|
+
# lat = latlon[:lat]
|
86
|
+
# lon = latlon[:lon]
|
87
|
+
# "<div>lat: #{lat}, lon: #{lon}</div>"
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
# ActionView::Helpers::AutoTagHelper::DisplayTypes.register(:latlon, LatLon)
|
91
|
+
#
|
92
|
+
# user = User.find(1)
|
93
|
+
# puts user # => #<User id: 1, email: "myemail@gmail.com", my_photo_url: "https://mywebsite.com/user/1/photo.jpg", my_home_lot: 139.691706, my_home_lat: 35.689487>
|
94
|
+
# display_tag(:my_photo_url, user)
|
95
|
+
# # => image_tag("https://mywebsite.com/user/1/photo.jpg", {width: '64px', height: '64px'})
|
96
|
+
#
|
97
|
+
# display_tag(:my_photo_url, user, width: '128px', height: '128px')
|
98
|
+
# # => image_tag("https://mywebsite.com/user/1/photo.jpg", {width: '128px', height: '128px'})
|
99
|
+
#
|
100
|
+
# display_tag('myhome_latlot', user)
|
101
|
+
# # => <div>lat: 35.689487, lon: 139.691706</div>
|
102
|
+
#
|
103
|
+
def set_display_options(column_name,options)
|
104
|
+
(@display_options ||= {})[column_name.to_sym] = options
|
105
|
+
end
|
106
|
+
|
107
|
+
# ==== Examples
|
108
|
+
# set_input_options :hoge_crypted_password, type: :password, maxlength: 8
|
109
|
+
# set_input_options :hoge_percent, type: :range, min: 0, max: 100
|
110
|
+
# ==== Enable combinations of column's type and input type
|
111
|
+
# * <tt>datetime</tt> - :datetime_local
|
112
|
+
# * <tt>string</tt> - :color, :email, :number, :password, :phone, :telephone, :url
|
113
|
+
# * <tt>integer</tt> - :range, :week, :month
|
114
|
+
#
|
115
|
+
def set_input_options(column_name,options)
|
116
|
+
(@input_options ||= {})[column_name.to_sym] = options
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "action_view/helpers/auto_tag_helper"
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionview-helpers-auto_tag_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shinjiro Itagaki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: actionview
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 4.2.3
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.2.3
|
111
|
+
description: Helper for generate input tags automatically by detect column info
|
112
|
+
email:
|
113
|
+
- ishinjiroster@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- actionview-helpers-auto_tag_helper.gemspec
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/action_view/helpers/auto_tag_helper.rb
|
131
|
+
- lib/action_view/helpers/auto_tag_helper/display_types.rb
|
132
|
+
- lib/action_view/helpers/auto_tag_helper/display_types/google_map.rb
|
133
|
+
- lib/action_view/helpers/auto_tag_helper/form_info.rb
|
134
|
+
- lib/action_view/helpers/auto_tag_helper/version.rb
|
135
|
+
- lib/actionview/helpers/auto_tag_helper.rb
|
136
|
+
homepage: https://github.com/baseball-bridge/actionview-helpers-auto_tag_helper
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.5
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Helper for generate input tags automatically
|
160
|
+
test_files: []
|