rails_admin_settings 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,6 +30,7 @@ Add this line to your application's Gemfile:
30
30
  - Put it after safe_yaml to get built-in support
31
31
  - Put it after validates_email_format_of to get built-in support
32
32
  - Put it after geocoder to get built-in support
33
+ - Put it after carrierwave / paperclip to get built-in support
33
34
 
34
35
  And then execute:
35
36
 
@@ -67,7 +68,7 @@ Supported types:
67
68
  phone (requires russian_phone)
68
69
  email (requires validates_email_format_of)
69
70
  address (requires geocoder)
70
-
71
+ file (requires paperclip or carrierwave)
71
72
 
72
73
  Strings and html support following replacement patterns:
73
74
 
@@ -22,6 +22,7 @@ module RailsAdminSettings
22
22
  include RailsAdminSettings::RequireHelpers
23
23
  include RailsAdminSettings::Processing
24
24
  include RailsAdminSettings::Validation
25
+ include RailsAdminSettings::Uploads
25
26
 
26
27
  def disabled?
27
28
  !enabled
@@ -32,8 +32,14 @@ module RailsAdminSettings
32
32
  'sanitized' == type
33
33
  end
34
34
 
35
+ def file_type?
36
+ 'file' == type
37
+ end
38
+
35
39
  def value
36
- if raw.blank? || disabled?
40
+ if file_type?
41
+ file.url
42
+ elsif raw.blank? || disabled?
37
43
  default_value
38
44
  else
39
45
  processed_value
@@ -112,7 +118,10 @@ module RailsAdminSettings
112
118
  load_yaml
113
119
  elsif phone_type?
114
120
  load_phone
121
+ elsif file_type?
122
+ file.url
115
123
  else
124
+ puts "[rails_admin_settings] Unknown field type: #{type}"
116
125
  nil
117
126
  end
118
127
  end
@@ -32,6 +32,14 @@ module RailsAdminSettings
32
32
  end
33
33
  field :raw do
34
34
  partial "setting_value"
35
+ visible do
36
+ !bindings[:object].file_type?
37
+ end
38
+ end
39
+ field :file do
40
+ visible do
41
+ bindings[:object].file_type?
42
+ end
35
43
  end
36
44
  end
37
45
  end
@@ -1,4 +1,8 @@
1
1
  class Settings
2
+ cattr_accessor :file_uploads_supported, :file_uploads_engine
3
+ @@file_uploads_supported = false
4
+ @@file_uploads_engine = false
5
+
2
6
  class << self
3
7
  @@loaded = false
4
8
  @@settings = {}
@@ -0,0 +1,9 @@
1
+ module RailsAdminSettings
2
+ module Uploads
3
+ class CarrierWave < CarrierWave::Uploader::Base
4
+ def extension_white_list
5
+ %w(jpg jpeg gif png tiff psd ai txt rtf doc docx xls xlsx ppt pptx odt odx zip rar 7z pdf)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module RailsAdminSettings
2
2
  def self.types
3
- ['string', 'integer', 'html', 'sanitized', 'yaml', 'phone', 'email', 'address']
3
+ ['string', 'integer', 'html', 'sanitized', 'yaml', 'phone', 'email', 'address', 'file']
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ module RailsAdminSettings
2
+ module Uploads
3
+ autoload :CarrierWave, "rails_admin_settings/storage/carrierwave"
4
+
5
+ def self.included(base)
6
+ # carrierwave
7
+ if base.respond_to?(:mount_uploader)
8
+ # puts "[rails_admin_settings] CarrierWave detected"
9
+ base.field(:file, type: String)
10
+ base.mount_uploader(:file, RailsAdminSettings::Uploads::CarrierWave)
11
+ Settings.file_uploads_supported = true
12
+ Settings.file_uploads_engine = :carrierwave
13
+ # paperclip
14
+ elsif base.respond_to?(:has_mongoid_attached_file)
15
+ # puts "[rails_admin_settings] PaperClip detected"
16
+ base.field(:file, type: String)
17
+ base.has_mongoid_attached_file(:file)
18
+ Settings.file_uploads_supported = true
19
+ Settings.file_uploads_engine = :paperclip
20
+ else
21
+ # puts "[rails_admin_settings] Uploads disabled"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -27,6 +27,13 @@ module RailsAdminSettings
27
27
  end
28
28
  end
29
29
 
30
+ base.validate if: :file_type? do
31
+ unless Settings.file_uploads_supported
32
+ raise '[rails_admin_settings] File type requires either CarrierWave or Paperclip. Check that rails_admin_settings is below them in Gemfile'
33
+ end
34
+ end
35
+
36
+
30
37
  if Object.const_defined?('Geocoder')
31
38
  base.field(:coordinates, type: Array, default: [])
32
39
  base.send(:include, Geocoder::Model::Mongoid)
@@ -1,3 +1,3 @@
1
1
  module RailsAdminSettings
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -5,6 +5,7 @@ module RailsAdminSettings
5
5
  autoload :Validation, "rails_admin_settings/validation"
6
6
  autoload :RequireHelpers, "rails_admin_settings/require_helpers"
7
7
  autoload :RailsAdminConfig, "rails_admin_settings/rails_admin_config"
8
+ autoload :Uploads, "rails_admin_settings/uploads"
8
9
  end
9
10
 
10
11
  require "rails_admin_settings/types"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -244,7 +244,9 @@ files:
244
244
  - lib/rails_admin_settings/rails_admin_config.rb
245
245
  - lib/rails_admin_settings/require_helpers.rb
246
246
  - lib/rails_admin_settings/settings.rb
247
+ - lib/rails_admin_settings/storage/carrierwave.rb
247
248
  - lib/rails_admin_settings/types.rb
249
+ - lib/rails_admin_settings/uploads.rb
248
250
  - lib/rails_admin_settings/validation.rb
249
251
  - lib/rails_admin_settings/version.rb
250
252
  - rails_admin_settings.gemspec
@@ -271,7 +273,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
273
  version: '0'
272
274
  segments:
273
275
  - 0
274
- hash: 4329122058332333433
276
+ hash: 126914792518638842
275
277
  required_rubygems_version: !ruby/object:Gem::Requirement
276
278
  none: false
277
279
  requirements:
@@ -280,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
282
  version: '0'
281
283
  segments:
282
284
  - 0
283
- hash: 4329122058332333433
285
+ hash: 126914792518638842
284
286
  requirements: []
285
287
  rubyforge_project:
286
288
  rubygems_version: 1.8.25