hyde-fonts 0.3.1 → 0.3.3

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: 3bb291228573bdea080627224050976ac18797c064ae8e4b3136cc032979d367
4
- data.tar.gz: eb6a3549cf8d1cc2dfcc460b34119f3d3b50ccada3ebbd1decf9f88a0fbf80fc
3
+ metadata.gz: 8b45842207d4fcca2f9294fc3926a10580fedf790fac681c216413da032d1677
4
+ data.tar.gz: 5786190067cbe6e726ac0317d9f06c02067c6e146fe67148e617e702830cb4f9
5
5
  SHA512:
6
- metadata.gz: f261bb3935f1187a39005c490c19519cc0fe9be749bdc321b29988f051ae2aa698d6bbfa037ef5977bb93105e774d559610ac11ad769c06930f4c9d5d6f6e605
7
- data.tar.gz: 0252b08511ba996024bb1b28d39138a6bf59a9a89922db06502fcae46ca2db91b5b1470e8bdf525a1421f97da690083f041c7237170d59e5a14baafbb77c293b
6
+ metadata.gz: 4c64109472b307adba55409231768623fa5ab9afffcb2d313b7de597ae54ac2275a1141886b3f8f361f7726d6335cb7cc344566d20093646c959df7b56ba3966
7
+ data.tar.gz: f44fd48352c0aaa10cc48940eae50f9bbf3ae3c93cd368e8966ab0609d810506a6db1b53e0e207fcc6194c816c8755adbd944dfa69009ad536dacc661a1cba76
data/lib/hyde-fonts.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Hyde
2
+ class Fonts
3
+ VERSION = "0.3.3"
4
+ end
5
+ end
6
+
7
+ require_relative "hyde_fonts/hyde_fonts"
@@ -13,12 +13,11 @@ module Hyde
13
13
  end
14
14
 
15
15
  def parse_faces
16
-
17
- for face in @data['faces'] do
16
+ for face in @data["faces"] do
18
17
  faces.push(Hyde::FontFace.new(face))
19
18
  end
20
19
 
21
- return faces
20
+ faces
22
21
  end
23
22
  end
24
23
  end
@@ -4,9 +4,9 @@ module Hyde
4
4
  attr_accessor :css
5
5
 
6
6
  def initialize(face)
7
- @name = face['name']
8
- @provider = face['provider']
9
- @weights = face['weights']
7
+ @name = face["name"]
8
+ @provider = face["provider"]
9
+ @weights = face["weights"]
10
10
  @variants = parse_variants
11
11
  @css = []
12
12
  end
@@ -20,19 +20,19 @@ module Hyde
20
20
  def to_s
21
21
  variants = sort_variants.map { |variant| variant.to_s }
22
22
 
23
- @name + ':ital,wght@' + variants.join(';')
23
+ @name + ":ital,wght@" + variants.join(";")
24
24
  end
25
25
 
26
- private
26
+ private
27
27
 
28
28
  def parse_variants
29
29
  variants = []
30
30
 
31
31
  for variant in @weights
32
- variants.push(Hyde::FontVariant.new(weight: variant['value'], italic: variant['italic']))
32
+ variants.push(Hyde::FontVariant.new(weight: variant["value"], italic: variant["italic"]))
33
33
  end
34
34
 
35
- return variants
35
+ variants
36
36
  end
37
37
  end
38
38
  end
@@ -18,11 +18,11 @@ module Hyde
18
18
  @uri = URI(uri)
19
19
  @format = format
20
20
 
21
- @filename = [@family, @style, @weight, @char_set + '.' + @format].join('_')
21
+ @filename = [@family, @style, @weight, @char_set + "." + @format].join("_")
22
22
  end
23
23
 
24
24
  def local_ruleset(path)
25
- @ruleset.gsub(/(?<=url\().*(?=\)\s)/, '/' + File.join(path, @filename))
25
+ @ruleset.gsub(/(?<=url\().*(?=\)\s)/, "/" + File.join(path, @filename))
26
26
  end
27
27
  end
28
28
  end
@@ -12,7 +12,7 @@ module Hyde
12
12
  end
13
13
 
14
14
  def to_s
15
- @italic.to_s + ',' + @weight.to_s
15
+ @italic.to_s + "," + @weight.to_s
16
16
  end
17
17
  end
18
18
  end
@@ -8,12 +8,12 @@ module Hyde
8
8
 
9
9
  def initialize(site, dir, name)
10
10
  @site = site
11
- @dir = dir
11
+ @dir = dir
12
12
  @name = name
13
13
  @relative_path = File.join(*[@dir, @name].compact)
14
14
  @extname = File.extname(@name)
15
15
  @type = @collection&.label&.to_sym
16
- @generator = 'hyde_fonts'
16
+ @generator = "hyde_fonts"
17
17
  end
18
18
 
19
19
  def write(dest)
@@ -23,7 +23,7 @@ module Hyde
23
23
  FileUtils.mkdir_p(File.dirname(dest_path))
24
24
  FileUtils.rm(dest_path) if File.exist?(dest_path)
25
25
 
26
- File.open(dest_path, 'w') do |output_file|
26
+ File.open(dest_path, "w") do |output_file|
27
27
  output_file << file_contents
28
28
  end
29
29
 
@@ -8,13 +8,13 @@ module Hyde
8
8
 
9
9
  def initialize(site, dir, name)
10
10
  @site = site
11
- @dir = dir
11
+ @dir = dir
12
12
  @name = name
13
13
  @relative_path = File.join(*[@dir, @name].compact)
14
14
  @extname = File.extname(@name)
15
15
  @type = @collection&.label&.to_sym
16
- @generator = 'hyde_fonts'
17
- @dest_path = ''
16
+ @generator = "hyde_fonts"
17
+ @dest_path = ""
18
18
  end
19
19
 
20
20
  def write(dest)
@@ -24,7 +24,7 @@ module Hyde
24
24
  FileUtils.mkdir_p(File.dirname(dest_path))
25
25
  FileUtils.rm(dest_path) if File.exist?(dest_path)
26
26
 
27
- File.open(dest_path, 'w') do |output_file|
27
+ File.open(dest_path, "w") do |output_file|
28
28
  output_file << file_contents
29
29
  end
30
30
 
@@ -1,11 +1,11 @@
1
- require 'jekyll'
2
- require_relative 'font_data.rb'
3
- require_relative 'font_face.rb'
4
- require_relative 'font_ruleset.rb'
5
- require_relative 'font_variant.rb'
6
- require_relative 'generated_css_file.rb'
7
- require_relative 'generated_font_file.rb'
8
- require_relative 'provider_google.rb'
1
+ require "jekyll"
2
+ require_relative "font_data"
3
+ require_relative "font_face"
4
+ require_relative "font_ruleset"
5
+ require_relative "font_variant"
6
+ require_relative "generated_css_file"
7
+ require_relative "generated_font_file"
8
+ require_relative "provider_google"
9
9
 
10
10
  module Jekyll
11
11
  class HydeFontsTag < Liquid::Tag
@@ -13,66 +13,67 @@ module Jekyll
13
13
  super
14
14
 
15
15
  @tag_name = tag_name
16
- style, indent = text.strip.split(' ')
16
+ style, indent = text.strip.split(" ")
17
+ return if style.nil?
17
18
  @style = style.strip
18
19
  @indent = indent.to_i || 0
19
20
  @tokens = tokens
20
21
  end
21
22
 
22
23
  def render(context)
23
- return unless context.registers[:site].config['hyde_fonts']['enable'] == true
24
+ return unless context.registers[:site].config["hyde_fonts"]["enable"] == true
24
25
 
25
26
  file = context.registers[:site].static_files.find { |file|
26
27
  file.is_a?(Hyde::GeneratedCssFile)
27
28
  }
28
29
 
29
- if @style == 'inline'
30
+ if @style == "inline"
30
31
  file.file_contents
31
- elsif @style == 'link'
32
+ elsif @style == "link"
32
33
  "<link href='" + file.relative_path + "' rel='stylesheet'>"
33
- elsif @style == 'decap-config'
34
- [
35
- "- label: Hyde-Fonts",
36
- " name: fonts",
37
- " file: \"src/_data/fonts.yml\"",
38
- " fields:",
39
- " - label: Fonts",
40
- " name: fonts",
41
- " widget: object",
42
- " fields:",
43
- " - label: Faces",
44
- " name: faces",
45
- " widget: list",
46
- " collapsed: false",
47
- " create: true",
48
- " fields:",
49
- " - label: Name",
50
- " name: name",
51
- " widget: string",
52
- " - label: Weights",
53
- " name: weights",
54
- " widget: list",
55
- " collapsed: false",
56
- " fields:",
57
- " - label: Weight",
58
- " name: value",
59
- " widget: string",
60
- " - label: Italic",
61
- " name: italic",
62
- " widget: boolean",
63
- ]
64
- .map { |x| x.prepend(' ' * 6) }
65
- .join("\n")
66
- .prepend("# Hyde Fonts ---\n")
34
+ elsif @style == "decap-config"
35
+ [
36
+ "- label: Hyde-Fonts",
37
+ " name: fonts",
38
+ " file: \"src/_data/fonts.yml\"",
39
+ " fields:",
40
+ " - label: Fonts",
41
+ " name: fonts",
42
+ " widget: object",
43
+ " fields:",
44
+ " - label: Faces",
45
+ " name: faces",
46
+ " widget: list",
47
+ " collapsed: false",
48
+ " create: true",
49
+ " fields:",
50
+ " - label: Name",
51
+ " name: name",
52
+ " widget: string",
53
+ " - label: Weights",
54
+ " name: weights",
55
+ " widget: list",
56
+ " collapsed: false",
57
+ " fields:",
58
+ " - label: Weight",
59
+ " name: value",
60
+ " widget: string",
61
+ " - label: Italic",
62
+ " name: italic",
63
+ " widget: boolean"
64
+ ]
65
+ .map { |x| x.prepend(" " * 6) }
66
+ .join("\n")
67
+ .prepend("# Hyde Fonts ---\n")
67
68
  end
68
69
  end
69
70
  end
70
71
 
71
- Liquid::Template.register_tag('hyde_fonts', Jekyll::HydeFontsTag)
72
+ Liquid::Template.register_tag("hyde_fonts", Jekyll::HydeFontsTag)
72
73
 
73
74
  class HydeFontsGenerator < Generator
74
75
  def generate(site)
75
- Hyde::Fonts.new(site).generate()
76
+ Hyde::Fonts.new(site).generate
76
77
  end
77
78
  end
78
79
  end
@@ -80,9 +81,9 @@ end
80
81
  module Hyde
81
82
  class Fonts
82
83
  @@config = {
83
- "data_source_name" => 'fonts',
84
- "file_output_path" => 'assets/fonts',
85
- "css_output_name" => 'fonts.css',
84
+ "data_source_name" => "fonts",
85
+ "file_output_path" => "assets/fonts",
86
+ "css_output_name" => "fonts.css",
86
87
  "css_minify" => true,
87
88
  "enable" => true,
88
89
  "fetch_fonts" => true,
@@ -91,35 +92,35 @@ module Hyde
91
92
 
92
93
  def initialize(site)
93
94
  @site = site
94
- @config = site.config.dig('hyde_fonts')
95
+ @config = site.config.dig("hyde_fonts")
95
96
 
96
- if (@config.nil?)
97
+ if @config.nil?
97
98
  @config = @@config
98
- site.config['hyde_fonts'] = @config
99
+ site.config["hyde_fonts"] = @config
99
100
  end
100
101
 
101
- if config('keep_files') == true
102
- @site.config['keep_files'].push(config('file_output_path'))
102
+ if config("keep_files") == true
103
+ @site.config["keep_files"].push(config("file_output_path"))
103
104
  end
104
105
 
105
- if site.config.dig('hyde_fonts').nil?
106
- @site.config['hyde_fonts'] = @config
106
+ if site.config.dig("hyde_fonts").nil?
107
+ @site.config["hyde_fonts"] = @config
107
108
  end
108
109
  end
109
110
 
110
111
  def generate
111
- return unless config('enable') == true
112
+ return unless config("enable") == true
112
113
  # get faces from jekyll data file
113
114
  font_data = Hyde::FontData.new(data)
114
115
 
115
116
  # handle font providers
116
117
  for face in font_data.faces
117
- Jekyll.logger.info('Fonts:', "Preparing #{face.name}")
118
+ Jekyll.logger.info("Fonts:", "Preparing #{face.name}")
118
119
 
119
120
  case face.provider
120
- when 'google'
121
+ when "google"
121
122
  Hyde::FontProviderGoogle.new(@site, @config).fetch(face)
122
- when 'local'
123
+ when "local"
123
124
  # TODO handle local fonts
124
125
  # Hyde::FontProviderLocal.new(@site, @config).fetch(face)
125
126
  end
@@ -127,26 +128,26 @@ module Hyde
127
128
 
128
129
  css = font_data.faces.map { |face| face.css }
129
130
  # generate static file containing face css rulesets
130
- css_file = Hyde::GeneratedCssFile.new(@site, config('file_output_path'), config('css_output_name'))
131
+ css_file = Hyde::GeneratedCssFile.new(@site, config("file_output_path"), config("css_output_name"))
131
132
  css_file.file_contents = minify(css.join("\n"))
132
133
 
133
134
  @site.static_files << css_file
134
135
  end
135
136
 
136
- private
137
+ private
137
138
 
138
- def config(*keys)
139
- @config.dig(*keys)
139
+ def config(*)
140
+ @config.dig(*)
140
141
  end
141
142
 
142
143
  def data
143
- @site.data.dig(config('data_source_name'), 'fonts')
144
+ @site.data.dig(config("data_source_name"), "fonts")
144
145
  end
145
146
 
146
147
  def minify(css)
147
- return css if config('css_minify') == false
148
+ return css if config("css_minify") == false
148
149
 
149
- converter_config = { 'sass' => { 'style' => 'compressed' } }
150
+ converter_config = {"sass" => {"style" => "compressed"}}
150
151
 
151
152
  Jekyll::Converters::Scss.new(converter_config).convert(css)
152
153
  end
@@ -1,5 +1,5 @@
1
- require 'uri'
2
- require 'net/http'
1
+ require "uri"
2
+ require "net/http"
3
3
 
4
4
  module Hyde
5
5
  class FontProviderGoogle
@@ -13,10 +13,10 @@ module Hyde
13
13
 
14
14
  begin
15
15
  uri_payload = Net::HTTP.get(face_uri, {
16
- "User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0'
16
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0"
17
17
  })
18
18
  rescue
19
- Jekyll.logger.warn('Fonts Warning:', 'Unable to reach Google Fonts service.')
19
+ Jekyll.logger.warn("Fonts Warning:", "Unable to reach Google Fonts service.")
20
20
  return
21
21
  end
22
22
 
@@ -30,14 +30,14 @@ module Hyde
30
30
  end
31
31
  end
32
32
 
33
- private
33
+ private
34
34
 
35
35
  def face_uri
36
- google_uri_base = 'https://fonts.googleapis.com/css2'
37
- params = [['display', 'swap']]
38
- params.push(['family', @face.to_s])
36
+ google_uri_base = "https://fonts.googleapis.com/css2"
37
+ params = [["display", "swap"]]
38
+ params.push(["family", @face.to_s])
39
39
 
40
- uri = google_uri_base + '?' + params.map { |param| param.join('=') }.join('&')
40
+ uri = google_uri_base + "?" + params.map { |param| param.join("=") }.join("&")
41
41
 
42
42
  URI(uri)
43
43
  end
@@ -50,21 +50,21 @@ module Hyde
50
50
 
51
51
  def fetch_font_from_ruleset(ruleset)
52
52
  filename = ruleset.filename
53
- file = Hyde::GeneratedFontFile.new(@site, @config['file_output_path'], filename)
53
+ file = Hyde::GeneratedFontFile.new(@site, @config["file_output_path"], filename)
54
54
 
55
- destination_fname = file.destination('./')
55
+ destination_fname = file.destination("./")
56
56
 
57
- if @config['keep_files'] == true
58
- Jekyll.logger.debug('Fonts:', "file #{filename} already exists.")
57
+ if @config["keep_files"] == true
58
+ Jekyll.logger.debug("Fonts:", "file #{filename} already exists.")
59
59
  return if File.exist?(destination_fname)
60
60
  end
61
61
 
62
- if @config['fetch_fonts'] == false
63
- Jekyll.logger.warn('Fonts:', "fetch disabled, no local version of #{filename} found.")
62
+ if @config["fetch_fonts"] == false
63
+ Jekyll.logger.warn("Fonts:", "fetch disabled, no local version of #{filename} found.")
64
64
  return
65
65
  end
66
66
 
67
- Jekyll.logger.debug('Fonts:', "downloading #{@face.name} from #{@face.provider}")
67
+ Jekyll.logger.debug("Fonts:", "downloading #{@face.name} from #{@face.provider}")
68
68
  font_uri_payload = Net::HTTP.get(ruleset.uri)
69
69
  file.file_contents = font_uri_payload
70
70
 
@@ -72,7 +72,7 @@ module Hyde
72
72
  end
73
73
 
74
74
  def rewrite_ruleset_to_local(ruleset)
75
- ruleset.local_ruleset(@config['file_output_path'])
75
+ ruleset.local_ruleset(@config["file_output_path"])
76
76
  end
77
77
  end
78
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyde-fonts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Daynes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-05 00:00:00.000000000 Z
11
+ date: 2023-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -37,7 +37,7 @@ executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
- - lib/hyde_fonts.rb
40
+ - lib/hyde-fonts.rb
41
41
  - lib/hyde_fonts/font_data.rb
42
42
  - lib/hyde_fonts/font_face.rb
43
43
  - lib/hyde_fonts/font_ruleset.rb
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.4.6
68
+ rubygems_version: 3.5.3
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: Plugin for jekyll to manage google fonts
data/lib/hyde_fonts.rb DELETED
@@ -1,8 +0,0 @@
1
- module Hyde
2
- class Fonts
3
- VERSION = "0.3.1"
4
- end
5
- end
6
-
7
- require_relative './hyde_fonts/hyde_fonts.rb'
8
-