cs-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +26 -0
- data/app/assets/javascripts/cs-rails/application.js +13 -0
- data/app/assets/javascripts/cs-rails/countries.coffee.erb +7 -0
- data/app/assets/stylesheets/cs_rails/application.css +15 -0
- data/app/assets/stylesheets/cs_rails/states.css +4 -0
- data/app/controllers/cs_rails/application_controller.rb +4 -0
- data/app/controllers/cs_rails/states_controller.rb +11 -0
- data/app/helpers/cs_rails/application_helper.rb +4 -0
- data/app/helpers/cs_rails/states_helper.rb +4 -0
- data/app/views/cs_rails/states/index.coffee +18 -0
- data/app/views/layouts/cs_rails/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/lib/core_extensions/action_view/helpers/form_options_helper.rb +105 -0
- data/lib/cs-rails.rb +6 -0
- data/lib/cs-rails/engine.rb +16 -0
- data/lib/cs-rails/version.rb +3 -0
- data/lib/tasks/cs-rails_tasks.rake +4 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74553dd3b1904ff0e3b2fd52e42fe7499029869c
|
4
|
+
data.tar.gz: aba7bcf8f4f56fb860f7fe694ac8dacba19de7f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71a8d9df018f13a2808923cddbd3dc88aebf052b66d520dee737b0dff785162f2745743d8b4a2dc13ad24526243dac8e39ff9c13870bb9e920617fe8e340c0b3
|
7
|
+
data.tar.gz: d414799120eca1d10512d148749ef010c66f2c46a6512c1ee9a119df3fbb6986e22694d00e676592942a56ec85bd3e8a7f0d9601eac332fb61f5f607c3b20863
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Kadu Diógenes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'CsRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_dependency "cs_rails/application_controller"
|
2
|
+
|
3
|
+
module CsRails
|
4
|
+
class StatesController < ApplicationController
|
5
|
+
def index
|
6
|
+
@states = ::ISO3166::Country[params[:country_code]].states.map { |k, v| [v['name'], k] }
|
7
|
+
@state_input_id = params[:state_input_id]
|
8
|
+
respond_to { |format| format.js }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
properties = (control, class_remove, class_add) ->
|
2
|
+
{
|
3
|
+
id: control.attr 'id'
|
4
|
+
name: control.attr 'name'
|
5
|
+
class: control.attr('class').replace(class_remove, class_add)
|
6
|
+
}
|
7
|
+
|
8
|
+
states_length = "<%= @states.length %>"
|
9
|
+
state_input_id = "<%= @state_input_id %>" || "_state"
|
10
|
+
control = $("select[id$=#{state_input_id}], input[id$=#{state_input_id}]")
|
11
|
+
if states_length > 0
|
12
|
+
options = "<%=j options_for_select(@states) %>"
|
13
|
+
if control.prop('tagName') == 'INPUT'
|
14
|
+
control.replaceWith $('<select>', properties(control, 'string', 'select')).append(options)
|
15
|
+
else
|
16
|
+
control.empty().append options
|
17
|
+
else
|
18
|
+
control.replaceWith $('<input>', properties(control, 'select', 'string')) if control.prop('tagName') == 'SELECT'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CsRails</title>
|
5
|
+
<%= stylesheet_link_tag "cs_rails/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "cs_rails/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormOptionsHelper
|
4
|
+
# Generate select and country option tags for the given object and method. A
|
5
|
+
# common use of this would be to allow users to select a state subregion within
|
6
|
+
# a given country.
|
7
|
+
#
|
8
|
+
# object - The model object to generate the select for
|
9
|
+
# method - The attribute on the object
|
10
|
+
# options - Other options pertaining to option tag generation. See
|
11
|
+
# `region_options_for_select`.
|
12
|
+
# html_options - Options to use when generating the select tag- class,
|
13
|
+
# id, etc.
|
14
|
+
#
|
15
|
+
# Uses country_options_for_select to generate the list of option tags.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
#
|
19
|
+
# country_select(@object, :country, {priority: ['US', 'CA']}, class: 'country')
|
20
|
+
#
|
21
|
+
# Note that in order to preserve compatibility with various existing
|
22
|
+
# libraries, an alternative API is supported but not recommended:
|
23
|
+
#
|
24
|
+
# country_select(@object, :region, ['US', 'CA'], class: region)
|
25
|
+
#
|
26
|
+
# Returns an `html_safe` string containing the HTML for a select element.
|
27
|
+
def country_select(object, method, priority_or_options = {}, options = {}, html_options = {})
|
28
|
+
if Hash === priority_or_options
|
29
|
+
html_options = options
|
30
|
+
options = priority_or_options
|
31
|
+
else
|
32
|
+
options[:priority] = priority_or_options
|
33
|
+
end
|
34
|
+
select_tag = ActionView::Helpers::Tags::Base.new(object, method, self, options)
|
35
|
+
select_tag.to_country_select_tag(ISO3166::Country.all, options, html_options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def country_options_for_select(countries, selected = nil, options = {})
|
39
|
+
language = I18n.locale.to_s.sub(/-.*/, '')
|
40
|
+
country_options = ''
|
41
|
+
priority_countries_codes = options[:priority] || []
|
42
|
+
|
43
|
+
unless priority_countries_codes.empty?
|
44
|
+
countries = ISO3166::Country.all unless countries.empty?
|
45
|
+
priority_countries = priority_countries_codes.map do |code|
|
46
|
+
country = ISO3166::Country[code]
|
47
|
+
[country.translation(language) || country.name, country.alpha2] if country
|
48
|
+
end.compact
|
49
|
+
unless priority_countries.empty?
|
50
|
+
country_options += options_for_select(priority_countries, selected)
|
51
|
+
country_options += "<option disabled>-------------</option>"
|
52
|
+
|
53
|
+
selected = nil if priority_countries_codes.include?(selected)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
collator = ICU::Collation::Collator.new(I18n.locale.to_s)
|
58
|
+
main_options = countries.map { |c| [c.translation(language) || c.name, c.alpha2] }
|
59
|
+
main_options.sort! { |a, b| collator.compare(a.first, b.first) }
|
60
|
+
main_options.unshift [options['prompt'], ''] if options['prompt']
|
61
|
+
|
62
|
+
country_options += options_for_select(main_options, selected)
|
63
|
+
country_options.html_safe
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module Tags
|
68
|
+
class Base
|
69
|
+
def to_country_select_tag(countries, options = {}, html_options = {})
|
70
|
+
html_options = html_options.stringify_keys
|
71
|
+
add_default_name_and_id(html_options)
|
72
|
+
options[:include_blank] ||= true unless options[:prompt] || select_not_required?(html_options)
|
73
|
+
|
74
|
+
value = options[:selected] ? options[:selected] : value(object)
|
75
|
+
priority_regions = options[:priority] || []
|
76
|
+
opts = add_options(country_options_for_select(countries, value, :priority => priority_regions), options, value)
|
77
|
+
select = content_tag("select", opts, html_options)
|
78
|
+
if html_options["multiple"] && options.fetch(:include_hidden, true)
|
79
|
+
tag("input", :disabled => html_options["disabled"], :name => html_options["name"], :type => "hidden", :value => "") + select
|
80
|
+
else
|
81
|
+
select
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class FormBuilder
|
88
|
+
# Generate select and country option tags with the provided name. A
|
89
|
+
# common use of this would be to allow users to select a country name inside a
|
90
|
+
# web form.
|
91
|
+
#
|
92
|
+
# See `FormOptionsHelper::country_select` for more information.
|
93
|
+
def country_select(method, priority_or_options = {}, options = {}, html_options = {})
|
94
|
+
if Hash === priority_or_options
|
95
|
+
html_options = options
|
96
|
+
options = priority_or_options
|
97
|
+
else
|
98
|
+
options[:priority] = priority_or_options
|
99
|
+
end
|
100
|
+
|
101
|
+
@template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/cs-rails.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module CsRails
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace CsRails
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec,
|
7
|
+
fixtures: true,
|
8
|
+
view_specs: false,
|
9
|
+
routing_specs: false,
|
10
|
+
controller_specs: true,
|
11
|
+
request_specs: false
|
12
|
+
g.template_engine :haml
|
13
|
+
g.javascript_engine :coffee
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cs-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kadu Diógenes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coffee-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: countries
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pg
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.18'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.18'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: haml-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
description: Country and state selects for Rails, inspired by carmen-rails.
|
98
|
+
email:
|
99
|
+
- kadu.diogenes@fnix.com.br
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- Rakefile
|
106
|
+
- app/assets/javascripts/cs-rails/application.js
|
107
|
+
- app/assets/javascripts/cs-rails/countries.coffee.erb
|
108
|
+
- app/assets/stylesheets/cs_rails/application.css
|
109
|
+
- app/assets/stylesheets/cs_rails/states.css
|
110
|
+
- app/controllers/cs_rails/application_controller.rb
|
111
|
+
- app/controllers/cs_rails/states_controller.rb
|
112
|
+
- app/helpers/cs_rails/application_helper.rb
|
113
|
+
- app/helpers/cs_rails/states_helper.rb
|
114
|
+
- app/views/cs_rails/states/index.coffee
|
115
|
+
- app/views/layouts/cs_rails/application.html.erb
|
116
|
+
- config/routes.rb
|
117
|
+
- lib/core_extensions/action_view/helpers/form_options_helper.rb
|
118
|
+
- lib/cs-rails.rb
|
119
|
+
- lib/cs-rails/engine.rb
|
120
|
+
- lib/cs-rails/version.rb
|
121
|
+
- lib/tasks/cs-rails_tasks.rake
|
122
|
+
homepage: https://github.com/fnix/cs-rails
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.8
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Not Counter-Strike, country and states for Rails.
|
146
|
+
test_files: []
|