taiwan_districts_form_helper 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb8c0d8724f99390c3375b30c73f7389ba040e1c1256deca3f51bfa09cd2489c
4
+ data.tar.gz: c0c93afdc00104978f1bdbe58ce5698d96872e96e895cf22079dc1c1089cce03
5
+ SHA512:
6
+ metadata.gz: fdc554581064ab298d78accbd48b541ba268b2fc4fbd22fa9f13bf6b6ff68aa5928f01335e4373d3e540e50df27446c5bfb9ff29809061ee9c38e076dd23501e
7
+ data.tar.gz: b95eeb757d7f7af0ee96b1c30c48c3fa9cd5fd6419cc6b7108775e013de335f35914633ad92a948bb86aa08e87b13e78db52d19effe4d7fcc669d97436d2122a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in taiwan_districts_form_helper.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ taiwan_districts_form_helper (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (12.3.3)
10
+
11
+ PLATFORMS
12
+ arm64-darwin-21
13
+
14
+ DEPENDENCIES
15
+ rake (~> 12.0)
16
+ taiwan_districts_form_helper!
17
+
18
+ BUNDLED WITH
19
+ 2.3.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 eddie
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,27 @@
1
+ # TaiwanDistrictsFormHelper
2
+
3
+ Form Helper for Taiwan districts
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'taiwan_districts_form_helper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install taiwan_districts_form_helper
20
+
21
+ # Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/5xTraining/taiwan_districts_form_helper.
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "taiwan_districts_form_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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,67 @@
1
+ require "json"
2
+
3
+ class TWRegionCityAndDistrict < ActionView::Helpers::FormBuilder
4
+ def self.json_data
5
+ File.read(File.join(File.dirname(__FILE__), "location.json"))
6
+ end
7
+
8
+ def region_select(attribute, selected: nil, **options)
9
+ data = load_data
10
+
11
+ selected = selected || ""
12
+ select(
13
+ attribute,
14
+ data.map { |d| d["region"] },
15
+ { selected: selected, disabled: "", prompt: "請選擇區域" },
16
+ **options
17
+ )
18
+ end
19
+
20
+ def city_select(attribute, selected: nil, region: nil, **options)
21
+ cities = []
22
+ if region
23
+ data = load_data
24
+ found_region = data.find { |d| d["region"] == region }
25
+ cities = found_region["cities"].map { |r| r["name"] }
26
+ end
27
+
28
+ selected = selected || ""
29
+
30
+ select(
31
+ attribute,
32
+ cities,
33
+ { selected: selected, disabled: "", prompt: "請先選擇區域" },
34
+ **options
35
+ )
36
+ end
37
+
38
+ def district_select(attribute, selected: nil, city: nil, **options)
39
+ districts = []
40
+
41
+ if city
42
+ data = load_data
43
+ found_city = nil
44
+ data.each do |d|
45
+ found_city = d["cities"].find { |c| c["name"] == city }
46
+ if found_city
47
+ districts = found_city["districts"]
48
+ end
49
+ end
50
+ end
51
+
52
+ selected = selected || ""
53
+
54
+ select(
55
+ attribute,
56
+ districts,
57
+ { selected: selected, disabled: "", prompt: "請先選擇縣市" },
58
+ **options
59
+ )
60
+ end
61
+
62
+ private
63
+
64
+ def load_data
65
+ @data ||= JSON.parse(File.read(File.join(File.dirname(__FILE__), "location.json")))
66
+ end
67
+ end
@@ -0,0 +1,203 @@
1
+ [
2
+ {
3
+ "region": "北區",
4
+ "cities": [
5
+ {
6
+ "name": "臺北市",
7
+ "districts": [
8
+ "中正區", "中山區", "大同區", "松山區", "大安區", "萬華區", "信義區",
9
+ "士林區", "北投區", "內湖區", "南港區", "文山區"
10
+ ]
11
+ },
12
+ {
13
+ "name": "新北市",
14
+ "districts": [
15
+ "萬里區", "金山區", "板橋區", "汐止區", "深坑區", "石碇區", "瑞芳區",
16
+ "平溪區", "雙溪區", "貢寮區", "新店區", "坪林區", "烏來區", "永和區",
17
+ "中和區", "土城區", "三峽區", "樹林區", "鶯歌區", "三重區", "新莊區",
18
+ "泰山區", "林口區", "蘆洲區", "五股區", "八里區", "淡水區", "三芝區",
19
+ "石門區"
20
+ ]
21
+ },
22
+ {
23
+ "name": "基隆市",
24
+ "districts": [
25
+ "仁愛區", "信義區", "中正區", "中山區", "安樂區", "暖暖區", "七堵區"
26
+ ]
27
+ },
28
+ {
29
+ "name": "宜蘭縣",
30
+ "districts": [
31
+ "宜蘭市", "頭城鎮", "礁溪鄉", "壯圍鄉", "員山鄉", "羅東鎮", "三星鄉",
32
+ "大同鄉", "五結鄉", "冬山鄉", "蘇澳鎮", "南澳鄉"
33
+ ]
34
+ },
35
+ {
36
+ "name": "桃園市",
37
+ "districts": [
38
+ "中壢區", "平鎮區", "龍潭區", "楊梅區", "新屋區", "觀音區", "桃園區",
39
+ "龜山區", "八德區", "大溪區", "復興區", "大園區", "蘆竹區"
40
+ ]
41
+ },
42
+ {
43
+ "name": "新竹市",
44
+ "districts": [
45
+ "東區", "北區", "香山區"
46
+ ]
47
+ },
48
+ {
49
+ "name": "新竹縣",
50
+ "districts": [
51
+ "竹北市", "湖口鄉", "新豐鄉", "新埔鎮", "關西鎮", "芎林鄉", "寶山鄉",
52
+ "竹東鎮", "五峰鄉", "橫山鄉", "尖石鄉", "北埔鄉", "峨眉鄉"
53
+ ]
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "region": "中區",
59
+ "cities": [
60
+ {
61
+ "name": "苗栗縣",
62
+ "districts": [
63
+ "竹南鎮", "頭份鎮", "三灣鄉", "南庄鄉", "獅潭鄉", "後龍鎮", "通霄鎮",
64
+ "苑裡鎮", "苗栗市", "造橋鄉", "頭屋鄉", "公館鄉", "大湖鄉", "泰安鄉",
65
+ "銅鑼鄉", "三義鄉", "西湖鄉", "卓蘭鎮"
66
+ ]
67
+ },
68
+ {
69
+ "name": "臺中市",
70
+ "districts": [
71
+ "中區", "東區", "南區", "西區", "北區", "北屯區", "西屯區", "南屯區",
72
+ "太平區", "大里區", "霧峰區", "烏日區", "豐原區", "后里區", "石岡區",
73
+ "東勢區", "和平區", "新社區", "潭子區", "大雅區", "神岡區", "大肚區",
74
+ "沙鹿區", "龍井區", "梧棲區", "清水區", "大甲區", "外埔區", "大安區"
75
+ ]
76
+ },
77
+ {
78
+ "name": "彰化縣",
79
+ "districts": [
80
+ "彰化市", "芬園鄉", "花壇鄉", "秀水鄉", "鹿港鎮", "福興鄉", "線西鄉",
81
+ "和美鎮", "伸港鄉", "員林鎮", "社頭鄉", "永靖鄉", "埔心鄉", "溪湖鎮",
82
+ "大村鄉", "埔鹽鄉", "田中鎮", "北斗鎮", "田尾鄉", "埤頭鄉", "溪州鄉",
83
+ "竹塘鄉", "二林鎮", "大城鄉", "芳苑鄉", "二水鄉"
84
+ ]
85
+ },
86
+ {
87
+ "name": "南投縣",
88
+ "districts": [
89
+ "南投市", "中寮鄉", "草屯鎮", "國姓鄉", "埔里鎮", "仁愛鄉", "名間鄉",
90
+ "集集鎮", "水里鄉", "魚池鄉", "信義鄉", "竹山鎮", "鹿谷鄉"
91
+ ]
92
+ },
93
+ {
94
+ "name": "雲林縣",
95
+ "districts": [
96
+ "斗南鎮", "大埤鄉", "虎尾鎮", "土庫鎮", "褒忠鄉", "東勢鄉", "臺西鄉",
97
+ "崙背鄉", "麥寮鄉", "斗六市", "林內鄉", "古坑鄉", "莿桐鄉", "西螺鎮",
98
+ "二崙鄉", "北港鎮", "水林鄉", "口湖鄉", "四湖鄉", "元長鄉"
99
+ ]
100
+ }
101
+ ]
102
+ },
103
+ {
104
+ "region": "南區",
105
+ "cities": [
106
+ {
107
+ "name": "嘉義市",
108
+ "districts": [
109
+ "西區", "東區"
110
+ ]
111
+ },
112
+ {
113
+ "name": "嘉義縣",
114
+ "districts": [
115
+ "番路鄉", "梅山鄉", "竹崎鄉", "阿里山鄉", "中埔鄉", "大埔鄉", "水上鄉",
116
+ "鹿草鄉", "太保市", "朴子市", "東石鄉", "六腳鄉", "新港鄉", "民雄鄉",
117
+ "大林鎮", "溪口鄉", "義竹鄉", "布袋鎮"
118
+ ]
119
+ },
120
+ {
121
+ "name": "臺南市",
122
+ "districts": [
123
+ "中西區", "東區", "南區", "北區", "安平區", "安南區", "永康區",
124
+ "歸仁區", "新化區", "左鎮區", "玉井區", "楠西區", "南化區", "仁德區",
125
+ "關廟區", "龍崎區", "官田區", "麻豆區", "佳里區", "西港區", "七股區",
126
+ "將軍區", "學甲區", "北門區", "新營區", "後壁區", "白河區", "東山區",
127
+ "六甲區", "下營區", "柳營區", "鹽水區", "善化區", "新市區", "大內區",
128
+ "山上區", "安定區"
129
+ ]
130
+ },
131
+ {
132
+ "name": "高雄市",
133
+ "districts": [
134
+ "新興區", "前金區", "苓雅區", "鹽埕區", "鼓山區", "旗津區", "前鎮區",
135
+ "三民區", "楠梓區", "小港區", "左營區", "仁武區", "大社區", "岡山區",
136
+ "路竹區", "阿蓮區", "田寮區", "燕巢區", "橋頭區", "梓官區", "彌陀區",
137
+ "永安區", "湖內區", "鳳山區", "大寮區", "林園區", "鳥松區", "大樹區",
138
+ "旗山區", "美濃區", "六龜區", "內門區", "杉林區", "甲仙區", "桃源區",
139
+ "那瑪夏", "茂林區", "茄萣區"
140
+ ]
141
+ },
142
+ {
143
+ "name": "屏東縣",
144
+ "districts": [
145
+ "屏東市", "三地門", "霧臺鄉", "瑪家鄉", "九如鄉", "里港鄉", "高樹鄉",
146
+ "鹽埔鄉", "長治鄉", "麟洛鄉", "竹田鄉", "內埔鄉", "萬丹鄉", "潮州鎮",
147
+ "泰武鄉", "來義鄉", "萬巒鄉", "崁頂鄉", "新埤鄉", "南州鄉", "林邊鄉",
148
+ "東港鎮", "琉球鄉", "佳冬鄉", "新園鄉", "枋寮鄉", "枋山鄉", "春日鄉",
149
+ "獅子鄉", "車城鄉", "牡丹鄉", "恆春鎮", "滿州鄉"
150
+ ]
151
+ }
152
+ ]
153
+ },
154
+ {
155
+ "region": "東區",
156
+ "cities": [
157
+ {
158
+ "name": "花蓮縣",
159
+ "districts": [
160
+ "花蓮市", "新城鄉", "秀林鄉", "吉安鄉", "壽豐鄉", "鳳林鎮", "光復鄉",
161
+ "豐濱鄉", "瑞穗鄉", "萬榮鄉", "玉里鎮", "卓溪鄉", "富里鄉"
162
+ ]
163
+ },
164
+ {
165
+ "name": "臺東縣",
166
+ "districts": [
167
+ "臺東市", "綠島鄉", "蘭嶼鄉", "延平鄉", "卑南鄉", "鹿野鄉", "關山鎮",
168
+ "海端鄉", "池上鄉", "東河鄉", "成功鎮", "長濱鄉", "太麻里", "金峰鄉",
169
+ "大武鄉", "達仁鄉"
170
+ ]
171
+ }
172
+ ]
173
+ },
174
+ {
175
+ "region": "離島",
176
+ "cities": [
177
+ {
178
+ "name": "澎湖縣",
179
+ "districts": [
180
+ "馬公市", "西嶼鄉", "望安鄉", "七美鄉", "白沙鄉", "湖西鄉"
181
+ ]
182
+ },
183
+ {
184
+ "name": "金門縣",
185
+ "districts": [
186
+ "金沙鎮", "金湖鎮", "金寧鄉", "金城鎮", "烈嶼鄉", "烏坵鄉"
187
+ ]
188
+ },
189
+ {
190
+ "name": "連江縣",
191
+ "districts": [
192
+ "南竿鄉", "北竿鄉", "莒光鄉", "東引鄉"
193
+ ]
194
+ },
195
+ {
196
+ "name": "離島地區",
197
+ "districts": [
198
+ "釣魚臺", "東沙群島", "南沙群島"
199
+ ]
200
+ }
201
+ ]
202
+ }
203
+ ]
@@ -0,0 +1,3 @@
1
+ module TaiwanDistrictsFormHelper
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "taiwan_districts_form_helper/version"
2
+ require "taiwan_districts_form_helper/form_builder"
3
+
4
+ module TaiwanDistrictsFormHelper
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/taiwan_districts_form_helper/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "taiwan_districts_form_helper"
5
+ spec.version = TaiwanDistrictsFormHelper::VERSION
6
+ spec.authors = ["Kao Chien Lung"]
7
+ spec.email = ["dev@5xcampus.com"]
8
+
9
+ spec.summary = %q{Form Helper for Taiwan regions, cities, and districts.}
10
+ spec.description = %q{Form Helper for Taiwan regions, cities, and districts.}
11
+ spec.homepage = "https://github.com/5xTraining/taiwan_districts_form_helper"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taiwan_districts_form_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kao Chien Lung
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Form Helper for Taiwan regions, cities, and districts.
14
+ email:
15
+ - dev@5xcampus.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - lib/taiwan_districts_form_helper.rb
29
+ - lib/taiwan_districts_form_helper/form_builder.rb
30
+ - lib/taiwan_districts_form_helper/location.json
31
+ - lib/taiwan_districts_form_helper/version.rb
32
+ - taiwan_districts_form_helper.gemspec
33
+ homepage: https://github.com/5xTraining/taiwan_districts_form_helper
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/5xTraining/taiwan_districts_form_helper
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.2.3
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Form Helper for Taiwan regions, cities, and districts.
57
+ test_files: []