nfg_ui 0.9.24.3 → 0.9.25

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: 9bb7cf85aae07648d3c7ee2131ffef86a7a3a3895338c3da54b8a92d77511fc1
4
- data.tar.gz: 7e4f35065081bfb343c817768bf60a55c3a9cc378ab136152608f27b21eaea26
3
+ metadata.gz: 255605aaf79082c250a38e2021f2cef46d06c90bca81af9912574ac62d110ecb
4
+ data.tar.gz: 21a793d0674e7bb9f4aacac84617f57ab118ffe2cf923ff341a2ca61db0fb688
5
5
  SHA512:
6
- metadata.gz: b84c1e2c619990fce3e695fd493ea05cb7e1216e851d0493686049707d3b0576e84617646b7bfd896b286aa46638bd98907216b029d0e84136ee6f32c9b447df
7
- data.tar.gz: 48be56ae1accf774edb14031b782498f88692b0502bc018776786363409da125c7c204f578e7e684a5177a9a1fcf1d6aea9b9d0f506290243496d047cd411e41
6
+ metadata.gz: 44bf230b5ee51da2b00f3bd8bf2e0410bf67d80310887f15c0978a74beccd4c3dbfcf59b96bbae0b77909c42bcc31a1df82a8499366f262b9e822d6a9a9d1da3
7
+ data.tar.gz: a827a15667b221b27e064897d7de30ba8142a36f1cb5962be21c30ffdc4880a3ae50735b72fab76e5626d353258d4a0e1e9e47897b0dd6d2ce12c554cab8134c
@@ -5,12 +5,14 @@ module NfgUi
5
5
  module Traits
6
6
  # Access to pre-designed Alert traits
7
7
  module Alert
8
+ include NfgUi::Components::Utilities::Traits::TraitUtilities
9
+
8
10
  TRAITS = %i[tip].freeze
9
11
 
10
12
  def tip_trait
11
- options[:icon] = NfgUi::DEFAULT_TIP_ICON
12
- options[:theme] = NfgUi::DEFAULT_TIP_THEME
13
- options[:dismissible] = false
13
+ maybe_update_option(:icon, value: NfgUi::DEFAULT_TIP_ICON)
14
+ maybe_update_option(:theme, value: NfgUi::DEFAULT_TIP_THEME)
15
+ maybe_update_option(:dismissible, value: false)
14
16
  end
15
17
  end
16
18
  end
@@ -5,6 +5,8 @@ module NfgUi
5
5
  module Traits
6
6
  # Access to pre-designed Icon traits
7
7
  module Icon
8
+ include NfgUi::Components::Utilities::Traits::TraitUtilities
9
+
8
10
  TRAITS = %i[loader tip].freeze
9
11
 
10
12
  def loader_trait
@@ -15,11 +17,12 @@ module NfgUi
15
17
  # Usage:
16
18
  # ui.nfg :icon, :tip, tooltip: 'The tip'
17
19
  def tip_trait
18
- options[:icon] = NfgUi::DEFAULT_TIP_ICON
19
- options[:theme] = NfgUi::DEFAULT_TIP_THEME
20
+ maybe_update_option(:icon, value: NfgUi::DEFAULT_TIP_ICON)
21
+
22
+ maybe_update_option(:theme, value: NfgUi::DEFAULT_TIP_THEME)
20
23
 
21
24
  if options[:text].present?
22
- options[:right] = true
25
+ maybe_update_option(:right, value: true)
23
26
  options[:class] += ' fa-fw'
24
27
  end
25
28
  end
@@ -5,12 +5,13 @@ module NfgUi
5
5
  module Traits
6
6
  # Access to pre-designed traits
7
7
  module Navbar
8
+ include NfgUi::Components::Utilities::Traits::TraitUtilities
9
+
8
10
  TRAITS = %i[white].freeze
9
11
 
10
12
  def white_trait
11
- options[:light] = true
12
- # options[:class] += ' bg-white'
13
- options[:theme] = :white
13
+ maybe_update_option(:light, value: true)
14
+ maybe_update_option(:theme, value: :white)
14
15
  end
15
16
  end
16
17
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NfgUi
4
+ module Components
5
+ module Utilities
6
+ module Traits
7
+ module TraitUtilities
8
+ private
9
+
10
+ # As a practice, traits are designed to help not rule.
11
+ #
12
+ # Leveraging this method to conditionally overwrite values in the options hash
13
+ # ensures that users of the gem are able to use
14
+ # traits and further customize them on the fly.
15
+ #
16
+ # Example:
17
+ # An example trait adjusts an icon and the theme.
18
+ # Gem user wants to customize the theme in a unique setting
19
+ # = ui.nfg :icon, :tip, theme: :danger
20
+ #
21
+ # Without using this #maybe_update_option method, `theme: :danger`
22
+ # would be ignored (and thus overwritten) by by the :tip trait
23
+ #
24
+ # Thus, when using this method, the :tip trait would first check if :theme option is present _before_
25
+ # setting the established trait's options[:theme] value.
26
+ #
27
+ # It may not always be necessary or appropriate to use this method. For example,
28
+ # Some traits modify only one value in options, and if that trait is being overwritten by a supplied option,
29
+ # it defeats the purpose of the trait.
30
+ #
31
+ # Example where method usage is not necessary:
32
+ # def active_trait
33
+ # options[:active] = true
34
+ # end
35
+ #
36
+ # Overall, trait creation doctrine really
37
+ # prefers usage of this method.
38
+ #
39
+ #
40
+ # Example Usage:
41
+ #
42
+ # def white_trait
43
+ # maybe_update_option(:light, value: true)
44
+ # maybe_update_option(:theme, value: :white)
45
+ # end
46
+ def maybe_update_option(option_key, value:)
47
+ return if options[option_key].present?
48
+ options[option_key] = value
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NfgUi
4
- VERSION = '0.9.24.3'
4
+ VERSION = '0.9.25'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfg_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.24.3
4
+ version: 0.9.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Roehm
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-06 00:00:00.000000000 Z
12
+ date: 2019-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bootstrap
@@ -749,6 +749,7 @@ files:
749
749
  - lib/nfg_ui/components/utilities/resource_themeable.rb
750
750
  - lib/nfg_ui/components/utilities/titleable.rb
751
751
  - lib/nfg_ui/components/utilities/traitable.rb
752
+ - lib/nfg_ui/components/utilities/traits/trait_utilities.rb
752
753
  - lib/nfg_ui/components/utilities/vertically_alignable.rb
753
754
  - lib/nfg_ui/engine.rb
754
755
  - lib/nfg_ui/ui/base.rb