thecore_settings 1.1.15 → 2.0.5

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +20 -0
  3. data/.devcontainer/devcontainer.json +33 -0
  4. data/.github/workflows/gempush.yml +34 -0
  5. data/.gitignore +542 -0
  6. data/.rakeTasks +7 -0
  7. data/.rspec +1 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +31 -0
  10. data/CHANGELOG.md +81 -0
  11. data/Gemfile +4 -0
  12. data/Gemfile.lock +275 -0
  13. data/LICENSE.txt +22 -0
  14. data/README.md +169 -0
  15. data/README.rdoc +68 -0
  16. data/Rakefile +6 -34
  17. data/app/{assets/config/thecore_settings_manifest.js → models/.keep} +0 -0
  18. data/app/models/thecore_settings/setting.rb +77 -0
  19. data/app/views/.keep +0 -0
  20. data/app/views/rails_admin/main/_setting_value.html.haml +41 -0
  21. data/bin/rails +13 -0
  22. data/config/locales/en.yml +29 -0
  23. data/config/locales/{thecore_settings.it.yml → it.yml} +2 -2
  24. data/config/locales/pt-BR.yml +28 -0
  25. data/config/locales/ru.yml +29 -0
  26. data/db/migrate/20161227101954_create_rails_admin_settings.rb +4 -4
  27. data/gemfiles/mongoid-6.0.gemfile +5 -0
  28. data/gemfiles/mongoid-6.3.gemfile +5 -0
  29. data/lib/generators/thecore_settings/migration_generator.rb +15 -0
  30. data/lib/generators/thecore_settings/templates/db/migrate/20161227101954_create_thecore_settings.rb +29 -0
  31. data/lib/generators/thecore_settings/templates/migration.rb +29 -0
  32. data/lib/thecore_settings/determine_mime_type.rb +193 -0
  33. data/lib/thecore_settings/dumper.rb +12 -0
  34. data/lib/thecore_settings/engine.rb +17 -3
  35. data/lib/thecore_settings/fallback.rb +21 -0
  36. data/lib/thecore_settings/hex_color_validator.rb +11 -0
  37. data/lib/thecore_settings/kinds.rb +34 -0
  38. data/lib/thecore_settings/mongoid.rb +19 -0
  39. data/lib/thecore_settings/namespaced.rb +210 -0
  40. data/lib/thecore_settings/processing.rb +217 -0
  41. data/lib/thecore_settings/rails_admin_config.rb +71 -0
  42. data/lib/thecore_settings/require_helpers.rb +86 -0
  43. data/lib/thecore_settings/settings.rb +95 -0
  44. data/lib/thecore_settings/storage/carrier_wave_uploader.rb +9 -0
  45. data/lib/thecore_settings/storage/shrine_uploader.rb +14 -0
  46. data/lib/thecore_settings/tasks.rb +35 -0
  47. data/lib/thecore_settings/uploads.rb +57 -0
  48. data/lib/thecore_settings/validation.rb +126 -0
  49. data/lib/thecore_settings/version.rb +1 -1
  50. data/lib/thecore_settings.rb +115 -123
  51. data/spec/advanced_usage_spec.rb +11 -0
  52. data/spec/carrierwave_spec.rb +41 -0
  53. data/spec/database_trickery_spec.rb +48 -0
  54. data/spec/defaults_spec.rb +87 -0
  55. data/spec/enabling_spec.rb +29 -0
  56. data/spec/factories/setting.rb +8 -0
  57. data/spec/label_spec.rb +16 -0
  58. data/spec/migration_spec.rb +20 -0
  59. data/spec/model_spec.rb +105 -0
  60. data/spec/namespaced_spec.rb +67 -0
  61. data/spec/paperclip_spec.rb +38 -0
  62. data/spec/settings_spec.rb +75 -0
  63. data/spec/shrine_spec.rb +34 -0
  64. data/spec/spec_helper.rb +85 -0
  65. data/spec/support/1024x768.gif +0 -0
  66. data/spec/support/database_cleaner.rb +10 -0
  67. data/spec/support/defaults.yml +23 -0
  68. data/spec/support/defaults_w_file.yml +19 -0
  69. data/spec/support/mongoid.rb +6 -0
  70. data/spec/support/mongoid.yml +6 -0
  71. data/spec/types_spec.rb +101 -0
  72. data/thecore_settings.gemspec +44 -0
  73. metadata +326 -63
  74. data/app/assets/stylesheets/rich/editor.css +0 -20
  75. data/config/initializers/rails_admin_requirements.rb +0 -22
  76. data/config/initializers/thecore_settings_abilities.rb +0 -22
  77. data/config/initializers/thecore_settings_post_init.rb +0 -9
  78. data/config/routes.rb +0 -3
  79. data/db/migrate/20161227101956_add_app_name.rb +0 -5
  80. data/lib/tasks/thecore_settings_tasks.rake +0 -4
data/README.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ === Rails Admin
2
+
3
+ Since 1.4.7, it is the user's responsibility to create assets/javascripts/rails_admin/custom/ui.js and include rich
4
+
5
+ //= require rich/base
6
+
7
+ To use Rich in your RA forms, use the following in your initializer:
8
+
9
+ config.model Post do
10
+ edit do
11
+ field :title
12
+ field :body, :rich_editor do
13
+ config({
14
+ :insert_many => true
15
+ })
16
+ end
17
+ end
18
+ end
19
+
20
+ To use the image picker on a string field, do this:
21
+
22
+ field :title, :rich_picker do
23
+ config({
24
+ :allowed_styles => [:original],
25
+ :view_mode => "list"
26
+ })
27
+ end
28
+
29
+ == Rich in production mode
30
+
31
+ Rich works just fine in production mode. To accommodate the structure of the CKEditor source, Rich extends the <tt>assets:precompile</tt> task to make sure the full CKEditor source tree is copied to your assets folder. So the following works as you would expect:
32
+
33
+ rake assets:precompile
34
+
35
+ Rich will also clean up these CKEditor files when you clean your assets. Like this:
36
+
37
+ rake assets:clean
38
+
39
+ Although generally not necessary, the underlying Rich tasks can be invoked directly.
40
+
41
+ rake rich:assetize_ckeditor
42
+ rake rich:clean_ckeditor
43
+
44
+ == Configuration and overrides
45
+
46
+ Take a look at the generated <tt>rich.rb</tt> initializer and – if you want to dig deeper – the Rich sourcecode. The initializer guides you through the most important settings and configuration options.
47
+
48
+ === Localization
49
+
50
+ Localization should be automatic. Rich uses the currently set locale (<tt>I18n.locale</tt>) for it's editor and file browser.
51
+
52
+ === CKEditor configuration
53
+
54
+ Rich attempts to provide you with a sensible set of buttons and capabilities. But of course, you might disagree. To that end, you can configure CKEditor through the <tt>config</tt> directive, either globally through the initializer, or per editor instance as an option.
55
+
56
+ Rich also includes a few settings that manipulate CKEditor settings, but are a bit easier to use. For example, you can set <tt>:allow_embeds</tt> to <tt>true</tt> to load a media embed plugin (think Youtube, Vimeo, etc.)
57
+
58
+ === Editor styles
59
+
60
+ When you run the generator a css file is created for you in <tt>app/assets/stylesheets/rich/editor.css</tt>. Use this stylesheet to define the contents of the Styles drop down in CKEditor.
61
+
62
+ === Image configuration & (re)processing
63
+
64
+ The styles you define in the initializer are passed to Paperclip directly, so the syntax is identical. See https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation for more information. You can also set additional processing options using <tt>convert_options</tt>. See your Rich initializer for more information.
65
+
66
+ When you change styles after uploading files, you will need to re-process those old files. To accomplish this, run the following command (avoid the standard Paperclip task!).
67
+
68
+ rake rich:refresh_assets
data/Rakefile CHANGED
@@ -1,37 +1,9 @@
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
1
+ require "bundler/gem_tasks"
6
2
 
7
- require 'rdoc/task'
3
+ require 'rspec/core/rake_task'
8
4
 
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'ThecoreSettings'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
16
7
 
17
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
- load 'rails/tasks/engine.rake'
19
-
20
-
21
- load 'rails/tasks/statistics.rake'
22
-
23
-
24
-
25
- require 'bundler/gem_tasks'
26
-
27
- require 'rake/testtask'
28
-
29
- Rake::TestTask.new(:test) do |t|
30
- t.libs << 'lib'
31
- t.libs << 'test'
32
- t.pattern = 'test/**/*_test.rb'
33
- t.verbose = false
34
- end
35
-
36
-
37
- task default: :test
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,77 @@
1
+ if ThecoreSettings.active_record?
2
+ module ThecoreSettings
3
+ class Setting < ActiveRecord::Base
4
+ end
5
+ end
6
+ end
7
+
8
+ module ThecoreSettings
9
+ class Setting
10
+ if ThecoreSettings.mongoid?
11
+ include ThecoreSettings::Mongoid
12
+ end
13
+
14
+ if ThecoreSettings.active_record?
15
+ self.table_name = "thecore_settings"
16
+ end
17
+
18
+ scope :enabled, -> { where(enabled: true) }
19
+ scope :ns, ->(ns) { where(ns: ns) }
20
+
21
+ include ThecoreSettings::RequireHelpers
22
+ include ThecoreSettings::Processing
23
+ include ThecoreSettings::Uploads
24
+ include ThecoreSettings::Validation
25
+
26
+ def disabled?
27
+ !enabled
28
+ end
29
+
30
+ def enabled?
31
+ enabled
32
+ end
33
+
34
+ def name
35
+ label.blank? ? key : label
36
+ end
37
+
38
+ def type
39
+ kind
40
+ end
41
+
42
+ def to_path
43
+ if value.nil?
44
+ nil
45
+ else
46
+ 'public' + URI.parse(value).path
47
+ end
48
+ end
49
+
50
+ def as_yaml(options = {})
51
+ v = {type: type, enabled: enabled, label: label}
52
+ if upload_type?
53
+ v[:value] = to_path
54
+ else
55
+ v[:value] = raw
56
+ end
57
+ v.stringify_keys!
58
+ v
59
+ end
60
+
61
+ # t = {_all: 'Все'}
62
+ if ::Settings.table_exists?
63
+ ::ThecoreSettings::Setting.pluck(:ns).uniq.each do |c|
64
+ s = "ns_#{c.gsub('-', '_')}".to_sym
65
+ scope s, -> { where(ns: c) }
66
+ # t[s] = c
67
+ end
68
+ end
69
+ # I18n.backend.store_translations(:ru, {admin: {scopes: {'thecore_settings/setting': t}}})
70
+
71
+ if Object.const_defined?('RailsAdmin')
72
+ include ThecoreSettings::RailsAdminConfig
73
+ else
74
+ puts "[thecore_settings] Rails Admin not detected -- put this gem after rails_admin in gemfile"
75
+ end
76
+ end
77
+ end
data/app/views/.keep ADDED
File without changes
@@ -0,0 +1,41 @@
1
+ - if ['string', 'integer', 'float', 'phone', 'email', 'address', 'url', 'domain'].include?(@object.type)
2
+ = form.text_field :raw, :value => field.value
3
+ - if @object.type == 'boolean'
4
+ = form.check_box :raw, {:value => field.value}, 'true', 'false'
5
+ - if @object.type == 'color'
6
+ = form.text_field :raw, :value => field.value, 'data-color' => true, style: "background-color: ##{field.value}"
7
+ - elsif %w(text simple_format simple_format_raw strip_tags yaml json phones).include?( @object.type )
8
+ = form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
9
+ - elsif @object.type == 'code' || @object.type == 'sanitize_code'
10
+ :ruby
11
+ js_data = {
12
+ csspath: asset_path('ckeditor/plugins/codemirror/css/codemirror.min.css'),
13
+ jspath: asset_path('ckeditor/plugins/codemirror/js/codemirror.min.js'),
14
+ options: {
15
+ mode: 'htmlmixed',
16
+ theme: 'monokai',
17
+ lineNumbers: true
18
+ },
19
+ locations: {
20
+ mode: asset_path('ckeditor/plugins/codemirror/js/codemirror.mode.htmlmixed.min.js'),
21
+ theme: asset_path('ckeditor/plugins/codemirror/theme/monokai.css')
22
+ }
23
+ }
24
+
25
+ = form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: 'codemirror', options: js_data.to_json }).reverse_merge({ value: field.form_value })
26
+ - elsif @object.type == 'html' || @object.type == 'sanitized' || @object.type == 'sanitize'
27
+ - if form.respond_to?(:cktext_area)
28
+ = javascript_include_tag "ckeditor/init"
29
+ = form.cktext_area :raw, :value => field.value, :rows => 10, :cols => 80
30
+ - elsif Object.const_defined?('Rich')
31
+ = form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
32
+
33
+ = javascript_include_tag "rich/base.js"
34
+ :javascript
35
+ var instance = CKEDITOR.instances['#{form.dom_id(field)}'];
36
+ if(instance) { CKEDITOR.remove(instance); }
37
+ CKEDITOR.replace('#{form.dom_id(field)}', #{Rich.options().to_json.html_safe});
38
+ - else
39
+ .alert.alert-error
40
+ = t('admin.settings.no_ckeditor_detected')
41
+ = form.text_area :raw, :value => field.value, :rows => 10, :cols => 80
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/thecore_settings/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,29 @@
1
+ en:
2
+ admin:
3
+ settings:
4
+ label: 'Settings'
5
+ no_ckeditor_detected: CKEditor not found &mdash; showing as text input
6
+ phone_invalid: Incorrect phone
7
+ phones_invalid: "Incorrect phone: %{phones}"
8
+ email_invalid: Incorrect email
9
+ yaml_invalid: Incorrect YAML
10
+ json_invalid: Incorrect JSON
11
+ color_invalid: Incorrect color
12
+ mongoid: &mongoid
13
+ models:
14
+ thecore_settings/setting: Settings
15
+ attributes:
16
+ thecore_settings/setting:
17
+ c_at: Created
18
+ u_at: Updated
19
+ enabled: Enabled
20
+ ns: Group
21
+ name: Name
22
+ key: Key
23
+ raw: Value
24
+ type: Type
25
+ kind: Type
26
+ label: Label
27
+ activerecord:
28
+ <<: *mongoid
29
+
@@ -15,9 +15,9 @@ it:
15
15
  color_invalid: Colore non valido
16
16
  mongoid: &mongoid
17
17
  models:
18
- rails_admin_settings/setting: Configurazioni
18
+ thecore_settings/setting: Configurazioni
19
19
  attributes:
20
- rails_admin_settings/setting:
20
+ thecore_settings/setting:
21
21
  c_at: Creato
22
22
  u_at: Modificato
23
23
  enabled: Abilitato
@@ -0,0 +1,28 @@
1
+ pt-BR:
2
+ admin:
3
+ settings:
4
+ label: 'Configurações'
5
+ no_ckeditor_detected: CKEditor não encontrado &mdash; exibindo como texto simples
6
+ phone_invalid: Telefone incorreto
7
+ phones_invalid: "Telefone incorreto: %{phones}"
8
+ email_invalid: Email incorreto
9
+ yaml_invalid: YAML incorreto
10
+ json_invalid: JSON incorreto
11
+ color_invalid: Cor incorreta
12
+ mongoid: &mongoid
13
+ models:
14
+ thecore_settings/setting: Configurações
15
+ attributes:
16
+ thecore_settings/setting:
17
+ c_at: Criado
18
+ u_at: Atualizado
19
+ enabled: Ativado
20
+ ns: Grupo
21
+ name: Nome
22
+ key: Chave
23
+ raw: Valor
24
+ type: Tipo
25
+ kind: Tipo
26
+ label: Legenda
27
+ activerecord:
28
+ <<: *mongoid
@@ -0,0 +1,29 @@
1
+ ru:
2
+ admin:
3
+ settings:
4
+ label: 'Настройки'
5
+ no_ckeditor_detected: CKEditor не обнаружен &mdash; отображаю настройку как текстовое поле
6
+ phone_invalid: Неверный телефонный номер
7
+ phones_invalid: "Неверный телефонный номер: %{phones}"
8
+ email_invalid: Неверный email
9
+ yaml_invalid: Неверный синтаксис YAML
10
+ json_invalid: Неверный синтаксис JSON
11
+ color_invalid: Неверный цвет
12
+ mongoid: &mongoid
13
+ models:
14
+ thecore_settings/setting: Настройки
15
+ attributes:
16
+ thecore_settings/setting:
17
+ c_at: Создано
18
+ u_at: Обновлено
19
+ enabled: Включено
20
+ ns: Группа
21
+ name: Название
22
+ key: Ключ
23
+ raw: Значение
24
+ type: Тип
25
+ kind: Тип
26
+ label: Подпись
27
+ activerecord:
28
+ <<: *mongoid
29
+
@@ -1,6 +1,6 @@
1
- class CreateRailsAdminSettings < ActiveRecord::Migration[5.0]
1
+ class CreateThecoreSettings < ActiveRecord::Migration[5.0]
2
2
  def change
3
- create_table :rails_admin_settings do |t|
3
+ create_table :thecore_settings do |t|
4
4
  t.boolean :enabled, default: true
5
5
  t.string :kind, null: false, default: 'string'
6
6
  t.string :ns, default: 'main'
@@ -19,7 +19,7 @@ class CreateRailsAdminSettings < ActiveRecord::Migration[5.0]
19
19
  t.timestamps
20
20
  end
21
21
 
22
- add_index :rails_admin_settings, :key
23
- add_index :rails_admin_settings, [:ns, :key], unique: true
22
+ add_index :thecore_settings, :key
23
+ add_index :thecore_settings, [:ns, :key], unique: true
24
24
  end
25
25
  end
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid", "~> 6.0.0"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid", "~> 6.3.0"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ module ThecoreSettings
5
+ class MigrationGenerator < Rails::Generators::Base
6
+ include ActiveRecord::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ desc 'RocketCMS migration generator'
10
+ def install
11
+ migration_template "migration.rb", "db/migrate/create_thecore_settings.rb"
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,29 @@
1
+ class CreateThecoreSettings < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :thecore_settings do |t|
4
+ t.boolean :enabled, default: true
5
+ t.string :kind, null: false, default: 'string'
6
+ t.string :ns, default: 'main'
7
+ t.string :key, null: false
8
+ if Object.const_defined?('Geocoder')
9
+ t.float :latitude
10
+ t.float :longitude
11
+ end
12
+ t.text :raw
13
+ t.string :label
14
+ if defined?(Paperclip)
15
+ t.attachment :file
16
+ elsif defined?(CarrierWave)
17
+ t.string :file
18
+ elsif defined?(Shrine)
19
+ t.text :file_data
20
+
21
+ end
22
+ t.timestamps
23
+ end
24
+
25
+ add_index :thecore_settings, :key
26
+ add_index :thecore_settings, [:ns, :key], unique: true
27
+ end
28
+ end
29
+
@@ -0,0 +1,29 @@
1
+ class CreateThecoreSettings < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :thecore_settings do |t|
4
+ t.boolean :enabled, default: true
5
+ t.string :kind, null: false, default: 'string'
6
+ t.string :ns, default: 'main'
7
+ t.string :key, null: false
8
+ if Object.const_defined?('Geocoder')
9
+ t.float :latitude
10
+ t.float :longitude
11
+ end
12
+ t.text :raw
13
+ t.string :label
14
+ if defined?(Paperclip)
15
+ t.attachment :file
16
+ elsif defined?(CarrierWave)
17
+ t.string :file
18
+ elsif defined?(Shrine)
19
+ t.text :file_data
20
+
21
+ end
22
+ t.timestamps
23
+ end
24
+
25
+ add_index :thecore_settings, :key
26
+ add_index :thecore_settings, [:ns, :key], unique: true
27
+ end
28
+ end
29
+