kadmin 0.6.19 → 0.6.21

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa35b62934941a72c116c6e988af5eb708fa82db
4
- data.tar.gz: 49d900bc1df849af9f03f41c06c75851c078430f
3
+ metadata.gz: 98456b6564d2ed7360237ee63add4224c3657332
4
+ data.tar.gz: b5ab9f55d662438bd78d20a773fd1d6e9f0d69f5
5
5
  SHA512:
6
- metadata.gz: 5d56bca021b9ebf5f7f2ea0014cc6c8b9dedad91e0db2e523e77d010d0e5f65aca697408513862abec25f0c7c3a125587430024c3e8ecaea1924cefaf40d634c
7
- data.tar.gz: 6020f7064197a8e1dccf9d35c86f62d87fa47095012267f79326e5bdd1049c2e5e2902d9273394a01c0213762ee910129277d1561d30134a5c5c07903720d595
6
+ metadata.gz: 492c06c2e1de2da68377bd30d0da378dadd9b2d8306525d2899ac879d8a5b13c412c7dab2aab020318fcc8edaa5ef7fe14799a264733aee19f6cf643044f81c7
7
+ data.tar.gz: c51a21974ec0d7cd74fb3bba05c11e7b1c8100cd3783b084032a5385a7615bfb884261a759c408403e1728a4a2c7cef40a4c9980d8052e67db1bedb0e409f8b2
data/Rakefile CHANGED
@@ -33,118 +33,3 @@ begin
33
33
  rescue LoadError
34
34
  puts 'yard not present, disabling Rake task'
35
35
  end
36
-
37
- require 'kadmin/version'
38
-
39
- namespace :cim do
40
- desc 'Tags, updates README, and CHANGELOG and pushes to Github. Requires ruby-git'
41
- task :release do
42
- tasks = ['cim:assert_clean_repo', 'cim:git_fetch', 'cim:set_new_version', 'cim:update_readme', 'cim:update_changelog', 'cim:commit_changes', 'cim:tag']
43
- begin
44
- tasks.each { |task| Rake::Task[task].invoke }
45
- `git push && git push origin '#{Kadmin::VERSION}'`
46
- rescue => error
47
- puts ">>> ERROR: #{error}; might want to reset your repository"
48
- end
49
- end
50
-
51
- desc 'Fails if the current repository is not clean'
52
- task :assert_clean_repo do
53
- status = `git status -s`.chomp.strip
54
- if status.strip.empty?
55
- status = `git log origin/master..HEAD`.chomp.strip # check if we have unpushed commits
56
- if status.strip.empty?
57
- puts '>>> Repository is clean!'
58
- else
59
- puts '>>> Please push your committed changes before releasing!'
60
- exit(-1)
61
- end
62
- else
63
- puts '>>> Please stash or commit your changes before releasing!'
64
- exit(-1)
65
- end
66
- end
67
-
68
- desc 'Fetches latest tags/commits'
69
- task :git_fetch do
70
- puts '>>> Fetching latest git refs'
71
- `git fetch --tags`
72
- end
73
-
74
- desc 'Requests the new version number'
75
- task :set_new_version do
76
- STDOUT.print(">>> New version number (current: #{Kadmin::VERSION}; leave blank if already updated): ")
77
- input = STDIN.gets.strip.tr("'", "\'")
78
-
79
- current = if input.empty?
80
- Kadmin::VERSION
81
- else
82
- unless input =~ /[0-9]+\.[0-9]+\.[0-9]+/
83
- puts '>>> Please use semantic versioning!'
84
- exit(-1)
85
- end
86
-
87
- input
88
- end
89
-
90
- latest = `git describe --abbrev=0`.chomp.strip
91
- unless Gem::Version.new(current) > Gem::Version.new(latest)
92
- puts ">>> Latest tagged version is #{latest}; make sure gem version (#{current}) is greater!"
93
- exit(-1)
94
- end
95
-
96
- if !input.empty?
97
- `sed -i -u "s@VERSION = '#{Kadmin::VERSION}'@VERSION = '#{input}'@" #{File.expand_path('../lib/kadmin/version.rb', __FILE__)}`
98
- $VERBOSE = nil
99
- Kadmin.const_set('VERSION', input)
100
- $VERBOSE = false
101
-
102
- `bundle check` # force updating version
103
- end
104
- end
105
-
106
- desc 'Updates README with latest version'
107
- task :update_readme do
108
- puts '>>> Updating README.md'
109
- replace = %([![GitHub release](https://img.shields.io/badge/release-#{Kadmin::VERSION}-blue.png)](https://github.com/barcoo/kadmin/releases/tag/#{Kadmin::VERSION}))
110
-
111
- `sed -i -u 's@^\\[\\!\\[GitHub release\\].*$@#{replace}@' README.md`
112
- end
113
-
114
- desc 'Updates CHANGELOG with commit log from last tag to this one'
115
- task :update_changelog do
116
- puts '>>> Updating CHANGELOG.md'
117
- latest = `git describe --abbrev=0`.chomp.strip
118
- range = $CHILD_STATUS.success? && !latest.empty? ? "'#{latest}'..HEAD" : ''
119
-
120
- log = `git log --pretty=format:'- [%h](https://github.com/barcoo/kadmin/commit/%h) *%ad* __%s__ (%an)' --date=short #{range}`.chomp
121
-
122
- changelog = File.open('.CHANGELOG.md', 'w')
123
- changelog.write("# Changelog\n\n###{Kadmin::VERSION}\n\n#{log}\n\n")
124
- File.open('CHANGELOG.md', 'r') do |file|
125
- file.readline # skip first two lines
126
- file.readline
127
-
128
- while buffer = file.read(2048) # rubocop: disable Lint/AssignmentInCondition
129
- changelog.write(buffer)
130
- end
131
- end
132
-
133
- changelog.close
134
- `mv '.CHANGELOG.md' 'CHANGELOG.md'`
135
- end
136
-
137
- desc 'Commits the README/CHANGELOG changes'
138
- task :commit_changes do
139
- puts '>>> Committing updates to README/CHANGELOG'
140
- `git commit -am'Updated README.md and CHANGELOG.md on new release'`
141
- end
142
-
143
- desc 'Creates and pushes the tag to git'
144
- task :tag do
145
- puts '>>> Tagging'
146
- STDOUT.print('>>> Please enter a tag message: ')
147
- input = STDIN.gets.strip.tr("'", "\'")
148
- `git tag -a '#{Kadmin::VERSION}' -m '#{input}'`
149
- end
150
- end
@@ -1,19 +1,20 @@
1
1
  //= require select2
2
- $(document).ready(function() {
3
- $.fn.select2.defaults.set("theme", "bootstrap");
4
- $.fn.select2.defaults.set("ajax", {
2
+ /* global jQuery */
3
+ jQuery(document).ready(function() {
4
+ jQuery.fn.select2.defaults.set("theme", "bootstrap");
5
+ jQuery.fn.select2.defaults.set("ajax", {
5
6
  cache: true,
6
7
  dataType: "json",
7
8
  delay: 300,
8
9
  data: transformRequest,
9
10
  processResults: transformResponse
10
11
  });
11
- $.fn.select2.defaults.set("allowClear", true);
12
+ jQuery.fn.select2.defaults.set("allowClear", true);
12
13
 
13
14
  function transformRequest(params) {
14
15
  var page = params.page || 0;
15
- var page_size = this.data('kadmin--page-size') || 10;
16
- var filter_param = this.data('kadmin--filter-param') || null;
16
+ var page_size = this.data("kadmin--page-size") || 10;
17
+ var filter_param = this.data("kadmin--filter-param") || null;
17
18
  var options = {
18
19
  page_offset: page * page_size,
19
20
  page_size: page_size
@@ -23,37 +24,75 @@ $(document).ready(function() {
23
24
  options[filter_param] = params.term;
24
25
  }
25
26
 
26
- return options;
27
+ return transform(options, this.data("kadmin--transform-request"));
27
28
  }
28
29
 
29
30
  function transformResponse(data, params) {
30
31
  var items = data.data || data.items;
31
32
  var options = this.options.options.kadmin || {}; // weird but it is what it is
32
- var displayProperty = options.displayProperty || 'text';
33
- var valueProperty = options.valueProperty || 'id';
34
-
33
+ var displayProperty = options.displayProperty || "text";
34
+ var valueProperty = options.valueProperty || "id";
35
35
  var results = [];
36
- $(items).each(function(index, item) {
36
+ var response = {};
37
+
38
+ jQuery(items).each(function(index, item) {
37
39
  results.push({ text: item[displayProperty], id: item[valueProperty] });
38
40
  });
39
41
 
40
- return {
42
+ response = {
41
43
  results: results,
42
44
  pagination: { more: data.more }
43
45
  };
46
+
47
+ return transform(response, this.$element.data("kadmin--transform-response"));
44
48
  }
45
49
 
46
50
  function optionsForSelect2(element) {
47
51
  return {
48
- minimumInputLength: $(element).data('kadmin--minimum-input-length') || 2,
52
+ minimumInputLength: jQuery(element).data("kadmin--minimum-input-length") || 2,
53
+ };
54
+ }
55
+
56
+ // Data callbacks
57
+ var gFunctions = {};
58
+ function transform(initial, name) {
59
+ var transformed = initial;
60
+
61
+ if (name) {
62
+ var callback = lookup(name);
63
+ if (jQuery.isFunction(callback)) {
64
+ transformed = callback(initial);
65
+ }
49
66
  }
67
+
68
+ return transformed;
69
+ }
70
+
71
+ function lookup(path) {
72
+ if (gFunctions[path]) return gFunctions[path];
73
+
74
+ var namespaces = path.split(".");
75
+ var functionName = namespaces.pop();
76
+ var context = window;
77
+ var func = null;
78
+
79
+ for (var i = 0; context && i < namespaces.length; i++) {
80
+ context = context[namespaces[i]];
81
+ }
82
+
83
+ if (jQuery.isFunction(context[functionName])) {
84
+ func = context[functionName];
85
+ gFunctions[path] = func;
86
+ }
87
+
88
+ return func;
50
89
  }
51
90
 
52
91
  // Need to delay a bit otherwise we have issues
53
92
  // TODO: Figure out why this happens?
54
93
  setTimeout(function() {
55
- $('select.kadmin-select2').each(function() {
56
- $(this).select2(optionsForSelect2(this));
94
+ jQuery("select.kadmin-select2").each(function() {
95
+ jQuery(this).select2(optionsForSelect2(this));
57
96
  });
58
97
  }, 300);
59
98
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  class Finder
4
5
  include Kadmin::Presentable
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  class Finder
4
5
  class Presenter < Kadmin::Presenter
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  # Parsing is done by using attribute setters. If you have an attribute called
4
5
  # name, then add a reader/writer for it, name and name=, and perform the
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  # TODO: Figure out how to have access to a properly scoped routing proxy
4
5
  module Navbar
@@ -45,7 +46,7 @@ module Kadmin
45
46
  css_classes = self.css_classes.dup << 'active' if @view.controller.request.path == path
46
47
 
47
48
  contents = @view.link_to(self.text.to_s.html_safe, path)
48
- contents << captured unless captured.blank?
49
+ contents << captured if captured.present?
49
50
 
50
51
  return %(<li class="#{css_classes.join(' ')}">#{contents}</li>).html_safe
51
52
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  # TODO: Clearly some functionality between Navbar::Link and Navbar::Section is shared and
4
5
  # could be refactored into Navbar::Item one day.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  # Simple Pager structure, used to paginate collections
4
5
  class Pager
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  class Pager
4
5
  # Generates HTML code to present the given pager
@@ -74,14 +75,14 @@ module Kadmin
74
75
  private :page_links
75
76
 
76
77
  def list_text(text, css_classes = nil)
77
- classes = %w(btn btn-default) + Array.wrap(css_classes)
78
+ classes = %w[btn btn-default] + Array.wrap(css_classes)
78
79
  return "<div class='#{classes.join(' ')}'>#{text}</div>".html_safe
79
80
  end
80
81
  private :list_text
81
82
 
82
83
  def list_link(text, options = {})
83
84
  link_options = @view.controller.request.query_parameters.merge(options)
84
- return @view.link_to(text.to_s.html_safe, link_options, class: %w(btn btn-default).join(' '))
85
+ return @view.link_to(text.to_s.html_safe, link_options, class: %w[btn btn-default].join(' '))
85
86
  end
86
87
  private :list_link
87
88
 
@@ -5,7 +5,10 @@ module Kadmin
5
5
  include Kadmin::Presentable
6
6
 
7
7
  CSS_CLASS_MARKER = 'kadmin-select2'
8
- DATA_ATTRIBUTES = %i[placeholder data_url filter_param display_property value_property page_size minimum_input_length].freeze
8
+ DATA_ATTRIBUTES = %i[
9
+ placeholder data_url filter_param display_property value_property
10
+ page_size minimum_input_length transform_request transform_response
11
+ ].freeze
9
12
 
10
13
  # @return [String] will be used as a placeholder if given
11
14
  attr_reader :placeholder
@@ -30,6 +33,12 @@ module Kadmin
30
33
  # @return [Integer] the minimum input length before trying to fetch remote data
31
34
  attr_reader :minimum_input_length
32
35
 
36
+ # @return [String] name of callback to a globally-accessible function that can transform the request
37
+ attr_reader :transform_request
38
+
39
+ # @return [String] name of the callback to a globally-accessible function that can transform the response
40
+ attr_reader :transform_response
41
+
33
42
  def initialize(options = {})
34
43
  @placeholder = options[:placeholder].to_s.freeze
35
44
  extract_ajax_options!(options).freeze if options.present?
@@ -42,6 +51,8 @@ module Kadmin
42
51
  @value_property = options.fetch(:value_property, 'id')
43
52
  @page_size = options.fetch(:page_size, 10)
44
53
  @minimum_input_length = options.fetch(:minimum_input_length, 2)
54
+ @transform_request = options[:transform_request]
55
+ @transform_response = options[:transform_response]
45
56
 
46
57
  raise ArgumentError, 'missing data URL for remote fetching' if @data_url.blank?
47
58
  end
@@ -55,8 +66,10 @@ module Kadmin
55
66
  'kadmin--display-property' => display_property,
56
67
  'kadmin--value-property' => value_property,
57
68
  'kadmin--page-size' => page_size,
58
- 'kadmin--minimum-input-length' => minimum_input_length
59
- }
69
+ 'kadmin--minimum-input-length' => minimum_input_length,
70
+ 'kadmin--transform-request' => transform_request,
71
+ 'kadmin--transform-response' => transform_response
72
+ }.compact
60
73
  end
61
74
 
62
75
  class << self
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  class ApplicationController < ActionController::Base
4
5
  layout 'kadmin/application'
@@ -19,7 +20,7 @@ module Kadmin
19
20
 
20
21
  # @!group Error Handling
21
22
 
22
- if Kadmin.config.handle_errors && !defined?(BetterErrors)
23
+ if Kadmin.config.handle_errors
23
24
  rescue_from StandardError, with: :handle_unexpected_error
24
25
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
25
26
  rescue_from ActionController::ParameterMissing, with: :params_missing
@@ -67,7 +67,7 @@ module Kadmin
67
67
  def valid_redirect_url?(url)
68
68
  valid = false
69
69
 
70
- unless url.blank?
70
+ if url.present?
71
71
  paths = [auth_login_path, auth_logout_path]
72
72
  valid = paths.none? { |invalid| url == invalid }
73
73
  end
@@ -92,7 +92,7 @@ module Kadmin
92
92
  end
93
93
  end
94
94
 
95
- provider_link = "#{provider_link}?origin=#{CGI.escape(origin)}" unless origin.blank?
95
+ provider_link = "#{provider_link}?origin=#{CGI.escape(origin)}" if origin.present?
96
96
  return provider_link
97
97
  end
98
98
  helper_method :omniauth_provider_link
@@ -3,8 +3,7 @@ module Kadmin
3
3
  # @!group Endpoints
4
4
 
5
5
  # GET /
6
- def index
7
- end
6
+ def index; end
8
7
 
9
8
  # @!endgroup
10
9
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  # Provide helpers for displaying alerts, as well as matching those alerts to
4
5
  # different flash keys.
@@ -13,7 +14,7 @@ module Kadmin
13
14
  dismissible = options.fetch(:dismissible, true)
14
15
  text_content = options.fetch(:content, '')
15
16
 
16
- css_classes = %W(alert alert-#{type})
17
+ css_classes = %W[alert alert-#{type}]
17
18
  css_classes << 'alert-dismissible' if options.fetch(:dismissible, true)
18
19
  block_content = capture(&block) if block_given?
19
20
 
@@ -27,17 +28,17 @@ module Kadmin
27
28
  content.concat(button)
28
29
  end
29
30
 
30
- content.concat(block_content.html_safe) unless block_content.blank?
31
+ content.concat(block_content.html_safe) if block_content.present?
31
32
  content
32
33
  end
33
34
  end
34
35
 
35
36
  Type = Struct.new(:flash_keys, :css_class, :glyphicon)
36
37
  TYPES = [
37
- Type.new(['danger', 'alert'], 'danger', 'exclamation-sign'),
38
+ Type.new(%w[danger alert], 'danger', 'exclamation-sign'),
38
39
  Type.new(['success'], 'success', 'ok-sign'),
39
- Type.new(['notice', 'info'], 'info', 'info-sign'),
40
- Type.new(['warn', 'warning'], 'warning', 'question-sign')
40
+ Type.new(%w[notice info], 'info', 'info-sign'),
41
+ Type.new(%w[warn warning], 'warning', 'question-sign')
41
42
  ].freeze
42
43
  def render_flash_alerts
43
44
  alerts = AlertHelper::TYPES.map do |type|
@@ -48,7 +49,7 @@ module Kadmin
48
49
  return safe_join(alerts)
49
50
  end
50
51
 
51
- def render_flash_alert(type, &block)
52
+ def render_flash_alert(type)
52
53
  messages = type.flash_keys.map { |key| Array.wrap(flash[key]).compact }.flatten
53
54
  return '' if messages.blank?
54
55
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  module ApplicationHelper
4
5
  REDMINE_URL = 'https://redmine.offerista.com/projects/apps-services/issues/new'
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- %w(app vendor).each do |folder|
3
+ %w[app vendor].each do |folder|
4
4
  path = Kadmin::Engine.root.join(folder, 'assets', '**', '*')
5
- Rails.application.config.assets.paths.concat(Dir.glob(path).select { |path| File.directory?(path) })
6
- Rails.application.config.assets.precompile.concat(Dir.glob(path).select { |path| File.file?(path) })
5
+ Rails.application.config.assets.paths.concat(Dir.glob(path).select { |p| File.directory?(p) })
6
+ Rails.application.config.assets.precompile.concat(Dir.glob(path).select { |p| File.file?(p) })
7
7
  end
8
8
  Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
data/config/routes.rb CHANGED
@@ -4,7 +4,7 @@ Kadmin::Engine.routes.draw do
4
4
  scope '/auth', controller: :auth, as: 'auth', defaults: { format: 'html' } do
5
5
  get '/login', action: :login, as: :login
6
6
  get '/logout', action: :logout, as: :logout
7
- match '/:provider/callback', action: :save, as: :callback, via: [:get, :post]
7
+ match '/:provider/callback', action: :save, as: :callback, via: %i[get post]
8
8
  get '/failure', action: :failure, as: :failure
9
9
  get '/unauthorized', action: :unauthorized, as: :unauthorized
10
10
  get '/', action: :login
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  class Configuration
4
5
  # @return [Logger] An instance of a Ruby compatible logger
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  module Presentable
4
5
  extend ActiveSupport::Concern
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kadmin
3
4
  class Presenter
4
5
  # Test class for Presenters. While this will not be common, it highlights how much
@@ -1,3 +1,3 @@
1
1
  module Kadmin
2
- VERSION = '0.6.19'.freeze
2
+ VERSION = '0.6.21'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.19
4
+ version: 0.6.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Pepin-Perreault
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-07-10 00:00:00.000000000 Z
13
+ date: 2017-08-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -74,6 +74,20 @@ dependencies:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0.4'
77
+ - !ruby/object:Gem::Dependency
78
+ name: barcoop
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
77
91
  description: Collection of utility, configuration, etc., for admin areas in a Rails
78
92
  application. Provides a boostrap environment, standard layout, authentication, and
79
93
  more.
@@ -172,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
186
  version: '0'
173
187
  requirements: []
174
188
  rubyforge_project:
175
- rubygems_version: 2.5.2
189
+ rubygems_version: 2.6.12
176
190
  signing_key:
177
191
  specification_version: 4
178
192
  summary: Collection of utility, configuration, etc., for admin areas