rails_admin_model_settings 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ef45dafc23b3cd2fd0abb741124d0f3065e9ce5
4
+ data.tar.gz: 4f7ce8b4c10b78c06104e68bfc83d5c11b50d99f
5
+ SHA512:
6
+ metadata.gz: 730518c40a093da246046476856e44cffa5b271119b218a53c1b96cbd7f0913e67664e5e48099cc178b0d7eee94a9888a02e57a2a28251e42a50d6f936e5f289
7
+ data.tar.gz: da17959c49e73509d0585d0085523369f7239b31b877872eecf25e5146bbe83559e1506a377881fb5a108a5ac0724fe1ce35f6bc9f5607bfe3478c0ac527d3c7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails_admin_model_settings
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_admin_model_settings.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # RailsAdminModelSettings
2
+
3
+ Do your models and [AckRailsAdminSettings](https://github.com/red-rocks/rails_admin_settings) cooperation is more easy.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rails_admin_model_settings'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rails_admin_model_settings
20
+
21
+ ## Usage
22
+
23
+ Add this into your model:
24
+ include RailsAdminModelSettings::ModelSettingable
25
+
26
+ and use it for access to mongoid collection of model settings
27
+ YourModel.rails_admin_model_settings.where(key: 'some_key')
28
+
29
+ or as wrapper for Settings
30
+ YourModel.settings.some_setting(kind: :html, default: "<p></p>")
31
+
32
+ Also add 'model_settings' action into your rails_admin config and it will add list of settings for current model in rails_admin panel;
33
+
34
+ ### Advanced
35
+
36
+ Default ns for AckRailsAdminSettings is "rails_admin_model_settings_#{underscored_model_name}" so you can use it like this
37
+ ```ruby
38
+ module RailsAdminSettings
39
+ class Setting
40
+
41
+ after_save do |record|
42
+ case record.ns
43
+ when /^rails_admin_model_settings_/
44
+ _ns = record.ns.sub("rails_admin_model_settings_", "")
45
+ case _ns
46
+ when 'this_model'
47
+ do_something
48
+ when 'that_model'
49
+ do_something_else
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/rails_admin_model_settings.
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ # $(document).delegate ".comment_edit_form_link", 'click', (e)->
2
+ # e.preventDefault()
3
+ # link = $(e.currentTarget)
4
+ # target = $(link.attr('href'))
5
+ # $('.comment_edit_form').addClass('hidden').closest('.comment_block').find(".content_block").removeClass('hidden')
6
+ # target.removeClass('hidden').closest('.comment_block').find(".content_block").addClass('hidden')
7
+ #
8
+ # $(document).delegate ".comment_delete_form_link", 'click', (e)->
9
+ # e.preventDefault()
10
+ # link = $(e.currentTarget)
11
+ # target = $(link.attr('href'))
12
+ # target.find('form').prepend("<input type='hidden' name='_method' value='delete'></input>").submit()
@@ -0,0 +1,17 @@
1
+ #rails_admin_model_settings
2
+ .hidden
3
+ display: none
4
+
5
+ .error
6
+ color: red
7
+
8
+ .success
9
+ color: green
10
+
11
+ .setting_block
12
+ span
13
+ margin-right: 10px
14
+ .setting_value
15
+ margin-left: 10px
16
+ padding-bottom: 10px
17
+ border-bottom: 1px dotted grey
@@ -0,0 +1,20 @@
1
+ module RailsAdminModelSettings
2
+ module ModelSettingable
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def rails_admin_model_settings
7
+ RailsAdminSettings::Setting.ns(rails_admin_settings_ns)
8
+ end
9
+
10
+ def settings
11
+ Settings.ns(rails_admin_settings_ns)
12
+ end
13
+
14
+ def rails_admin_settings_ns
15
+ "rails_admin_model_settings_#{self.name.gsub("::", "").underscore}"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ #rails_admin_model_settings_wrapper
2
+ = stylesheet_link_tag 'rails_admin/rails_admin_model_settings'
3
+ = javascript_include_tag 'rails_admin/rails_admin_model_settings'
4
+
5
+ #rails_admin_model_settings
6
+ .controls
7
+ - @settings.each do |s|
8
+ .setting_block
9
+ span= s.label
10
+ span= s.key
11
+ span= s.type
12
+ span= link_to "открыть".freeze, show_path(model_name: 'rails_admin_settings~setting'.freeze, id: s.id)
13
+ span= link_to "редактировать".freeze, edit_path(model_name: 'rails_admin_settings~setting'.freeze, id: s.id)
14
+ .setting_value
15
+ - if s.file_kind?
16
+ = link_to CGI::escapeHTML(s.to_path), CGI::escapeHTML(s.file.url)
17
+ - elsif s.image_kind?
18
+ = link_to CGI::escapeHTML(s.file.url) do
19
+ = image_tag CGI::escapeHTML(s.file.url)
20
+ / - elsif s.enum_kind?
21
+ / - option = s.enum_collection.select { |e| e.last.to_s == s.value }.first
22
+ / = option ? option.first : s.value
23
+ - else
24
+ == s.value
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_admin_model_settings"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ ru:
2
+ admin:
3
+ actions:
4
+ model_settings:
5
+ menu: "Настройки"
6
+ breadcrumb: "Настройки"
7
+ title: "Настройки"
@@ -0,0 +1,33 @@
1
+ require "rails_admin_model_settings/version"
2
+ require "rails_admin_model_settings/engine"
3
+ require 'rails_admin_model_settings/configuration'
4
+
5
+ require 'rails_admin'
6
+ require 'rails_admin_settings'
7
+
8
+ require 'rails_admin_model_settings/action'
9
+
10
+
11
+ module RailsAdminModelSettings
12
+ class << self
13
+ def orm
14
+ :mongoid
15
+ # if defined?(::Mongoid)
16
+ # :mongoid
17
+ # else
18
+ # :active_record
19
+ # end
20
+ end
21
+
22
+ def mongoid?
23
+ orm == :mongoid
24
+ end
25
+
26
+ def active_record?
27
+ orm == :active_record
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ require 'rails_admin_model_settings/rails_admin_settings_patch'
@@ -0,0 +1,61 @@
1
+ require 'rails_admin/config/actions'
2
+ require 'rails_admin/config/model'
3
+
4
+ module RailsAdmin
5
+ module Config
6
+ module Actions
7
+ class ModelSettings < Base
8
+ RailsAdmin::Config::Actions.register(self)
9
+
10
+ # Is the action acting on the root level (Example: /admin/contact)
11
+ register_instance_option :root? do
12
+ false
13
+ end
14
+
15
+ register_instance_option :collection? do
16
+ true
17
+ end
18
+
19
+ # Is the action on an object scope (Example: /admin/team/1/edit)
20
+ register_instance_option :member? do
21
+ false
22
+ end
23
+
24
+ register_instance_option :rails_admin_settings_ns do
25
+ if @abstract_model and @abstract_model.model.respond_to?(:rails_admin_settings_ns)
26
+ @abstract_model.model.rails_admin_settings_ns
27
+ else
28
+ "rails_admin_model_settings"
29
+ end
30
+ end
31
+
32
+ register_instance_option :route_fragment do
33
+ 'model_settings'
34
+ end
35
+
36
+ register_instance_option :controller do
37
+ Proc.new do |klass|
38
+ @config = ::RailsAdminModelSettings::Configuration.new @abstract_model
39
+ if request.get?
40
+ if @abstract_model
41
+ @model = @abstract_model.model
42
+ @settings = @model.respond_to?(:rails_admin_model_settings) ? @model.rails_admin_model_settings.all.to_a : []
43
+ else
44
+ @settings = RailsAdminSettings::Setting.ns(@action.rails_admin_settings_ns)
45
+ end
46
+ render action: @action.template_name
47
+ end
48
+ end
49
+ end
50
+
51
+ register_instance_option :link_icon do
52
+ 'fa fa-gear'
53
+ end
54
+
55
+ register_instance_option :http_methods do
56
+ [:get]
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ module RailsAdminModelSettings
2
+ class Configuration
3
+ def initialize(abstract_model)
4
+ @abstract_model = abstract_model
5
+ end
6
+
7
+ def options
8
+ @options ||= {}
9
+ end
10
+
11
+ protected
12
+ def config
13
+ if @abstract_model
14
+ ::RailsAdmin::Config.model(@abstract_model.model).comments || {}
15
+ else
16
+ {}
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module RailsAdminModelSettings
2
+ class Engine < ::Rails::Engine
3
+
4
+ initializer "RailsAdminModelSettings precompile hook", group: :all do |app|
5
+ app.config.assets.precompile += %w(rails_admin/rails_admin_model_settings.js rails_admin/rails_admin_model_settings.css)
6
+ end
7
+
8
+ # initializer 'Include RailsAdminModelSettings::RailsAdminSettingsPatch' do |app|
9
+ # RailsAdminSettings::Setting.send :include, RailsAdminModelSettings::RailsAdminSettingsPatch
10
+ # end
11
+
12
+ # initializer 'Include RailsAdminModelSettings::Helper' do |app|
13
+ # ActionView::Base.send :include, RailsAdminModelSettings::Helper
14
+ # end
15
+
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # module RailsAdminModelSettings
2
+ # module RailsAdminSettingsPatch
3
+ # extend ActiveSupport::Concern
4
+ #
5
+ # included do
6
+ # if RailsAdminModelSettings.mongoid?
7
+ # field :data, type: Hash, default: {}
8
+ # end
9
+ # end
10
+ #
11
+ # def enum_collection
12
+ # data[:enum] ? (data[:enum][:collection] || []) : []
13
+ # end
14
+ #
15
+ # def enum_multiple
16
+ # data[:enum] and data[:enum][:multiple]
17
+ # end
18
+ #
19
+ # def enum_label
20
+ # data[:enum] ? (data[:enum][:label] || "") : ""
21
+ # end
22
+ #
23
+ # end
24
+ # end
25
+ #
26
+ #
27
+ # ###################################################################
28
+ #
29
+ # module RailsAdminSettings
30
+ # module_eval <<-EVAL
31
+ # def self.kinds
32
+ # #{RailsAdminSettings.kinds.to_a.to_s} + ['enum']
33
+ # end
34
+ # EVAL
35
+ # end
@@ -0,0 +1,3 @@
1
+ module RailsAdminModelSettings
2
+ VERSION = "0.2.1".freeze
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_admin_model_settings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_admin_model_settings"
8
+ spec.version = RailsAdminModelSettings::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["i43ack@gmail.com"]
11
+
12
+ spec.summary = %q{rails_admin_model_settings}
13
+ spec.description = %q{rails_admin_model_settings}
14
+ spec.homepage = "https://github.com/red-rocks/rails_admin_model_settings"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency "ack_rails_admin_settings", '~> 1.1'
34
+ spec.add_dependency "rails_admin", '~> 0.8.1'
35
+ spec.add_dependency "mongoid", [">= 5.0", "< 7.0"]
36
+ end
data/release.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push -u origin master
6
+ rake release
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_model_settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ack_rails_admin_settings
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails_admin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '7.0'
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '5.0'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '7.0'
89
+ description: rails_admin_model_settings
90
+ email:
91
+ - i43ack@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".ruby-gemset"
98
+ - ".ruby-version"
99
+ - ".travis.yml"
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - app/assets/javascripts/rails_admin/rails_admin_model_settings.coffee
105
+ - app/assets/stylesheets/rails_admin/rails_admin_model_settings.sass
106
+ - app/models/concerns/rails_admin_model_settings/model_settingable.rb
107
+ - app/views/rails_admin/main/model_settings.html.slim
108
+ - bin/console
109
+ - bin/setup
110
+ - config/locales/ru.rails_admin_model_settings.yml
111
+ - lib/rails_admin_model_settings.rb
112
+ - lib/rails_admin_model_settings/action.rb
113
+ - lib/rails_admin_model_settings/configuration.rb
114
+ - lib/rails_admin_model_settings/engine.rb
115
+ - lib/rails_admin_model_settings/rails_admin_settings_patch.rb
116
+ - lib/rails_admin_model_settings/version.rb
117
+ - rails_admin_model_settings.gemspec
118
+ - release.sh
119
+ homepage: https://github.com/red-rocks/rails_admin_model_settings
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.8
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: rails_admin_model_settings
143
+ test_files: []