heroicon 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d84d48fe0bd5ee18ae0a8ff4fcb18700b44415bdb6c834b2d606b334635990c
4
- data.tar.gz: e34a0b8f7f67ae51c8d0712b28c9592c5a6a40bb1b91a790a2a025f9b18856e8
3
+ metadata.gz: 4b1da2f6a254f8d75998ee51b23dae5e795f1b020c2a4558aa765f99b5b0c290
4
+ data.tar.gz: df21e11c2767a743614d7ee5a01f95bd32aec73ea3445a409ed8462166f9cd6a
5
5
  SHA512:
6
- metadata.gz: 3b5ad7a7dd7e3636840d551f75c449ab16da0f43e868abe9e3d5304abefd99fb3dce2651c93d15c1efde4d87a09c9475c28b3c7f6fa1edbb7dc02596f0d0f98c
7
- data.tar.gz: 66f0d51350a460c9b23518e3a6f9982a2ac3890ea97e0f3b2c3fb4fc5ee5a2d1afc97e391d34a378fe97662bdc5e86ba4f195abf981c25ad7551141828f455a2
6
+ metadata.gz: 0525f055760da3fb88e91f688ac16511cc9d15a434f46708e8134b95fd9e0b1727684ed5e11f7ac567a7b144d1e2feffe363b623af4e495ceb368688d43b193c
7
+ data.tar.gz: bf4faf542d32e2b246d2bfae07fd71fb99adaa01d06b7eed63f2904e3502ebd113b77c7a1205a1ac3c2cbc99764ee2880df47923ce780b6ddc17f12ba38e238e
data/README.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # Heroicon
2
+
2
3
  [![Build Status](https://github.com/bharget/heroicon/workflows/CI/badge.svg)](https://github.com/bharget/heroicon/actions)
3
4
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
4
5
 
5
- Ruby on Rails view helpers for the beautiful hand-crafted SVG icons, Heroicons. This gem has no official affiliation with Tailwind CSS or the Heroicon team.
6
+ Ruby on Rails view helpers for the beautiful hand-crafted SVG icons, Heroicons.
7
+
8
+ Used in production at [Morning Brew ☕](https://www.morningbrew.com/?utm_source=bharget_github)
6
9
 
7
- Check out their sites:
10
+ This gem has no official affiliation with Tailwind CSS or the Heroicon team (yet!). Check out their sites:
8
11
 
9
12
  - [Tailwind CSS](https://tailwindcss.com/?utm_source=bharget_github)
10
13
  - [Tailwind UI](https://tailwindui.com/?utm_source=bharget_github)
11
14
  - [Heroicons](https://heroicons.com/?utm_source=bharget_github)
12
15
 
13
16
  ## Installation
17
+
14
18
  Add this line to your application's Gemfile:
15
19
 
16
20
  ```ruby
@@ -18,11 +22,13 @@ gem "heroicon"
18
22
  ```
19
23
 
20
24
  And then execute:
25
+
21
26
  ```bash
22
27
  $ bundle
23
28
  ```
24
29
 
25
30
  Run the installer
31
+
26
32
  ```bash
27
33
  $ rails g heroicon:install
28
34
  ```
@@ -35,19 +41,47 @@ To use a icon in your views, simply use the provided view helper with the name o
35
41
  <%= heroicon "search" %>
36
42
  ```
37
43
 
38
- Heroicon comes with two variants, `:outline` and `:solid`. By default it uses the variant provided in the configuration file that was generated during installation. To overwrite this in the view, use
44
+ Heroicon comes with two variants, `:outline` and `:solid`. The default variant is `:solid`. This can be changed in `config/initializers/heroicon.rb`, which is generated during installation (See [Configuration](#configuration)). To overwrite this in the view, use
39
45
 
40
46
  ```rb
41
47
  <%= heroicon "search", variant: :outline %>
42
48
  ```
43
49
 
44
- You can also pass a class to use on the icon.
50
+ You can also pass HTML options directly to the icon.
45
51
 
46
52
  ```rb
47
53
  <%= heroicon "search", options: { class: "text-primary-500" } %>
48
54
  ```
49
55
 
50
- Heroicon currently supports icons up to `Version 0.4.1`. If there is a icon that is missing, feel free to contribute by following our contributing guide below.
56
+ Heroicon currently supports icons up to [`Version 1.0.1`](https://github.com/tailwindlabs/heroicons/releases/tag/v1.0.1). If there is a icon that is missing, feel free to contribute by following our contributing guide below.
57
+
58
+ # Configuration
59
+
60
+ After running `rails g heroicon:install` in the installation step, a configuration file will be created at `config/initializers/heroicon.rb`.
61
+
62
+ Currently there are two configuration options:
63
+
64
+ - `variant`: The default variant to use if no variant is specified in the view.
65
+ - You can set this to either `:outline` or `:solid`. Defaults to `:solid`.
66
+ - `default_class`: A default class that gets applied to every icon.
67
+ - This accepts either a String to apply to every icon, or a Hash, which applies the class based on the variant of the icon (see the example below).
68
+ - You can disable this on a per-icon basis by passing `disable_default_class: true` in the options hash within the view.
69
+ - _Note: If you use the `default_class` option with PurgeCSS (or something similar), make sure you add the classes you want to use to the generated CSS file. For PurgeCSS, you may want to add `config/intializers/heroicon.rb` to the list of purged paths._
70
+
71
+ An example configuration looks like this:
72
+
73
+ ```ruby
74
+ Heroicon.configure do |config|
75
+ config.variant = :solid
76
+ config.default_class = {solid: "h-5 w-5", outline: "h-6 w-6"}
77
+ end
78
+ ```
79
+
80
+ Disabling the default class in the view:
81
+
82
+ ```rb
83
+ <%= heroicon "search", options: { class: "custom-class" disable_default_class: true } %>
84
+ ```
51
85
 
52
86
  ## Contributing
53
87
 
@@ -68,4 +102,5 @@ bundle exec rake test
68
102
  ```
69
103
 
70
104
  ## License
105
+
71
106
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,5 +1,5 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
2
- <path fill="#fff" d="M12 14l9-5-9-5-9 5 9 5z"/>
3
- <path fill="#fff" d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"/>
2
+ <path d="M12 14l9-5-9-5-9 5 9 5z"/>
3
+ <path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"/>
4
4
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222"/>
5
5
  </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
2
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 13l-5 5m0 0l-5-5m5 5V6"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
2
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 17l-5-5m0 0l5-5m-5 5h12"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
2
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7l5 5m0 0l-5 5m5-5H6"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
2
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 11l5-5m0 0l5 5m-5-5v12"/>
3
+ </svg>
@@ -1,4 +1,4 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
2
- <path fill="#fff" d="M9 17a2 2 0 11-4 0 2 2 0 014 0zM19 17a2 2 0 11-4 0 2 2 0 014 0z"/>
2
+ <path d="M9 17a2 2 0 11-4 0 2 2 0 014 0zM19 17a2 2 0 11-4 0 2 2 0 014 0z"/>
3
3
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16V6a1 1 0 00-1-1H4a1 1 0 00-1 1v10a1 1 0 001 1h1m8-1a1 1 0 01-1 1H9m4-1V8a1 1 0 011-1h2.586a1 1 0 01.707.293l3.414 3.414a1 1 0 01.293.707V16a1 1 0 01-1 1h-1m-6-1a1 1 0 001 1h1M5 17a2 2 0 104 0m-4 0a2 2 0 114 0m6 0a2 2 0 104 0m-4 0a2 2 0 114 0"/>
4
4
  </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
2
+ <path fill-rule="evenodd" d="M14.707 10.293a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 111.414-1.414L9 12.586V5a1 1 0 012 0v7.586l2.293-2.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
2
+ <path fill-rule="evenodd" d="M9.707 14.707a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 1.414L7.414 9H15a1 1 0 110 2H7.414l2.293 2.293a1 1 0 010 1.414z" clip-rule="evenodd"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
2
+ <path fill-rule="evenodd" d="M10.293 5.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L12.586 11H5a1 1 0 110-2h7.586l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
2
+ <path fill-rule="evenodd" d="M5.293 9.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 7.414V15a1 1 0 11-2 0V7.414L6.707 9.707a1 1 0 01-1.414 0z" clip-rule="evenodd"/>
3
+ </svg>
@@ -2,8 +2,13 @@
2
2
 
3
3
  module Heroicon
4
4
  module ApplicationHelper
5
- def heroicon(name, variant: Heroicon.configuration.variant, options: {})
6
- raw Heroicon::Icon.render(name: name, variant: variant, options: options)
5
+ def heroicon(name, variant: Heroicon.configuration.variant, options: {}, path_options: {})
6
+ raw Heroicon::Icon.render(
7
+ name: name,
8
+ variant: variant,
9
+ options: options,
10
+ path_options: path_options
11
+ )
7
12
  end
8
13
  end
9
14
  end
@@ -2,4 +2,9 @@
2
2
 
3
3
  Heroicon.configure do |config|
4
4
  config.variant = :solid # Options are :solid and :outline
5
+
6
+ ##
7
+ # You can set a default class, which will get applied to every icon with
8
+ # the given variant. To do so, un-comment the line below.
9
+ # config.default_class = {solid: "h-5 w-5", outline: "h-6 w-6"}
5
10
  end
data/lib/heroicon.rb CHANGED
@@ -5,4 +5,7 @@ require "heroicon/icon"
5
5
  require "heroicon/configuration"
6
6
 
7
7
  module Heroicon
8
+ def self.root
9
+ File.dirname(__dir__)
10
+ end
8
11
  end
@@ -2,10 +2,13 @@
2
2
 
3
3
  module Heroicon
4
4
  class Configuration
5
+ DEFAULT_VARIANT = :solid
6
+
5
7
  attr_accessor :variant
8
+ attr_accessor :default_class
6
9
 
7
10
  def initialize
8
- @variant = :solid
11
+ @variant = DEFAULT_VARIANT
9
12
  end
10
13
  end
11
14
 
data/lib/heroicon/icon.rb CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  module Heroicon
4
4
  class Icon
5
- attr_reader :name, :variant, :options
5
+ attr_reader :name, :variant, :options, :path_options
6
6
 
7
- def initialize(name:, variant:, options:)
7
+ def initialize(name:, variant:, options:, path_options:)
8
8
  @name = name
9
9
  @variant = safe_variant(variant)
10
10
  @options = options
11
+ @path_options = path_options
11
12
  end
12
13
 
13
14
  def render
@@ -15,13 +16,53 @@ module Heroicon
15
16
 
16
17
  doc = Nokogiri::HTML::DocumentFragment.parse(file)
17
18
  svg = doc.at_css "svg"
18
- svg["class"] = options[:class] if options[:class].present?
19
+
20
+ path_options.each do |key, value|
21
+ attribute = key.to_s.dasherize
22
+ svg.css("path[#{attribute}]").each do |item|
23
+ item[attribute] = value.to_s
24
+ end
25
+ end
26
+
27
+ prepend_default_class_name
28
+
29
+ options.each do |key, value|
30
+ svg[key.to_s] = value
31
+ end
19
32
 
20
33
  doc
21
34
  end
22
35
 
23
36
  private
24
37
 
38
+ ##
39
+ # Prepends the default CSS class name for an icon. You can provide a String, which will apply
40
+ # to all icons, or a Hash, which will apply to the specified variant.
41
+ #
42
+ # @example
43
+ # Heroicon.configure do |config|
44
+ # config.default_class = { solid: "h-5 w-5", outline: "h-6 w-6" }
45
+ # end
46
+ #
47
+ # #=> <svg class="h-5 w-5">...</svg>
48
+ def prepend_default_class_name
49
+ return if disable_default_class?
50
+
51
+ default_class_config = Heroicon.configuration.default_class
52
+
53
+ default_class = if default_class_config.is_a?(String)
54
+ default_class_config
55
+ elsif default_class_config.is_a?(Hash)
56
+ default_class_config[variant]
57
+ end
58
+
59
+ options[:class] = "#{default_class} #{options[:class]}".strip if default_class.present?
60
+ end
61
+
62
+ def disable_default_class?
63
+ @disable_default_class ||= !!options.delete(:disable_default_class)
64
+ end
65
+
25
66
  def safe_variant(provided_variant)
26
67
  if %i[solid outline].include?(provided_variant.to_sym)
27
68
  provided_variant
@@ -31,26 +72,32 @@ module Heroicon
31
72
  end
32
73
 
33
74
  def file
34
- @file ||= Rails.application.assets_manifest.find_sources("heroicon/#{variant}/#{name}.svg").first.force_encoding("UTF-8")
75
+ @file ||= File.read(file_path).force_encoding("UTF-8")
35
76
  rescue
36
77
  nil
37
78
  end
38
79
 
80
+ def file_path
81
+ File.join(Heroicon.root, "app/assets/images/heroicon/#{variant}/#{name}.svg")
82
+ end
83
+
39
84
  def warning
40
85
  return unless Rails.env.development?
41
86
 
42
- <<-HTML
87
+ script = <<-HTML
43
88
  <script type="text/javascript">
44
89
  //<![CDATA[
45
90
  console.warn("Heroicon: Failed to find heroicon: #{name}")
46
91
  //]]>
47
92
  </script>
48
93
  HTML
94
+
95
+ script.strip
49
96
  end
50
97
 
51
98
  class << self
52
- def render(*args)
53
- new(*args).render
99
+ def render(**kwargs)
100
+ new(**kwargs).render
54
101
  end
55
102
  end
56
103
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Heroicon
4
- VERSION = "0.2.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroicon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Hargett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-15 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Ruby on Rails view helpers for the beautiful hand-crafted SVG icons,
98
112
  Heroicons.
99
113
  email:
@@ -120,6 +134,10 @@ files:
120
134
  - app/assets/images/heroicon/outline/arrow-narrow-right.svg
121
135
  - app/assets/images/heroicon/outline/arrow-narrow-up.svg
122
136
  - app/assets/images/heroicon/outline/arrow-right.svg
137
+ - app/assets/images/heroicon/outline/arrow-sm-down.svg
138
+ - app/assets/images/heroicon/outline/arrow-sm-left.svg
139
+ - app/assets/images/heroicon/outline/arrow-sm-right.svg
140
+ - app/assets/images/heroicon/outline/arrow-sm-up.svg
123
141
  - app/assets/images/heroicon/outline/arrow-up.svg
124
142
  - app/assets/images/heroicon/outline/arrows-expand.svg
125
143
  - app/assets/images/heroicon/outline/at-symbol.svg
@@ -346,6 +364,10 @@ files:
346
364
  - app/assets/images/heroicon/solid/arrow-narrow-right.svg
347
365
  - app/assets/images/heroicon/solid/arrow-narrow-up.svg
348
366
  - app/assets/images/heroicon/solid/arrow-right.svg
367
+ - app/assets/images/heroicon/solid/arrow-sm-down.svg
368
+ - app/assets/images/heroicon/solid/arrow-sm-left.svg
369
+ - app/assets/images/heroicon/solid/arrow-sm-right.svg
370
+ - app/assets/images/heroicon/solid/arrow-sm-up.svg
349
371
  - app/assets/images/heroicon/solid/arrow-up.svg
350
372
  - app/assets/images/heroicon/solid/arrows-expand.svg
351
373
  - app/assets/images/heroicon/solid/at-symbol.svg