activeadmin-settings 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -2
- data/activeadmin-settings.gemspec +2 -4
- data/app/models/activeadmin_settings/picture.rb +57 -36
- data/app/models/activeadmin_settings/setting.rb +72 -46
- data/db/migrate/20121123145121_create_activeadmin_settings_pictures.rb +13 -0
- data/db/migrate/20121123145237_create_activeadmin_settings_settings.rb +11 -0
- data/lib/activeadmin-settings.rb +4 -2
- data/lib/activeadmin-settings/helper.rb +4 -4
- data/lib/activeadmin-settings/version.rb +1 -1
- metadata +6 -26
data/README.md
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
**IN DEVELOPMENT**
|
4
4
|
|
5
|
-
|
5
|
+
**TODO**: use yaml file only for settings synchronisation, all settings should be stored in db with all those default values and other meta.
|
6
6
|
|
7
|
-
|
7
|
+
Easy to use general purpose settings backend for activeadmin.
|
8
|
+
|
9
|
+
![ActiveadminSettings Demo](https://raw.github.com/slate-studio/activeadmin-settings/master/img/activeadmin-settings-demo.jpg)
|
8
10
|
|
9
11
|
|
10
12
|
### Installation
|
@@ -17,6 +19,22 @@ Run installer:
|
|
17
19
|
|
18
20
|
$ rails g activeadmin_settings:install
|
19
21
|
|
22
|
+
#### ActiveRecord
|
23
|
+
|
24
|
+
gem "aws-s3"
|
25
|
+
gem "fog"
|
26
|
+
gem "mini_magick"
|
27
|
+
gem "carrierwave"
|
28
|
+
|
29
|
+
gem "bson_ext"
|
30
|
+
gem "devise"
|
31
|
+
gem "activeadmin-settings"
|
32
|
+
|
33
|
+
Run migrations:
|
34
|
+
|
35
|
+
$ rake activeadmin_settings:install:migrations
|
36
|
+
$ rake db:migrate
|
37
|
+
|
20
38
|
#### Mongoid 2.x
|
21
39
|
|
22
40
|
If you're using mongoid 2.x the gem expects to see **activeadmin-mongoid** and **carrierwave-mongoid** (for image uploading feature) in Gemfile. Here is a working example:
|
@@ -28,6 +46,7 @@ If you're using mongoid 2.x the gem expects to see **activeadmin-mongoid** and *
|
|
28
46
|
|
29
47
|
gem "bson_ext"
|
30
48
|
gem "mongoid"
|
49
|
+
gem "mongoid-globalize"
|
31
50
|
gem "devise"
|
32
51
|
gem "activeadmin-mongoid"
|
33
52
|
gem "activeadmin-settings"
|
@@ -51,6 +70,7 @@ Here is an example of Gemfile with a support of 3.x version:
|
|
51
70
|
# Activeadmin
|
52
71
|
gem 'devise', '>= 2.1.2'
|
53
72
|
gem 'activeadmin-mongoid', git: 'git://github.com/elia/activeadmin-mongoid.git'
|
73
|
+
gem "mongoid-globalize"
|
54
74
|
gem 'activeadmin-settings'
|
55
75
|
|
56
76
|
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.version = ActiveadminSettings::VERSION
|
7
7
|
gem.authors = ["Alex Kravets"]
|
8
8
|
gem.email = ["santyor@gmail.com"]
|
9
|
-
gem.homepage = "https://github.com/
|
9
|
+
gem.homepage = "https://github.com/slate-studio/activeadmin-settings"
|
10
10
|
gem.description = "Easy to use general purpose settings backend for activeadmin"
|
11
11
|
gem.summary = ""
|
12
12
|
|
@@ -14,6 +14,4 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.files = `git ls-files`.split($\)
|
15
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
-
|
18
|
-
gem.add_runtime_dependency "mongoid_globalize"
|
19
|
-
end
|
17
|
+
end
|
@@ -1,48 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
include Mongoid::Timestamps
|
1
|
+
module ActiveadminSettings
|
2
|
+
module PictureMethods
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
field :height, :type => Integer
|
4
|
+
def self.included(base)
|
5
|
+
# Features
|
6
|
+
base.mount_uploader :data, ActiveadminSettings::RedactorPictureUploader
|
7
|
+
end
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
# Helpers
|
10
|
+
def has_dimensions?
|
11
|
+
respond_to?(:width) && respond_to?(:height)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
def image?
|
15
|
+
ActiveadminSettings::IMAGE_TYPES.include?(data_content_type)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
18
|
+
def url
|
19
|
+
data.url
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def image
|
23
|
+
url
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def thumb
|
27
|
+
data.thumb.url
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def as_json_methods
|
31
|
+
[:image, :thumb]
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
def as_json(options = nil)
|
35
|
+
options = {
|
36
|
+
:methods => as_json_methods
|
37
|
+
}
|
38
|
+
super options
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
if defined?(Mongoid)
|
43
|
+
class Picture
|
44
|
+
include Mongoid::Document
|
45
|
+
include Mongoid::Timestamps
|
46
|
+
|
47
|
+
# Fields
|
48
|
+
field :data_file_size
|
49
|
+
field :data_content_type
|
50
|
+
field :width, :type => Integer
|
51
|
+
field :height, :type => Integer
|
52
|
+
|
53
|
+
include PictureMethods
|
54
|
+
|
55
|
+
# Scopes
|
56
|
+
default_scope order_by(:created_at => :desc)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
class Picture < ActiveRecord::Base
|
60
|
+
|
61
|
+
attr_accessible :data_content_type, :data_file_size, :height, :width, :data
|
62
|
+
|
63
|
+
include PictureMethods
|
41
64
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}
|
46
|
-
super options
|
65
|
+
# Scopes
|
66
|
+
default_scope order('created_at desc')
|
67
|
+
end
|
47
68
|
end
|
48
|
-
end
|
69
|
+
end
|
@@ -1,59 +1,85 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# Fields
|
7
|
-
field :name
|
8
|
-
|
9
|
-
translates do
|
10
|
-
field :string, :default => ""
|
11
|
-
fallbacks_for_empty_translations!
|
12
|
-
end
|
1
|
+
module ActiveadminSettings
|
2
|
+
module SettingMethods
|
3
|
+
def self.included(base)
|
4
|
+
base.mount_uploader :file, ActiveadminSettings::SettingsFileUploader
|
13
5
|
|
14
|
-
|
6
|
+
# Validators
|
7
|
+
base.validates_presence_of :name
|
8
|
+
base.validates_uniqueness_of :name
|
9
|
+
base.validates_length_of :name, minimum: 1
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
validates_uniqueness_of :name
|
19
|
-
validates_length_of :name, minimum: 1
|
11
|
+
base.extend ClassMethods
|
12
|
+
end
|
20
13
|
|
21
|
-
# Indexes
|
22
|
-
index :name rescue index name: 1
|
23
|
-
# Mongoid 3.x workaround
|
24
14
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
# Class
|
16
|
+
module ClassMethods
|
17
|
+
def initiate_setting(name)
|
18
|
+
s = self.new(name: name)
|
19
|
+
if s.type == "text" or s.type == "html"
|
20
|
+
s.string = s.default_value
|
21
|
+
end
|
22
|
+
s.save
|
23
|
+
s
|
24
|
+
end
|
25
|
+
end
|
29
26
|
|
30
|
-
def description
|
31
|
-
(ActiveadminSettings.all_settings[name]["description"] ||= "").to_s
|
32
|
-
end
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
# Instance
|
29
|
+
def type
|
30
|
+
(ActiveadminSettings.all_settings[name]["type"] ||= "string").to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
(ActiveadminSettings.all_settings[name]["description"] ||= "").to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_value
|
38
|
+
val = (ActiveadminSettings.all_settings[name]["default_value"] ||= "").to_s
|
39
|
+
|
40
|
+
if type == "file" and not val.include? '//'
|
41
|
+
val = ActionController::Base.helpers.asset_path(val)
|
42
|
+
end
|
43
|
+
|
44
|
+
val
|
45
|
+
end
|
46
|
+
|
47
|
+
def value
|
48
|
+
val = respond_to?(type) ? send(type).to_s : send(:string).to_s
|
49
|
+
val = default_value if val.empty?
|
50
|
+
val.html_safe
|
39
51
|
end
|
40
|
-
|
41
|
-
val
|
42
|
-
end
|
43
52
|
|
44
|
-
def value
|
45
|
-
val = respond_to?(type) ? send(type).to_s : send(:string).to_s
|
46
|
-
val = default_value if val.empty?
|
47
|
-
val.html_safe
|
48
53
|
end
|
49
54
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
if defined?(Mongoid)
|
56
|
+
class Setting
|
57
|
+
include Mongoid::Document
|
58
|
+
include Mongoid::Timestamps
|
59
|
+
include Mongoid::Globalize
|
60
|
+
|
61
|
+
# Fields
|
62
|
+
field :name
|
63
|
+
|
64
|
+
translates do
|
65
|
+
field :string, :default => ""
|
66
|
+
fallbacks_for_empty_translations!
|
67
|
+
end
|
68
|
+
|
69
|
+
include SettingMethods
|
70
|
+
|
71
|
+
def self.[](name)
|
72
|
+
find_or_create_by(:name => name).value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
else
|
76
|
+
class Setting < ActiveRecord::Base
|
77
|
+
include SettingMethods
|
78
|
+
attr_accessible :name, :string, :file
|
79
|
+
|
80
|
+
def self.[](name)
|
81
|
+
find_or_create_by_name(name).value
|
82
|
+
end
|
55
83
|
end
|
56
|
-
s.save
|
57
|
-
s
|
58
84
|
end
|
59
85
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateActiveadminSettingsPictures < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :activeadmin_settings_pictures do |t|
|
4
|
+
t.string :data
|
5
|
+
t.string :data_file_size
|
6
|
+
t.string :data_content_type
|
7
|
+
t.integer :width
|
8
|
+
t.integer :height
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/activeadmin-settings.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require "activeadmin-settings/version"
|
2
2
|
|
3
|
-
require "mongoid_globalize"
|
4
|
-
|
5
3
|
module ActiveadminSettings
|
4
|
+
def self.table_name_prefix
|
5
|
+
'activeadmin_settings_'
|
6
|
+
end
|
7
|
+
|
6
8
|
require 'activeadmin-settings/engine'
|
7
9
|
require 'activeadmin-settings/helper'
|
8
10
|
require 'activeadmin-settings/routing'
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module ActiveadminSettings
|
2
2
|
module Helpers
|
3
3
|
def settings_value(name)
|
4
|
-
Setting
|
4
|
+
Setting[name]
|
5
5
|
end
|
6
6
|
|
7
7
|
def settings_link_value(name, html_options={})
|
8
|
-
val = Setting
|
9
|
-
|
8
|
+
val = Setting[name]
|
9
|
+
|
10
10
|
if not val.empty? # add regular expression check here
|
11
11
|
title, url = val.split(')')
|
12
12
|
title.gsub!('(', '').strip!
|
@@ -14,7 +14,7 @@ module ActiveadminSettings
|
|
14
14
|
|
15
15
|
link_to(title, url, html_options)
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
18
18
|
|
19
19
|
module_function :settings_value, :settings_link_value
|
20
20
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: mongoid_globalize
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
30
14
|
description: Easy to use general purpose settings backend for activeadmin
|
31
15
|
email:
|
32
16
|
- santyor@gmail.com
|
@@ -52,6 +36,8 @@ files:
|
|
52
36
|
- app/views/admin/settings/_admins_table.html.erb
|
53
37
|
- app/views/admin/settings/_index.html.erb
|
54
38
|
- app/views/admin/settings/_settings_table.html.erb
|
39
|
+
- db/migrate/20121123145121_create_activeadmin_settings_pictures.rb
|
40
|
+
- db/migrate/20121123145237_create_activeadmin_settings_settings.rb
|
55
41
|
- img/activeadmin-settings-demo.jpg
|
56
42
|
- lib/activeadmin-settings.rb
|
57
43
|
- lib/activeadmin-settings/.DS_Store
|
@@ -73,7 +59,7 @@ files:
|
|
73
59
|
- vendor/assets/javascripts/redactor.js.erb
|
74
60
|
- vendor/assets/stylesheets/activeadmin_settings.css.scss
|
75
61
|
- vendor/assets/stylesheets/redactor.css
|
76
|
-
homepage: https://github.com/
|
62
|
+
homepage: https://github.com/slate-studio/activeadmin-settings
|
77
63
|
licenses: []
|
78
64
|
post_install_message:
|
79
65
|
rdoc_options: []
|
@@ -85,18 +71,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
71
|
- - ! '>='
|
86
72
|
- !ruby/object:Gem::Version
|
87
73
|
version: '0'
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
hash: 2595808076055630025
|
91
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
75
|
none: false
|
93
76
|
requirements:
|
94
77
|
- - ! '>='
|
95
78
|
- !ruby/object:Gem::Version
|
96
79
|
version: '0'
|
97
|
-
segments:
|
98
|
-
- 0
|
99
|
-
hash: 2595808076055630025
|
100
80
|
requirements: []
|
101
81
|
rubyforge_project:
|
102
82
|
rubygems_version: 1.8.24
|