ns_settings_ui 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rubocop.yml +14 -0
  4. data/.rubocop_u2i.yml +54 -0
  5. data/Appraisals +5 -0
  6. data/Gemfile +16 -0
  7. data/Guardfile +79 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +65 -0
  10. data/Rakefile +28 -0
  11. data/app/assets/images/ns_settings_ui/.keep +0 -0
  12. data/app/assets/javascripts/ns_settings_ui/application.js +13 -0
  13. data/app/assets/javascripts/ns_settings_ui/jquery.liveFilter.js +50 -0
  14. data/app/assets/stylesheets/ns_settings_ui/application.css +15 -0
  15. data/app/assets/stylesheets/ns_settings_ui/settings.css.scss +21 -0
  16. data/app/controllers/ns_settings_ui/application_controller.rb +4 -0
  17. data/app/controllers/ns_settings_ui/settings_controller.rb +29 -0
  18. data/app/helpers/ns_settings_ui/application_helper.rb +17 -0
  19. data/app/helpers/ns_settings_ui/settings_helper.rb +15 -0
  20. data/app/models/ns_settings_ui/setting.rb +26 -0
  21. data/app/views/ns_settings_ui/settings/_edit.html.erb +12 -0
  22. data/app/views/ns_settings_ui/settings/_setting_row.html.erb +6 -0
  23. data/app/views/ns_settings_ui/settings/_update.js.erb +3 -0
  24. data/app/views/ns_settings_ui/settings/index.html.erb +21 -0
  25. data/bin/rails +13 -0
  26. data/bin/rspec +15 -0
  27. data/config/routes.rb +7 -0
  28. data/db/migrate/20151210214903_create_ns_settings_ui_settings.rb +15 -0
  29. data/db/migrate/20151215081718_add_value_type_to_ns_settings_ui_settings.rb +5 -0
  30. data/gemfiles/rails_3.2.gemfile +7 -0
  31. data/gemfiles/rails_4.2.gemfile +7 -0
  32. data/lib/ns_settings_ui/engine.rb +9 -0
  33. data/lib/ns_settings_ui/version.rb +3 -0
  34. data/lib/ns_settings_ui.rb +6 -0
  35. data/lib/tasks/ns_settings_ui_tasks.rake +4 -0
  36. data/ns_settings_ui.gemspec +37 -0
  37. data/spec/controllers/ns_settings_ui/settings_controller_spec.rb +61 -0
  38. data/spec/dummy/README.rdoc +261 -0
  39. data/spec/dummy/Rakefile +7 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/spec/dummy/app/mailers/.gitkeep +0 -0
  45. data/spec/dummy/app/models/.gitkeep +0 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/spec/dummy/config/application.rb +55 -0
  48. data/spec/dummy/config/application.rb~ +64 -0
  49. data/spec/dummy/config/boot.rb +10 -0
  50. data/spec/dummy/config/database.yml +25 -0
  51. data/spec/dummy/config/environment.rb +5 -0
  52. data/spec/dummy/config/environments/development.rb +30 -0
  53. data/spec/dummy/config/environments/production.rb +67 -0
  54. data/spec/dummy/config/environments/test.rb +34 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/inflections.rb +15 -0
  57. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  58. data/spec/dummy/config/initializers/ns_settings_ui.rb +4 -0
  59. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  60. data/spec/dummy/config/initializers/session_store.rb +8 -0
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  62. data/spec/dummy/config/locales/en.yml +5 -0
  63. data/spec/dummy/config/routes.rb +3 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/db/development.sqlite3 +0 -0
  66. data/spec/dummy/db/schema.rb +25 -0
  67. data/spec/dummy/db/test.sqlite3 +0 -0
  68. data/spec/dummy/lib/assets/.gitkeep +0 -0
  69. data/spec/dummy/log/.gitkeep +0 -0
  70. data/spec/dummy/log/development.log +17213 -0
  71. data/spec/dummy/log/test.log +0 -0
  72. data/spec/dummy/public/404.html +26 -0
  73. data/spec/dummy/public/422.html +26 -0
  74. data/spec/dummy/public/500.html +25 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/script/rails +6 -0
  77. data/spec/helpers/ns_settings_ui/settings_helper_spec.rb +27 -0
  78. data/spec/models/ns_settings_ui/setting_spec.rb +114 -0
  79. data/spec/spec_helper.rb +40 -0
  80. data/spec/spec_helper.rb~ +37 -0
  81. data/spec/support/blueprints.rb +3 -0
  82. data/test/dummy/README.rdoc +28 -0
  83. data/test/dummy/Rakefile +6 -0
  84. data/test/dummy/app/assets/images/.keep +0 -0
  85. data/test/dummy/app/assets/javascripts/application.js +13 -0
  86. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  87. data/test/dummy/app/controllers/application_controller.rb +5 -0
  88. data/test/dummy/app/controllers/concerns/.keep +0 -0
  89. data/test/dummy/app/helpers/application_helper.rb +2 -0
  90. data/test/dummy/app/mailers/.keep +0 -0
  91. data/test/dummy/app/models/.keep +0 -0
  92. data/test/dummy/app/models/concerns/.keep +0 -0
  93. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  94. data/test/dummy/bin/bundle +3 -0
  95. data/test/dummy/bin/rails +4 -0
  96. data/test/dummy/bin/rake +4 -0
  97. data/test/dummy/config/application.rb +22 -0
  98. data/test/dummy/config/boot.rb +5 -0
  99. data/test/dummy/config/database.yml +25 -0
  100. data/test/dummy/config/environment.rb +5 -0
  101. data/test/dummy/config/environments/development.rb +37 -0
  102. data/test/dummy/config/environments/production.rb +78 -0
  103. data/test/dummy/config/environments/test.rb +39 -0
  104. data/test/dummy/config/initializers/assets.rb +8 -0
  105. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  106. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  107. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  108. data/test/dummy/config/initializers/inflections.rb +16 -0
  109. data/test/dummy/config/initializers/mime_types.rb +4 -0
  110. data/test/dummy/config/initializers/session_store.rb +3 -0
  111. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  112. data/test/dummy/config/locales/en.yml +23 -0
  113. data/test/dummy/config/routes.rb +3 -0
  114. data/test/dummy/config/secrets.yml +22 -0
  115. data/test/dummy/config.ru +4 -0
  116. data/test/dummy/lib/assets/.keep +0 -0
  117. data/test/dummy/log/.keep +0 -0
  118. data/test/dummy/public/404.html +67 -0
  119. data/test/dummy/public/422.html +67 -0
  120. data/test/dummy/public/500.html +66 -0
  121. data/test/dummy/public/favicon.ico +0 -0
  122. data/test/integration/navigation_test.rb +9 -0
  123. data/test/ns_settings_ui_test.rb +7 -0
  124. data/test/test_helper.rb +15 -0
  125. metadata +424 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 620d3d4a37036756b288e67585ce6e0438dd3755
4
+ data.tar.gz: d2ac6935cc37e0bf72b7427e5bef7859033b454a
5
+ SHA512:
6
+ metadata.gz: aa7c499bd852dfb1f66bdc3e079fc5f0499a8b282ee5a9f5a9fa4b3ee53c2bc50fa1c347efc4cb461bd63b6e3c4321bde508786e8d39facb98361d76a920c66b
7
+ data.tar.gz: a2f0cfb55baefacd78f29004d242a6da74f2f33c20be924c9872836c5dd733ed7d18c793b3f66eaeab3d160d3f87cae35716334467e3846b943feabacf4ddac9
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
9
+ Gemfile.lock
10
+
11
+ # Skip emacs backup files
12
+ *~
13
+ [#]*[#]
14
+ .[#]*
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ inherit_from: .rubocop_u2i.yml
2
+
3
+ AllCops:
4
+ Include:
5
+ - '**/Rakefile'
6
+ - '**/config.ru'
7
+ Exclude:
8
+ - config/**/*
9
+
10
+ Style/Lambda:
11
+ Enabled: false
12
+
13
+ Rails/ActionFilter:
14
+ Enabled: false
data/.rubocop_u2i.yml ADDED
@@ -0,0 +1,54 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - '**/config.ru'
5
+ Exclude:
6
+ - bin/**/*
7
+ - db/**/*
8
+ - config/**/*
9
+ - script/**/*
10
+ - db/schema.rb
11
+ - bundle/**/*
12
+
13
+ Style/MultilineOperationIndentation:
14
+ EnforcedStyle: indented
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/WhileUntilModifier:
20
+ MaxLineLength: 120
21
+ Exclude:
22
+ - spec/**/*
23
+
24
+ Style/SpaceInsideHashLiteralBraces:
25
+ EnforcedStyle: no_space
26
+ EnforcedStyleForEmptyBraces: no_space
27
+
28
+ Style/MultilineBlockChain:
29
+ Enabled: true
30
+
31
+ Style/DotPosition:
32
+ EnforcedStyle: trailing
33
+ Enabled: true
34
+
35
+ Style/SingleLineMethods:
36
+ AllowIfMethodIsEmpty: false
37
+
38
+ Style/NumericLiterals:
39
+ Enabled: false
40
+
41
+ #Style/TrailingComma:
42
+ # # If EnforcedStyleForMultiline is comma, the cop allows a comma after the
43
+ # # last item of a list, but only for lists where each item is on its own line.
44
+ # EnforcedStyleForMultiline: comma
45
+
46
+ Metrics/LineLength:
47
+ Max: 120
48
+ Enabled: true
49
+ Exclude:
50
+ - spec/**/*
51
+
52
+ Metrics/MethodLength:
53
+ CountComments: false # count full line comments?
54
+ Max: 30
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ [4.2, 3.2].each do |version|
2
+ appraise "rails_#{version}" do
3
+ gem 'rails', "~> #{version}.0"
4
+ end
5
+ end
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in ns_settings_ui.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
15
+
16
+ gem 'rails', '~> 3.2' # assuming Rails 3.2 for jenkins jobs and top level rake tasks
data/Guardfile ADDED
@@ -0,0 +1,79 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+ # This group allows to skip running RuboCop if RSpec.
27
+
28
+ group :red_green_refactor, halt_on_fail: true do
29
+ guard :rspec, cmd: "bin/rspec" do
30
+ require "guard/rspec/dsl"
31
+ dsl = Guard::RSpec::Dsl.new(self)
32
+
33
+ # Feel free to open issues for suggestions and improvements
34
+
35
+ # RSpec files
36
+ rspec = dsl.rspec
37
+ watch(rspec.spec_helper) { rspec.spec_dir }
38
+ watch(rspec.spec_support) { rspec.spec_dir }
39
+ watch(rspec.spec_files)
40
+
41
+ # Ruby files
42
+ ruby = dsl.ruby
43
+ dsl.watch_spec_files_for(ruby.lib_files)
44
+
45
+ # Rails files
46
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
47
+ dsl.watch_spec_files_for(rails.app_files)
48
+ dsl.watch_spec_files_for(rails.views)
49
+
50
+ watch(rails.controllers) do |m|
51
+ [
52
+ rspec.spec.("routing/#{m[1]}_routing"),
53
+ rspec.spec.("controllers/#{m[1]}_controller"),
54
+ rspec.spec.("acceptance/#{m[1]}")
55
+ ]
56
+ end
57
+
58
+ # Rails config changes
59
+ watch(rails.spec_helper) { rspec.spec_dir }
60
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62
+
63
+ # Capybara features specs
64
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
65
+ watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
66
+
67
+ # Turnip features and steps
68
+ watch(%r{^spec/acceptance/(.+)\.feature$})
69
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
71
+ end
72
+ end
73
+
74
+ guard :rubocop, all_on_start: false, cli: %w(--format fuubar --rails) do
75
+ watch(%r{.+\.rb$})
76
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
77
+ end
78
+ end
79
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ [![Build Status](http://jenkins.nielsensocial.u2i.eu/buildStatus/icon?job=(master) ns_settings_ui)](http://jenkins.nielsensocial.u2i.eu/job/(master) ns_settings_ui)
2
+
3
+ # NsSettingsUi
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ns_settings_ui'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ns_settings_ui
18
+
19
+ Install migrations:
20
+
21
+ $ rake ns_settings_ui:install:migrations
22
+
23
+ And run db:migrate in your application
24
+
25
+ $ rake db:migate
26
+
27
+ ## Configuration
28
+
29
+ Add ns_setting_ui initializer to config/initializers/ns_settings_ui.rb
30
+
31
+ ```
32
+ if defined?(NsSettingsUi)
33
+ NsSettingsUi.layout = nil
34
+ NsSettingsUi.parent_controller = ActionController::Base
35
+ end
36
+ ```
37
+
38
+ You can modify NsSettingsUi variables in order to:
39
+ * `NsSettingsUi.layout` - set a layout from your application
40
+ * `NsSettingsUi.parent_controller` - choose a controller that NsSettingUi controllers will inherit from
41
+
42
+ ## Testing
43
+
44
+ This engine is used by NTTR and socialguide, thereby needs to be compatible with both Rails 3.2 and 4.2.
45
+ It uses [Appraisal](https://github.com/thoughtbot/appraisal) gem with a set up similar to [permitters gem](https://github.com/permitters/permitters) to give you an easy way of testing the code under multiple Rails versions.
46
+
47
+ To bundle install for each appraisal defined:
48
+
49
+ `appraisal install`
50
+
51
+ And then to run specs for all the appraisals:
52
+
53
+ `appraisal bundle exec rspec spec`
54
+
55
+ Or a specific one:
56
+
57
+ `appraisal rails_4.2 bundle exec rspec spec`
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( http://github.com/<my-github-username>/ns_settings_ui/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,28 @@
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
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'NsSettingsUi'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rspec/core'
23
+ require 'rspec/core/rake_task'
24
+
25
+ desc 'Run all specs in spec directory (excluding plugin specs)'
26
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
27
+
28
+ task default: :spec
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,50 @@
1
+ /*
2
+ * jQuery.liveFilter
3
+ *
4
+ * Copyright (c) 2009 Mike Merritt
5
+ *
6
+ * Forked by Lim Chee Aun (cheeaun.com)
7
+ *
8
+ */
9
+
10
+ (function($){
11
+ $.fn.liveFilter = function(inputEl, filterEl, options){
12
+ var defaults = {
13
+ filterChildSelector: null,
14
+ filter: function(el, val){
15
+ return $(el).text().toUpperCase().match(val.toUpperCase()) !== null;
16
+ },
17
+ before: function(){},
18
+ after: function(){}
19
+ };
20
+ var options = $.extend(defaults, options);
21
+
22
+ var el = $(this).find(filterEl);
23
+ if (options.filterChildSelector) el = el.find(options.filterChildSelector);
24
+
25
+ var filter = options.filter;
26
+ $(inputEl).keyup(function(){
27
+ var val = $(this).val();
28
+ var contains = el.filter(function(){
29
+ return filter(this, val);
30
+ });
31
+ var containsNot = el.not(contains);
32
+ if (options.filterChildSelector){
33
+ contains = contains.parents(filterEl);
34
+ containsNot = containsNot.parents(filterEl).hide();
35
+ }
36
+
37
+ options.before.call(this, contains, containsNot);
38
+
39
+ contains.show();
40
+ containsNot.hide();
41
+
42
+ if (val === '') {
43
+ contains.show();
44
+ containsNot.show();
45
+ }
46
+
47
+ options.after.call(this, contains, containsNot);
48
+ });
49
+ }
50
+ })(jQuery);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,21 @@
1
+ // Place all the styles related to the Settings controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
4
+
5
+ #ns_settings_ui {
6
+ ul {
7
+ list-style-type: none;
8
+ }
9
+ form {
10
+ display: inline;
11
+ }
12
+ input[type=text] {
13
+ width: 130px;
14
+ display: inline;
15
+ }
16
+ table {
17
+ td {
18
+ padding: 2px;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,4 @@
1
+ module NsSettingsUi
2
+ class ApplicationController < NsSettingsUi.parent_controller
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ module NsSettingsUi
2
+ class SettingsController < NsSettingsUi::ApplicationController
3
+ layout NsSettingsUi.layout
4
+ before_filter :setting_from_id_param, only: [:update, :reset]
5
+
6
+ def index
7
+ @settings = Setting.order('`key`').all
8
+ end
9
+
10
+ def update
11
+ @setting.value = params[:setting][:value]
12
+ @setting.default_value = params[:setting][:default_value]
13
+ @setting.save!
14
+ render partial: 'update'
15
+ end
16
+
17
+ def reset
18
+ @setting.value = @setting.default_value
19
+ @setting.save!
20
+ render partial: 'update'
21
+ end
22
+
23
+ private
24
+
25
+ def setting_from_id_param
26
+ @setting = Setting.find(params[:id])
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module NsSettingsUi
2
+ module ApplicationHelper
3
+ def url_for(options)
4
+ super(options)
5
+ rescue ActionController::RoutingError
6
+ main_app.url_for(options)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ if main_app.respond_to?(method)
11
+ main_app.send(method, *args)
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module NsSettingsUi
2
+ module SettingsHelper
3
+ def setting_value_class(setting)
4
+ return 'alert-danger' if setting.value.nil? || setting.value.empty?
5
+ return 'alert-warning' if setting.value != setting.default_value
6
+ ''
7
+ end
8
+
9
+ private
10
+
11
+ def recursive_hash
12
+ Hash.new { |hash, key| hash[key] = recursive_hash }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module NsSettingsUi
2
+ class Setting < ActiveRecord::Base
3
+ TYPES = {
4
+ string: 1,
5
+ integer: 2
6
+ }.freeze
7
+
8
+ def self.get(*keys)
9
+ where(key: keys.join('.')).first_or_create
10
+ end
11
+
12
+ def keys
13
+ key.split('.').map(&:to_sym)
14
+ end
15
+
16
+ def formatted_value
17
+ return nil if value.nil?
18
+ case value_type
19
+ when TYPES[:string] then value.to_s
20
+ when TYPES[:integer] then value.to_i
21
+ else
22
+ value
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ <div id="setting_<%= setting.id -%>">
2
+ <%= form_for(setting, url: ns_settings_ui.setting_path(setting), method: :put, remote: true, html: {class: 'form-inline'}) do |f| %>
3
+ <%= f.label(:value) %>
4
+ <%= f.text_field(:value, size: 10, class: "form-control #{setting_value_class(setting)}" ) %>
5
+ <%= f.label(:default_value) %>
6
+ <%= f.text_field(:default_value, size: 10, class: 'form-control') %>
7
+ <%= f.submit('Update', class: 'btn btn-default') %>
8
+ <% end %>
9
+ <%= form_for(setting, url: ns_settings_ui.reset_setting_path(setting), method: :put, remote: true) do |f| %>
10
+ <%= f.submit('Reset to default', class: 'btn btn-default') %>
11
+ <% end %>
12
+ </div>
@@ -0,0 +1,6 @@
1
+ <tr>
2
+ <td class="setting_key"><h5><%= setting.key -%></h5></td>
3
+ <td>
4
+ <%= render partial: 'edit', locals: {setting: setting} -%>
5
+ </td>
6
+ </tr>
@@ -0,0 +1,3 @@
1
+ $("#ns_settings_ui #setting_<%= @setting.id -%>").replaceWith("<%= escape_javascript(render partial: 'edit', locals: {setting: @setting}) %>");
2
+ $("#ns_settings_ui #setting_<%= @setting.id -%>").append('<span class="notice text-success">Updated</span>');
3
+ $("#ns_settings_ui #setting_<%= @setting.id -%> .notice").delay(1000).fadeOut('slow');
@@ -0,0 +1,21 @@
1
+ <%= content_for :head do %>
2
+ <%= stylesheet_link_tag 'ns_settings_ui/settings' -%>
3
+ <%= javascript_include_tag 'ns_settings_ui/application' -%>
4
+ <% end %>
5
+ <div id="ns_settings_ui">
6
+ <div class="panel panel-default">
7
+ <div class="panel-heading">
8
+ <span>Filter: </span>
9
+ <input class="form-control" id="filter-input" type="text" value=""> (regular expressions are available)
10
+ </div>
11
+ <div class="panel-body">
12
+ <table class="table table-striped table-bordered">
13
+ <%= render partial: 'setting_row', collection: @settings, as: 'setting' -%>
14
+ </table>
15
+ </div>
16
+ </div>
17
+ </div>
18
+
19
+ <%= javascript_tag do -%>
20
+ $('#ns_settings_ui').liveFilter('#ns_settings_ui #filter-input', 'tr', {filterChildSelector: '.setting_key'});
21
+ <% end %>
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails"
3
+ # with Rails 4 gems installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/ns_settings_ui/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'
data/bin/rspec ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
11
+
12
+ require 'rubygems'
13
+ require 'bundler/setup'
14
+
15
+ load Gem.bin_path('rspec-core', 'rspec')
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ NsSettingsUi::Engine.routes.draw do
2
+ resources :settings, only: [:index, :update] do
3
+ member do
4
+ put 'reset'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ class CreateNsSettingsUiSettings < ActiveRecord::Migration
2
+ def up
3
+ create_table :ns_settings_ui_settings do |t|
4
+ t.string :key, null: false
5
+ t.string :value
6
+ t.string :default_value
7
+ t.timestamps
8
+ end
9
+ add_index :ns_settings_ui_settings, :key
10
+ end
11
+
12
+ def down
13
+ drop_table :ns_settings_ui_settings
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class AddValueTypeToNsSettingsUiSettings < ActiveRecord::Migration
2
+ def change
3
+ add_column :ns_settings_ui_settings, :value_type, :integer, default: 0
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ module NsSettingsUi
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace NsSettingsUi
4
+
5
+ initializer 'ns_settings_ui.assets.precompile' do |app|
6
+ app.config.assets.precompile += %w(ns_settings_ui/settings.css)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module NsSettingsUi
2
+ VERSION = '1.0.0'.freeze
3
+ end