jekyll-heroicons 0.1.1 → 0.2.1

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: 322cd61f2d8878a54eb79e17095b92481ab9c61e4ae901c34a89bef592601644
4
- data.tar.gz: 1ea45b683425828a15df226a591143b8d85afc0b59099730de462189d5f60d1c
3
+ metadata.gz: 112fbd4869748edda881eba9c9ef2ee54455adc9bd02f9459f2b6f6283561242
4
+ data.tar.gz: fd5b1f750f6a421d0ec7666a653c572d468cd7e3d062bc0dbe635641d8f40f87
5
5
  SHA512:
6
- metadata.gz: d627303c0bf01da17aee0e56408ce006f3634909e8b296ffc1278228371af74e0fa57ca8f6c35a0f570c9c55b343b48669d18fb2a9d2c9516de601a6d4e0cd41
7
- data.tar.gz: 48d3fac6c1c06de615b73e4a13ef3327dd172f83d09bd76c94f0fa8bbc101f39e629cd954d043a9cd9ce1a10b75fd5bc8e107b62b4c574183ace9140c5e63c6b
6
+ metadata.gz: fb3f32efc24439124b355dd25a95265c7253045864de3a4bf513b63d4c1cc1451bfb4c17602cdf1b192d260b6eebcc05e187128d8a2cef738e94f91c07bfefc2
7
+ data.tar.gz: 6da0122ce4bac2056602a170e1a02d522e0d12f744fb7f76bc10b4b7832e2f391415b1658d5dce1e8a0879ccf895ab6395012126c48e097e478d01f0dd196120
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Jekyll-Heroicons
2
2
 
3
+ ## 0.2.1
4
+ - Remove new line character from icon raw code.
5
+ ## 0.2.0
6
+ - Introduce Icon class to deal with different parameters that could be passed to vsg code.
3
7
  ## 0.1.1
4
8
  - Include icons/ directory with a gem
5
9
  ## 0.1
data/README.md CHANGED
@@ -30,6 +30,12 @@ Configure default settings in `_config.yml`:
30
30
  ```ruby
31
31
  heroicons:
32
32
  variant: 'solid'
33
+ default_class: {
34
+ solid: "size-6",
35
+ outline: "size-6",
36
+ mini: "size-5",
37
+ micro: "size-4",
38
+ }
33
39
  ```
34
40
 
35
41
  And then you can use:
@@ -0,0 +1,44 @@
1
+ require "nokogiri"
2
+
3
+ module Jekyll
4
+ class Heroicons < Liquid::Tag
5
+ class Icon
6
+ def initialize(symbol, variant, options = {})
7
+ @symbol = symbol
8
+ @variant = variant
9
+ @options = options
10
+ end
11
+
12
+ def raw
13
+ doc = Nokogiri::HTML::DocumentFragment.parse(file)
14
+ svg = doc.at_css "svg"
15
+
16
+ prepend_default_classes
17
+
18
+ @options.each do |key, value|
19
+ svg[key.to_s] = value
20
+ end
21
+
22
+ doc.to_html.strip
23
+ end
24
+
25
+ private
26
+
27
+ def prepend_default_classes
28
+ if @options[:class]
29
+ @options[:class] += " size-6"
30
+ else
31
+ @options[:class] = "size-6"
32
+ end
33
+ end
34
+
35
+ def file
36
+ @file ||= File.read(file_path).force_encoding("UTF-8")
37
+ end
38
+
39
+ def file_path
40
+ File.join(Jekyll::Heroicons.root, "icons/#{@variant}/#{@symbol}.svg")
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #prevent bundler errors
3
+ # prevent bundler errors
4
4
  module Liquid; class Tag; end; end
5
5
 
6
6
  module Jekyll
7
7
  class Heroicons < Liquid::Tag
8
- VERSION = "0.1.1"
8
+ VERSION = "0.2.1"
9
9
  end
10
10
  end
@@ -1,39 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'jekyll-heroicons/version'
4
- require 'liquid'
5
- require 'jekyll/liquid_extensions'
3
+ require_relative "jekyll-heroicons/version"
4
+ require_relative "jekyll-heroicons/icon"
5
+ require "liquid"
6
+ require "jekyll/liquid_extensions"
6
7
 
7
8
  module Jekyll
8
9
  class Heroicons < Liquid::Tag
9
10
  include Jekyll::LiquidExtensions
10
11
 
12
+ def self.root
13
+ File.dirname(__dir__)
14
+ end
15
+
11
16
  # Syntax for the heroicon symbol
12
- Syntax = /\A(#{Liquid::VariableSignature}+)/
17
+ SYNTAX = /\A(#{Liquid::VariableSignature}+)/
13
18
 
14
19
  # For interpolation, look for liquid variables
15
- Variable = /\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i
20
+ VARIABLE = /\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i
16
21
 
17
22
  # Copied from Liquid::TagAttributes to allow dashes in tag names:
18
23
  #
19
24
  # {% heroicon alert area-label:"Hello World!" %}
20
25
  #
21
- TagAttributes = /([\w-]+)\s*\:\s*(#{Liquid::QuotedFragment})/o
26
+ TAG_ATTRIBUTES = /([\w-]+)\s*:\s*(#{Liquid::QuotedFragment})/o
22
27
 
23
28
  def initialize(tag_name, markup, options)
24
29
  super
25
30
  @markup = markup
26
31
 
27
32
  # If there's interpolation going on, we need to do this in render
28
- prepare(markup) unless markup.match(Variable)
33
+ prepare(markup) unless markup.match(VARIABLE)
29
34
  end
30
35
 
31
36
  def render(context)
32
- prepare(interpolate(@markup, context)) if @markup.match(Variable)
37
+ prepare(interpolate(@markup, context)) if @markup.match(VARIABLE)
33
38
 
34
39
  return nil if @symbol.nil?
35
40
 
36
- File.read(File.expand_path("../icons/#{@variant}/#{@symbol}.svg", __dir__))
41
+ Icon.new(@symbol, @variant, @options.except(:variant)).raw
37
42
  end
38
43
 
39
44
  private
@@ -41,16 +46,16 @@ module Jekyll
41
46
  def prepare(markup)
42
47
  @symbol = symbol(markup)
43
48
  @options = string_to_hash(markup)
44
- @variant = if (match = markup.split('/')).length > 1
45
- match.first
46
- elsif @options.key?(:variant)
47
- @options[:variant]
48
- end
49
+ @variant = if (match = markup.split("/")).length > 1
50
+ match.first
51
+ elsif @options.key?(:variant)
52
+ @options[:variant]
53
+ end
49
54
  end
50
55
 
51
56
  def interpolate(markup, context)
52
- markup.scan Variable do |variable|
53
- markup = markup.gsub(Variable, lookup_variable(context, variable.first))
57
+ markup.scan VARIABLE do |variable|
58
+ markup = markup.gsub(VARIABLE, lookup_variable(context, variable.first))
54
59
  end
55
60
  markup
56
61
  end
@@ -59,9 +64,9 @@ module Jekyll
59
64
  def string_to_hash(markup)
60
65
  options = {}
61
66
 
62
- if markup.match(Syntax)
63
- markup.scan(TagAttributes) do |key, value|
64
- options[key.to_sym] = value.gsub(/\A"|"\z/, '')
67
+ if markup.match(SYNTAX)
68
+ markup.scan(TAG_ATTRIBUTES) do |key, value|
69
+ options[key.to_sym] = value.gsub(/\A"|"\z/, "")
65
70
  end
66
71
  end
67
72
 
@@ -69,13 +74,13 @@ module Jekyll
69
74
  end
70
75
 
71
76
  def symbol(markup)
72
- if (match = markup.split('/')).length > 1
73
- match[1].match(Syntax)
77
+ if (match = markup.split("/")).length > 1
78
+ match[1].match(SYNTAX)
74
79
  else
75
- markup.match(Syntax)
80
+ markup.match(SYNTAX)
76
81
  end
77
82
  end
78
83
  end
79
84
  end
80
85
 
81
- Liquid::Template.register_tag('heroicon', Jekyll::Heroicons)
86
+ Liquid::Template.register_tag("heroicon", Jekyll::Heroicons)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-heroicons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Jekyll liquid tags for the beautiful hand-crafted SVG icons, Heroicons.
28
42
  email:
29
43
  - github@skatkov.com
@@ -1326,6 +1340,7 @@ files:
1326
1340
  - icons/solid/x-circle.svg
1327
1341
  - icons/solid/x-mark.svg
1328
1342
  - lib/jekyll-heroicons.rb
1343
+ - lib/jekyll-heroicons/icon.rb
1329
1344
  - lib/jekyll-heroicons/version.rb
1330
1345
  homepage: https://github.com/skatkov/jekyll-heroicons
1331
1346
  licenses: