rails_admin_settings 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/app/views/rails_admin/main/_setting_value.html.haml +1 -1
- data/config/locales/en.yml +1 -0
- data/config/locales/ru.yml +1 -0
- data/lib/rails_admin_settings/processing.rb +19 -1
- data/lib/rails_admin_settings/types.rb +1 -0
- data/lib/rails_admin_settings/validation.rb +13 -1
- data/lib/rails_admin_settings/version.rb +1 -1
- data/spec/types_spec.rb +13 -0
- metadata +2 -3
- data/gemfiles/mongoid-4.0.gemfile.lock +0 -130
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ea98edd6e8bad6c86e500d5dffd7fb55588fcd4
|
4
|
+
data.tar.gz: a5b9d884b4d4b5f7deeac4f3e46dc135e521721e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e4348c966b49d6252543f12d00090bafcf302a98b8a456aa4776c6dc401aed384dcc93b9f5be4a47c67a01d18b0eeb22597142b6b7d54731ab2dffa44c3548c
|
7
|
+
data.tar.gz: 378f2c80f910a6a73f25a4e70aebee49a4a812a5f315dfd20cb68003c8cd03ed1960c4aff8c82006b8b4bc22ae2849d1cad83ad2e8ae404b394468a5a8f1a148
|
data/.travis.yml
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
= form.text_field :raw, :value => field.value
|
3
3
|
- if @object.type == 'color'
|
4
4
|
= form.text_field :raw, :value => field.value, 'data-color' => true, style: "background-color: ##{field.value}"
|
5
|
-
- elsif
|
5
|
+
- elsif %w(text yaml phones).include?( @object.type )
|
6
6
|
= form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
|
7
7
|
- elsif @object.type == 'html'
|
8
8
|
- if form.respond_to?(:cktext_area)
|
data/config/locales/en.yml
CHANGED
@@ -4,6 +4,7 @@ en:
|
|
4
4
|
label: 'Settings'
|
5
5
|
no_ckeditor_detected: CKEditor not found — showing as text input
|
6
6
|
phone_invalid: Incorrect phone
|
7
|
+
phones_invalid: "Incorrect phone: %{phones}"
|
7
8
|
email_invalid: Incorrect email
|
8
9
|
yaml_invalid: Incorrect YAML
|
9
10
|
color_invalid: Incorrect color
|
data/config/locales/ru.yml
CHANGED
@@ -4,6 +4,7 @@ ru:
|
|
4
4
|
label: 'Настройки'
|
5
5
|
no_ckeditor_detected: CKEditor не обнаружен — отображаю настройку как текстовое поле
|
6
6
|
phone_invalid: Неверный телефонный номер
|
7
|
+
phones_invalid: "Неверный телефонный номер: %{phones}"
|
7
8
|
email_invalid: Неверный email
|
8
9
|
yaml_invalid: Неверный синтаксис YAML
|
9
10
|
color_invalid: Неверный цвет
|
@@ -7,7 +7,7 @@ module RailsAdminSettings
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def text_type?
|
10
|
-
(RailsAdminSettings.types - ['phone', 'integer', 'yaml']).include? type
|
10
|
+
(RailsAdminSettings.types - ['phone', 'phones', 'integer', 'yaml']).include? type
|
11
11
|
end
|
12
12
|
|
13
13
|
def upload_type?
|
@@ -71,11 +71,21 @@ module RailsAdminSettings
|
|
71
71
|
require_russian_phone do
|
72
72
|
RussianPhone::Number.new('')
|
73
73
|
end
|
74
|
+
elsif phones_type?
|
75
|
+
[]
|
74
76
|
else
|
75
77
|
nil
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
81
|
+
def default_serializable_value
|
82
|
+
if phones_type?
|
83
|
+
''
|
84
|
+
else
|
85
|
+
default_value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
79
89
|
def process_text
|
80
90
|
text = raw.dup
|
81
91
|
text.gsub!('{{year}}', Time.now.strftime('%Y'))
|
@@ -96,6 +106,12 @@ module RailsAdminSettings
|
|
96
106
|
end
|
97
107
|
end
|
98
108
|
|
109
|
+
def load_phones
|
110
|
+
require_russian_phone do
|
111
|
+
raw.gsub("\r", '').split("\n").map{|i| RussianPhone::Number.new(i)}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
99
115
|
def load_yaml
|
100
116
|
require_safe_yaml do
|
101
117
|
YAML.safe_load(raw)
|
@@ -111,6 +127,8 @@ module RailsAdminSettings
|
|
111
127
|
load_yaml
|
112
128
|
elsif phone_type?
|
113
129
|
load_phone
|
130
|
+
elsif phones_type?
|
131
|
+
load_phones
|
114
132
|
elsif file_type?
|
115
133
|
file.url
|
116
134
|
else
|
@@ -2,7 +2,7 @@ module RailsAdminSettings
|
|
2
2
|
module Validation
|
3
3
|
def self.included(base)
|
4
4
|
base.before_validation do
|
5
|
-
self.raw =
|
5
|
+
self.raw = default_serializable_value if raw.blank?
|
6
6
|
end
|
7
7
|
base.before_validation :sanitize_value, if: :sanitized_type?
|
8
8
|
base.validates_uniqueness_of :key, scope: :ns
|
@@ -15,6 +15,18 @@ module RailsAdminSettings
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
base.validate if: :phones_type? do
|
19
|
+
require_russian_phone do
|
20
|
+
unless raw.blank?
|
21
|
+
invalid_phones = raw.gsub("\r", '').split("\n").inject([]) do |memo, value|
|
22
|
+
memo << value unless RussianPhone::Number.new(value).valid?
|
23
|
+
memo
|
24
|
+
end
|
25
|
+
errors.add(:raw, I18n.t('admin.settings.phones_invalid', phones: invalid_phones * ', ')) unless invalid_phones.empty?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
base.validate if: :email_type? do
|
19
31
|
require_validates_email_format_of do
|
20
32
|
errors.add(:raw, I18n.t('admin.settings.email_invalid')) unless raw.blank? || ValidatesEmailFormatOf.validate_email_format(raw).nil?
|
data/spec/types_spec.rb
CHANGED
@@ -30,6 +30,19 @@ describe 'Settings types' do
|
|
30
30
|
Settings.get(:tphone).val.formatted_subscriber.should eq '111-11-11'
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'supports phones type' do
|
34
|
+
Settings.set(:tphone, ['906 111 11 11', '907 111 11 11'] * "\n", type: 'phones')
|
35
|
+
Settings.get(:tphone).val.class.name.should eq 'Array'
|
36
|
+
Settings.tphone.class.name.should eq 'Array'
|
37
|
+
Settings.get(:tphone).val.first.class.name.should eq 'RussianPhone::Number'
|
38
|
+
Settings.tphone.first.class.name.should eq 'RussianPhone::Number'
|
39
|
+
Settings.tphone.first.should eq '906 111 11 11'
|
40
|
+
Settings.get(:tphone).phones_type?.should be_true
|
41
|
+
Settings.get(:tphone).val.first.city.should eq '906'
|
42
|
+
Settings.get(:tphone).val.last.city.should eq '907'
|
43
|
+
Settings.get(:tphone).val.first.formatted_subscriber.should eq '111-11-11'
|
44
|
+
end
|
45
|
+
|
33
46
|
it 'defaults for phone' do
|
34
47
|
Settings.dphone(type: 'phone')
|
35
48
|
Settings.get(:dphone).phone_type?.should be_true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Tv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -271,7 +271,6 @@ files:
|
|
271
271
|
- config/locales/ru.yml
|
272
272
|
- gemfiles/mongoid-3.1.gemfile
|
273
273
|
- gemfiles/mongoid-4.0.gemfile
|
274
|
-
- gemfiles/mongoid-4.0.gemfile.lock
|
275
274
|
- lib/rails_admin_settings.rb
|
276
275
|
- lib/rails_admin_settings/dumper.rb
|
277
276
|
- lib/rails_admin_settings/engine.rb
|
@@ -1,130 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/mongoid/mongoid.git
|
3
|
-
revision: 151e2a937f08a3f2a45082bf0d84e4ba2ddaf2be
|
4
|
-
branch: master
|
5
|
-
specs:
|
6
|
-
mongoid (4.0.0.alpha2)
|
7
|
-
activemodel (>= 4.0.0)
|
8
|
-
moped (~> 2.0.beta5)
|
9
|
-
origin (~> 2.1)
|
10
|
-
tzinfo (>= 0.3.37)
|
11
|
-
|
12
|
-
PATH
|
13
|
-
remote: /data/rails_admin_settings
|
14
|
-
specs:
|
15
|
-
rails_admin_settings (0.6.1)
|
16
|
-
mongoid (>= 3.1)
|
17
|
-
|
18
|
-
GEM
|
19
|
-
remote: https://rubygems.org/
|
20
|
-
specs:
|
21
|
-
activemodel (4.0.2)
|
22
|
-
activesupport (= 4.0.2)
|
23
|
-
builder (~> 3.1.0)
|
24
|
-
activesupport (4.0.2)
|
25
|
-
i18n (~> 0.6, >= 0.6.4)
|
26
|
-
minitest (~> 4.2)
|
27
|
-
multi_json (~> 1.3)
|
28
|
-
thread_safe (~> 0.1)
|
29
|
-
tzinfo (~> 0.3.37)
|
30
|
-
addressable (2.3.5)
|
31
|
-
atomic (1.1.14)
|
32
|
-
bson (2.1.0)
|
33
|
-
builder (3.1.4)
|
34
|
-
carrierwave (0.9.0)
|
35
|
-
activemodel (>= 3.2.0)
|
36
|
-
activesupport (>= 3.2.0)
|
37
|
-
json (>= 1.7)
|
38
|
-
climate_control (0.0.3)
|
39
|
-
activesupport (>= 3.0)
|
40
|
-
cocaine (0.5.3)
|
41
|
-
climate_control (>= 0.0.3, < 1.0)
|
42
|
-
coderay (1.1.0)
|
43
|
-
connection_pool (1.2.0)
|
44
|
-
database_cleaner (1.2.0)
|
45
|
-
diff-lcs (1.2.5)
|
46
|
-
docile (1.1.1)
|
47
|
-
factory_girl (4.3.0)
|
48
|
-
activesupport (>= 3.0.0)
|
49
|
-
geocoder (1.1.9)
|
50
|
-
glebtv-carrierwave-mongoid (0.6.5)
|
51
|
-
carrierwave (>= 0.8.0, < 0.10.0)
|
52
|
-
mongoid (>= 3.0, < 5.0)
|
53
|
-
mongoid (>= 3.0, < 5.0)
|
54
|
-
glebtv-mongoid-paperclip (0.1.0)
|
55
|
-
paperclip (>= 2.3.6)
|
56
|
-
i18n (0.6.9)
|
57
|
-
json (1.8.1)
|
58
|
-
method_source (0.8.2)
|
59
|
-
mime-types (2.0)
|
60
|
-
mini_portile (0.5.2)
|
61
|
-
minitest (4.7.5)
|
62
|
-
mongoid-rspec (1.10.0)
|
63
|
-
mongoid (>= 3.0.1)
|
64
|
-
rake
|
65
|
-
rspec (>= 2.14)
|
66
|
-
moped (2.0.0.beta5)
|
67
|
-
bson (~> 2.1)
|
68
|
-
connection_pool (~> 1.2)
|
69
|
-
optionable (~> 0.2.0)
|
70
|
-
multi_json (1.8.4)
|
71
|
-
nokogiri (1.6.1)
|
72
|
-
mini_portile (~> 0.5.0)
|
73
|
-
optionable (0.2.0)
|
74
|
-
origin (2.1.0)
|
75
|
-
paperclip (3.5.2)
|
76
|
-
activemodel (>= 3.0.0)
|
77
|
-
activesupport (>= 3.0.0)
|
78
|
-
cocaine (~> 0.5.3)
|
79
|
-
mime-types
|
80
|
-
pry (0.9.12.4)
|
81
|
-
coderay (~> 1.0)
|
82
|
-
method_source (~> 0.8)
|
83
|
-
slop (~> 3.4)
|
84
|
-
rake (10.1.1)
|
85
|
-
rspec (2.14.1)
|
86
|
-
rspec-core (~> 2.14.0)
|
87
|
-
rspec-expectations (~> 2.14.0)
|
88
|
-
rspec-mocks (~> 2.14.0)
|
89
|
-
rspec-core (2.14.7)
|
90
|
-
rspec-expectations (2.14.4)
|
91
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
92
|
-
rspec-mocks (2.14.4)
|
93
|
-
russian_phone (0.3.5)
|
94
|
-
mongoid (>= 3.0.0)
|
95
|
-
safe_yaml (1.0.1)
|
96
|
-
sanitize (2.0.6)
|
97
|
-
nokogiri (>= 1.4.4)
|
98
|
-
simplecov (0.8.2)
|
99
|
-
docile (~> 1.1.0)
|
100
|
-
multi_json
|
101
|
-
simplecov-html (~> 0.8.0)
|
102
|
-
simplecov-html (0.8.0)
|
103
|
-
slop (3.4.7)
|
104
|
-
thread_safe (0.1.3)
|
105
|
-
atomic
|
106
|
-
tzinfo (0.3.38)
|
107
|
-
validates_email_format_of (1.5.3)
|
108
|
-
|
109
|
-
PLATFORMS
|
110
|
-
ruby
|
111
|
-
|
112
|
-
DEPENDENCIES
|
113
|
-
addressable (~> 2.3.3)
|
114
|
-
bundler
|
115
|
-
database_cleaner (~> 1.2.0)
|
116
|
-
factory_girl (~> 4.3.0)
|
117
|
-
geocoder (~> 1.1.6)
|
118
|
-
glebtv-carrierwave-mongoid
|
119
|
-
glebtv-mongoid-paperclip
|
120
|
-
mongoid!
|
121
|
-
mongoid-rspec (~> 1.10.0)
|
122
|
-
pry
|
123
|
-
rails_admin_settings!
|
124
|
-
rake (~> 10.1.1)
|
125
|
-
rspec (~> 2.14.1)
|
126
|
-
russian_phone (~> 0.3.2)
|
127
|
-
safe_yaml (~> 1.0.0)
|
128
|
-
sanitize (~> 2.0.3)
|
129
|
-
simplecov (~> 0.8.2)
|
130
|
-
validates_email_format_of (~> 1.5.3)
|