jekyll-heroicons 0.1.1 → 0.2

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: d75f8059ea7aa63207d3554a911705015944ad140535354c3488869f1b2c1276
4
+ data.tar.gz: 3fa2aa1a5127b87a6c209d26e2a868eaf8eb4987a790f59401db1789f71e043d
5
5
  SHA512:
6
- metadata.gz: d627303c0bf01da17aee0e56408ce006f3634909e8b296ffc1278228371af74e0fa57ca8f6c35a0f570c9c55b343b48669d18fb2a9d2c9516de601a6d4e0cd41
7
- data.tar.gz: 48d3fac6c1c06de615b73e4a13ef3327dd172f83d09bd76c94f0fa8bbc101f39e629cd954d043a9cd9ce1a10b75fd5bc8e107b62b4c574183ace9140c5e63c6b
6
+ metadata.gz: 57e8044b126bd1fb9839ff9c8eed9e6e33d247c0ef376a2311d6cbbc409cf2d1d9fe619ad9a651d9384b400544f87e9123a34107cfb602bf1681ec99dfabc5c1
7
+ data.tar.gz: 1091d7b8bd64b141ac8bb1ebf900f9be812179bf48f9198e6c45140c8e2a5e18dcb2d76da98810ce6199cb22d1b56c23d5a7e72ec7873e21c89023f99626a3c8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Jekyll-Heroicons
2
2
 
3
+ ## 0.2.0
4
+ - Introduce Icon class to deal with different parameters that could be passed to vsg code.
3
5
  ## 0.1.1
4
6
  - Include icons/ directory with a gem
5
7
  ## 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
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"
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'
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: