activeadmin-settings 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ class ActiveadminSettings::Setting
5
5
  # Fields
6
6
  field :name
7
7
  field :string, :default => ""
8
- mount_uploader :file, SettingsFileUploader
8
+ mount_uploader :file, ActiveadminSettings::SettingsFileUploader
9
9
 
10
10
  # Validators
11
11
  validates_presence_of :name
@@ -25,7 +25,13 @@ class ActiveadminSettings::Setting
25
25
  end
26
26
 
27
27
  def default_value
28
- (ActiveadminSettings.all_settings[name]["default_value"] ||= "").to_s
28
+ val = (ActiveadminSettings.all_settings[name]["default_value"] ||= "").to_s
29
+
30
+ if type == "file" and not val.include? '//'
31
+ val = ActionController::Base.helpers.asset_path(val)
32
+ end
33
+
34
+ val
29
35
  end
30
36
 
31
37
  def value
@@ -0,0 +1,5 @@
1
+ class ActiveadminSettings::SettingsFileUploader < CarrierWave::Uploader::Base
2
+ def store_dir
3
+ "system/settings/files/#{model.id}"
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveadminSettings
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -6,14 +6,6 @@ module ActiveadminSettings
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
 
8
8
  def copy_files
9
- # models
10
- puts "Installing models:"
11
- copy_file "models/setting.rb", "app/models/activeadmin_settings/setting.rb"
12
-
13
- # uploaders
14
- puts "Installing uploaders:"
15
- copy_file "uploaders/settings_file_uploader.rb", "app/uploaders/settings_file_uploader.rb"
16
-
17
9
  # admin
18
10
  puts "Installing admin:"
19
11
  copy_file "admin/settings.rb", "app/admin/settings.rb"
@@ -1,24 +1,33 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  namespace :activeadmin do
4
- desc "Create default admin user"
5
- task :create_admin => :environment do
6
- AdminUser.create :email => 'admin@example.com', :password => 'password', :password_confirmation => 'password'
7
- puts "New admin user created:
8
- email: admin@example.com
9
- password: password"
10
- end
4
+ namespace :settings do
5
+ desc "Create default admin user"
6
+ task :create_admin => :environment do
7
+ AdminUser.create :email => 'admin@example.com', :password => 'password', :password_confirmation => 'password'
8
+ puts "New admin user created:
9
+ email: admin@example.com
10
+ password: password"
11
+ end
11
12
 
12
- desc "Add missing settings from activeadmin_settings.yml file to the db"
13
- task :add_settings => :environment do
14
- ActiveadminSettings.all_settings.each_key do |name|
15
- puts "Add setting: #{name}"
16
- ActiveadminSettings::Setting.find_or_create_by(name: name)
13
+ desc "Add missing settings from activeadmin_settings.yml file to the db"
14
+ task :add => :environment do
15
+ ActiveadminSettings.all_settings.each_key do |name|
16
+ puts "Add setting: #{name}"
17
+ s = ActiveadminSettings::Setting.find_or_create_by(name: name)
18
+
19
+ # Save default text values to db,
20
+ # as this way it's more easy to edit them
21
+ if s.type == "text"
22
+ s.string = s.default_value
23
+ s.save
24
+ end
25
+ end
17
26
  end
18
- end
19
27
 
20
- desc "Add settings from activeadmin_settings.yml file to the db"
21
- task :flush_settings => :environment do
22
- ActiveadminSettings::Setting.all.destroy
28
+ desc "Add settings from activeadmin_settings.yml file to the db"
29
+ task :flush => :environment do
30
+ ActiveadminSettings::Setting.all.destroy
31
+ end
23
32
  end
24
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,6 +24,8 @@ files:
24
24
  - activeadmin-settings.gemspec
25
25
  - app/controller/activeadmin_settings/admin_users_controller.rb
26
26
  - app/controller/activeadmin_settings/settings_controller.rb
27
+ - app/models/activeadmin_settings/setting.rb
28
+ - app/uploaders/activeadmin_settings/settings_file_uploader.rb
27
29
  - app/views/admin/settings/_admin.html.erb
28
30
  - app/views/admin/settings/_admin_form.html.erb
29
31
  - app/views/admin/settings/_admins_table.html.erb
@@ -38,8 +40,6 @@ files:
38
40
  - lib/generators/activeadmin_settings/install_generator.rb
39
41
  - lib/generators/activeadmin_settings/templates/admin/settings.rb
40
42
  - lib/generators/activeadmin_settings/templates/config/activeadmin_settings.yml
41
- - lib/generators/activeadmin_settings/templates/models/setting.rb
42
- - lib/generators/activeadmin_settings/templates/uploaders/settings_file_uploader.rb
43
43
  - lib/tasks/activeadmin_settings.rake
44
44
  - vendor/assets/javascripts/activeadmin_settings/admins.js.coffee
45
45
  - vendor/assets/javascripts/activeadmin_settings/flashes.js.coffee
@@ -63,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  segments:
65
65
  - 0
66
- hash: -2786191008632219396
66
+ hash: -2743706927528205930
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  none: false
69
69
  requirements:
@@ -1,5 +0,0 @@
1
- class SettingsFileUploader < CarrierWave::Uploader::Base
2
- def store_dir
3
- "system/settings/files/#{model.id}"
4
- end
5
- end