ndr_ui 3.0.0 → 3.1.0

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
  SHA256:
3
- metadata.gz: c2ff0be798e49d6cbfecd8a82543a26ffbacbb2f174d845514c85a5a7559d47c
4
- data.tar.gz: 5976e1781c40230a0b1119d6471e1f426f6c993c9773ae1e96a13ee8a3c05533
3
+ metadata.gz: 3584658f79ff90044cc3e87c60a194ca964d7c59fb257784d90db46b3f7f87c1
4
+ data.tar.gz: 607c2995d427226512cbce4eddb889f809edaa11fb6707656bf25b9484921571
5
5
  SHA512:
6
- metadata.gz: a795f3be88fbe72eb68194117c5cff8c7292860164fb28d2ee0e0b047bd04a58ce1967cfcda8071aebf0cd681757259c913afca1acda9a8b83cf04bc09101515
7
- data.tar.gz: 96d6ea40d4816fbffca4c974be97ad0ca749871b12dc12d60c1e785c9755e7fc7c17e118668f6b46d2b9b70f6b4703900962b8c5b43e820ccba250efee696335
6
+ metadata.gz: 5bf345b17539ac9d694ba9bb1ffc8a02b4e87effda793384be7e02f672d28fda2ef158d5c1857b8298488a43a46f08be873352972148a04596d11d8e7e980b81
7
+ data.tar.gz: 338e557549e9cd6dd5c0d249ff36e316b892830a2662371d557a2b824b8be65f1992b80d2e272d6db16b642a88e2fd7788ae3c50d26ea5e3e576688ea0382fd6
@@ -445,6 +445,36 @@ module NdrUi
445
445
  content_tag(:div, capture(&block), class: 'btn-group')
446
446
  end
447
447
 
448
+ # Creates a Boostrap 'New' link.
449
+ #
450
+ # ==== Signatures
451
+ #
452
+ # new_link(path, options = {})
453
+ #
454
+ # ==== Examples
455
+ #
456
+ # <%= new_link('#') %>
457
+ # # => <a title="New" class="btn btn-primary btn-xs" href="#">
458
+ # <span class="glyphicon glyphicon-plus-sign"></span>
459
+ # </a>
460
+ #
461
+ # <%= new_link(Post.new) %>
462
+ # # => <a title="New" class="btn btn-primary btn-xs" href="/posts/new">
463
+ # <span class="glyphicon glyphicon-plus-sign"></span>
464
+ # </a>
465
+ #
466
+ def new_link(path, options = {})
467
+ return unless options.delete(:skip_authorization) || ndr_can?(:new, path)
468
+
469
+ path = new_polymorphic_path(path) if can_generate_polymorphic_path?(path)
470
+
471
+ defaults = {
472
+ icon: 'plus-sign', title: 'New', path: path, class: 'btn btn-primary btn-xs'
473
+ }
474
+
475
+ link_to_with_icon(defaults.merge(options))
476
+ end
477
+
448
478
  # Creates a Boostrap 'Details' link.
449
479
  #
450
480
  # ==== Signatures
@@ -459,7 +489,7 @@ module NdrUi
459
489
  # </a>
460
490
  #
461
491
  def details_link(path, options = {})
462
- return unless options[:skip_authorization] || ndr_can?(:read, path)
492
+ return unless options.delete(:skip_authorization) || ndr_can?(:read, path)
463
493
 
464
494
  link_to_with_icon({ icon: 'share-alt', title: 'Details', path: path }.merge(options))
465
495
  end
@@ -478,7 +508,7 @@ module NdrUi
478
508
  # </a>
479
509
  #
480
510
  def edit_link(path, options = {})
481
- return unless options[:skip_authorization] || ndr_can?(:edit, path)
511
+ return unless options.delete(:skip_authorization) || ndr_can?(:edit, path)
482
512
 
483
513
  path = edit_polymorphic_path(path) if path.is_a?(ActiveRecord::Base)
484
514
 
@@ -499,7 +529,7 @@ module NdrUi
499
529
  # <span class="glyphicon glyphicon-trash icon-white"></span>
500
530
  # </a>'
501
531
  def delete_link(path, options = {})
502
- return unless options[:skip_authorization] || ndr_can?(:delete, path)
532
+ return unless options.delete(:skip_authorization) || ndr_can?(:delete, path)
503
533
 
504
534
  defaults = {
505
535
  icon: 'trash icon-white', title: 'Delete', path: path,
@@ -574,5 +604,12 @@ module NdrUi
574
604
 
575
605
  can?(action, subject, *extra_args)
576
606
  end
607
+
608
+ def can_generate_polymorphic_path?(path)
609
+ case path
610
+ when Array, ActiveRecord::Base then true
611
+ else false
612
+ end
613
+ end
577
614
  end
578
615
  end
@@ -1,2 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+ resources :posts do
3
+ resources :comments
4
+ end
2
5
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # This stores the current version of the NdrUi gem. Use semantic versioning http://semver.org
4
4
  module NdrUi
5
- VERSION = '3.0.0'.freeze
5
+ VERSION = '3.1.0'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndr_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NDR Development Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails