heroicons_helper 0.4.1 → 0.4.2
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 +4 -4
 - data/README.md +3 -3
 - data/lib/heroicons_helper/icon.rb +10 -10
 - data/lib/heroicons_helper/version.rb +1 -1
 - data/lib/heroicons_helper.rb +16 -3
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 32e795de2bdf5ffe8332a8e4d6cdb04def32910875e359606d5fcc65dc31f82d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ea6e061f06312b495ed529102e10972a06f10462134ef0d96f32de246ee7bd2e
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 07b15015752f2446cd1939ad3a330bffa9a313142b55d291e4ed1941b68ee047f5591ef921978deb0cb3619da28ab66a1da9f7e1e1ac06faafd011df61ca46ba
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: dd8578a59db2b627bb809b59051e5d2f238c9c559f6cfe1d0ee91f7eb1ab56d2d5ab88e93f6be5e45f040089d5fb0332b767a7db3df367dcadc5ffe16e3d1ae6
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # HeroiconsHelper
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            This gem helps you use Heroicons in your Ruby projects. It's inspired by [heroicons-ruby](https://github.com/chunlea/heroicons-ruby) and [ 
     | 
| 
      
 3 
     | 
    
         
            +
            This gem helps you use Heroicons in your Ruby projects. It's inspired by [heroicons-ruby](https://github.com/chunlea/heroicons-ruby) and [octicons_gem](https://github.com/primer/octicons/tree/main/lib/octicons_gem).
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            ## Installation
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
         @@ -25,12 +25,12 @@ include HeroiconsHelper 
     | 
|
| 
       25 
25 
     | 
    
         
             
            You'll have a brand new method called `heroicon` whose signature looks like this:
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            ```ruby
         
     | 
| 
       28 
     | 
    
         
            -
            heroicon( 
     | 
| 
      
 28 
     | 
    
         
            +
            heroicon(icon, variant, attributes: {})
         
     | 
| 
       29 
29 
     | 
    
         
             
            ```
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
            where
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
            * ` 
     | 
| 
      
 33 
     | 
    
         
            +
            * `icon` is the Heroicon name (eg. `:bell` or `"bell")
         
     | 
| 
       34 
34 
     | 
    
         
             
            * `variant` is the type of Heroicons (eg., `outline` or `solid`)
         
     | 
| 
       35 
35 
     | 
    
         
             
            * `attributes` are any additional HTML attributes to add on to the resulting `svg` element
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
         @@ -3,17 +3,17 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            module HeroiconsHelper
         
     | 
| 
       4 
4 
     | 
    
         
             
              # Icon to show heroicons by name and variant.
         
     | 
| 
       5 
5 
     | 
    
         
             
              class Icon
         
     | 
| 
       6 
     | 
    
         
            -
                attr_reader :path, :attributes, :width, :height, : 
     | 
| 
      
 6 
     | 
    
         
            +
                attr_reader :path, :attributes, :width, :height, :name, :variant, :keywords
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                VARIANT_OUTLINE = "outline"
         
     | 
| 
       9 
9 
     | 
    
         
             
                VARIANT_SOLID = "solid"
         
     | 
| 
       10 
10 
     | 
    
         
             
                VARIANTS = [VARIANT_OUTLINE, VARIANT_SOLID].freeze
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                def initialize( 
     | 
| 
       13 
     | 
    
         
            -
                  @ 
     | 
| 
      
 12 
     | 
    
         
            +
                def initialize(name, variant, attributes: {})
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @name = name.to_s
         
     | 
| 
       14 
14 
     | 
    
         
             
                  @variant = variant.to_s
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  heroicon = get_heroicon(@ 
     | 
| 
      
 16 
     | 
    
         
            +
                  heroicon = get_heroicon(@name, @variant)
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                  @path = heroicon["path"]
         
     | 
| 
       19 
19 
     | 
    
         
             
                  @width = heroicon["width"]
         
     | 
| 
         @@ -54,7 +54,7 @@ module HeroiconsHelper 
     | 
|
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                # prepare the octicon class
         
     | 
| 
       56 
56 
     | 
    
         
             
                private def classes
         
     | 
| 
       57 
     | 
    
         
            -
                  "heroicon heroicon-#{@ 
     | 
| 
      
 57 
     | 
    
         
            +
                  "heroicon heroicon-#{@name}-#{@variant} #{@attributes[:class]} ".strip
         
     | 
| 
       58 
58 
     | 
    
         
             
                end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                private def variant_attributes
         
     | 
| 
         @@ -101,17 +101,17 @@ module HeroiconsHelper 
     | 
|
| 
       101 
101 
     | 
    
         
             
                  (width.to_i * @height) / @width
         
     | 
| 
       102 
102 
     | 
    
         
             
                end
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
                private def get_heroicon( 
     | 
| 
       105 
     | 
    
         
            -
                  raise ArgumentError, "Icon name can't be empty" if  
     | 
| 
      
 104 
     | 
    
         
            +
                private def get_heroicon(name, variant)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  raise ArgumentError, "Icon name can't be empty" if name.empty?
         
     | 
| 
       106 
106 
     | 
    
         | 
| 
       107 
107 
     | 
    
         
             
                  raise ArgumentError, "Variant `#{variant.inspect}` is invalid; must be one of #{VARIANTS.join(", ")}" unless VARIANTS.include?(variant)
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
                  icon = HeroiconsHelper:: 
     | 
| 
      
 109 
     | 
    
         
            +
                  icon = HeroiconsHelper::ICON_NAMES[name]
         
     | 
| 
       110 
110 
     | 
    
         | 
| 
       111 
     | 
    
         
            -
                  raise ArgumentError, "Couldn't find Heroicon for `#{ 
     | 
| 
      
 111 
     | 
    
         
            +
                  raise ArgumentError, "Couldn't find Heroicon for `#{name.inspect}`" unless icon
         
     | 
| 
       112 
112 
     | 
    
         | 
| 
       113 
113 
     | 
    
         
             
                  icon_variant = icon["variants"][variant]
         
     | 
| 
       114 
     | 
    
         
            -
                  raise ArgumentError, "Heroicon for `#{ 
     | 
| 
      
 114 
     | 
    
         
            +
                  raise ArgumentError, "Heroicon for `#{name.inspect}` doesn't have variant `#{variant.inspect}`" unless icon_variant
         
     | 
| 
       115 
115 
     | 
    
         | 
| 
       116 
116 
     | 
    
         
             
                  {
         
     | 
| 
       117 
117 
     | 
    
         
             
                    "name" => icon["name"],
         
     | 
    
        data/lib/heroicons_helper.rb
    CHANGED
    
    | 
         @@ -7,9 +7,22 @@ require "json" 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            module HeroiconsHelper
         
     | 
| 
       9 
9 
     | 
    
         
             
              file_data = File.read(File.join(File.dirname(__FILE__), "./heroicons_helper/data.json"))
         
     | 
| 
       10 
     | 
    
         
            -
               
     | 
| 
      
 10 
     | 
    
         
            +
              ICON_NAMES = JSON.parse(file_data).freeze
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              def heroicon( 
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
      
 12 
     | 
    
         
            +
              def heroicon(name, variant:, **attributes)
         
     | 
| 
      
 13 
     | 
    
         
            +
                cache_key = HeroiconsHelper::Cache.get_key(
         
     | 
| 
      
 14 
     | 
    
         
            +
                  name: name,
         
     | 
| 
      
 15 
     | 
    
         
            +
                  variant: variant,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  height: attributes[:height],
         
     | 
| 
      
 17 
     | 
    
         
            +
                  width: attributes[:width]
         
     | 
| 
      
 18 
     | 
    
         
            +
                )
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                cached_heroicon = HeroiconsHelper::Cache.read(cache_key)
         
     | 
| 
      
 21 
     | 
    
         
            +
                return cached_heroicon unless cached_heroicon.nil?
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                heroicon = ::HeroiconsHelper::Icon.new(name, variant, attributes: attributes)
         
     | 
| 
      
 24 
     | 
    
         
            +
                HeroiconsHelper::Cache.set(cache_key, heroicon)
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                heroicon
         
     | 
| 
       14 
27 
     | 
    
         
             
              end
         
     | 
| 
       15 
28 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: heroicons_helper
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.4. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Garen J. Torikian
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2022-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-06-15 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: A package that distributes Heroicons as a gem, for easy inclusion in
         
     | 
| 
       14 
14 
     | 
    
         
             
              Ruby projects.
         
     |