klenod-build 0.0.33 → 0.0.34

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8d75c7c0abc58318ff254e605f618ba14399b9df7fab791e2de204c5546774f
4
- data.tar.gz: 86117e7ef465f1a39c59eb25d937eaad3ce0d25096f5a569c396b298db9beccf
3
+ metadata.gz: 5c9113a2ead2ad79421171b10bff81a17d78ab553c7ee07ca65a30fe174cc1ce
4
+ data.tar.gz: aac9493e330c9705ffef7ed136edd78ad148c89e9b282fbdde835609230aff92
5
5
  SHA512:
6
- metadata.gz: a4213e39362700cb1a30e741a48f5e26220b7e00ad77f4cd4f52fddb0ed13ccf5e7bf54f9661da232d3da47f831004169e9217a5e2fe4d5bc8bf654198fde4cb
7
- data.tar.gz: 8c1377e40417a5bb09eccca2a167c14883054debd8a9cc010726e748fccc77e9e962243bdd36bb30137b219f487a522404a7d2dc1130630d053326734c13875c
6
+ metadata.gz: '09af24e68044c29489757c960e4040b8b471705b9ce5bf7193982d9dbe1fc79c48624304a2ad4911a96f7715b52ee9eacad13e44246e9a305618037d6c53845f'
7
+ data.tar.gz: 3f05c599da56eb48373e8084c3f8f33047fc443398a29e52218b9addc61e230581943fa6627be3fd0c70885db2293b68a49a762a316b8aa2d2a0ded2ac56b8ad
@@ -16,13 +16,16 @@ module Klenod
16
16
  @extensions = extensions.freeze
17
17
  @path_prefix = path_prefix.to_s
18
18
  @spelling_index = nil
19
+ @directory_entries = {}
19
20
  end
20
21
 
21
- # Forget the cached file listing behind did-you-mean suggestions. The
22
- # owning resolver clears it whenever files change, so a suggestion never
23
- # walks the source tree more than once between file events.
22
+ # Forget the cached directory listings, and the file listing behind
23
+ # did-you-mean suggestions. The owning resolver clears them whenever
24
+ # files change, so neither reads the source tree more than once
25
+ # between file events.
24
26
  def clear_cache
25
27
  @spelling_index = nil
28
+ @directory_entries = {}
26
29
  end
27
30
 
28
31
  def resolve(relative_path)
@@ -101,12 +104,19 @@ module Klenod
101
104
  end
102
105
  end
103
106
 
107
+ # Kept until the cache is cleared. Every import of a file reads the
108
+ # directories above it, so a directory of a thousand modules was
109
+ # listed a thousand times.
104
110
  def directory_entries(directory)
105
- return [] unless directory.directory?
111
+ @directory_entries[directory.to_s] ||= read_directory_entries(directory)
112
+ end
113
+
114
+ def read_directory_entries(directory)
115
+ return Set.new unless directory.directory?
106
116
 
107
- directory.children.map { it.basename.to_s }
117
+ directory.children.to_set { it.basename.to_s }
108
118
  rescue SystemCallError
109
- []
119
+ Set.new
110
120
  end
111
121
 
112
122
  SpellingIndex = Data.define(:aliases, :checker)
@@ -555,17 +555,19 @@ module Klenod
555
555
  def module_ids_for_assets(record_or_module_id, recursive:, type: nil)
556
556
  return Array(record_or_module_id).map { |module_ref| module_id_for(module_ref) }.uniq unless recursive
557
557
 
558
- seen = []
558
+ # A hash, because a page of a large site reaches thousands of modules
559
+ # and each of them asks whether it was seen.
560
+ seen = {}
559
561
  Array(record_or_module_id).flat_map do |module_ref|
560
562
  ordered_module_ids_for_assets(module_id_for(module_ref), seen, type: type)
561
563
  end
562
564
  end
563
565
 
564
566
  def ordered_module_ids_for_assets(module_id, seen, type: nil)
565
- return [] if seen.include?(module_id)
567
+ return [] if seen.key?(module_id)
566
568
  return [] unless @records.key?(module_id)
567
569
 
568
- seen << module_id
570
+ seen[module_id] = true
569
571
  record = @records.fetch(module_id)
570
572
  dependency_ids =
571
573
  record
@@ -161,6 +161,15 @@
161
161
  "unitsPerEm": 2048,
162
162
  "xWidthAvg": 649
163
163
  },
164
+ "Agrave Pro": {
165
+ "familyName": "Agrave Pro",
166
+ "category": "handwriting",
167
+ "ascent": 1050,
168
+ "descent": -390,
169
+ "lineGap": 0,
170
+ "unitsPerEm": 1000,
171
+ "xWidthAvg": 423
172
+ },
164
173
  "Agu Display": {
165
174
  "familyName": "Agu Display",
166
175
  "category": "display",
@@ -2832,7 +2841,7 @@
2832
2841
  "descent": -245,
2833
2842
  "lineGap": 330,
2834
2843
  "unitsPerEm": 1000,
2835
- "xWidthAvg": 451
2844
+ "xWidthAvg": 450
2836
2845
  },
2837
2846
  "Castoro Titling": {
2838
2847
  "familyName": "Castoro Titling",
@@ -2841,7 +2850,7 @@
2841
2850
  "descent": -245,
2842
2851
  "lineGap": 330,
2843
2852
  "unitsPerEm": 1000,
2844
- "xWidthAvg": 613
2853
+ "xWidthAvg": 608
2845
2854
  },
2846
2855
  "Catamaran": {
2847
2856
  "familyName": "Catamaran",
@@ -4715,6 +4724,15 @@
4715
4724
  "unitsPerEm": 1000,
4716
4725
  "xWidthAvg": 379
4717
4726
  },
4727
+ "Firjar": {
4728
+ "familyName": "Firjar",
4729
+ "category": "sans-serif",
4730
+ "ascent": 1000,
4731
+ "descent": -400,
4732
+ "lineGap": 0,
4733
+ "unitsPerEm": 1000,
4734
+ "xWidthAvg": 438
4735
+ },
4718
4736
  "Fjalla One": {
4719
4737
  "familyName": "Fjalla One",
4720
4738
  "category": "sans-serif",
@@ -7931,8 +7949,8 @@
7931
7949
  "Linefont": {
7932
7950
  "familyName": "Linefont",
7933
7951
  "category": "display",
7934
- "ascent": 1200,
7935
- "descent": -200,
7952
+ "ascent": 1300,
7953
+ "descent": -300,
7936
7954
  "lineGap": 0,
7937
7955
  "unitsPerEm": 1000,
7938
7956
  "xWidthAvg": 100
@@ -14075,6 +14093,69 @@
14075
14093
  "unitsPerEm": 1000,
14076
14094
  "xWidthAvg": 464
14077
14095
  },
14096
+ "Redaction": {
14097
+ "familyName": "Redaction",
14098
+ "category": "serif",
14099
+ "ascent": 900,
14100
+ "descent": -300,
14101
+ "lineGap": 0,
14102
+ "unitsPerEm": 1000,
14103
+ "xWidthAvg": 443
14104
+ },
14105
+ "Redaction 10": {
14106
+ "familyName": "Redaction 10",
14107
+ "category": "serif",
14108
+ "ascent": 900,
14109
+ "descent": -300,
14110
+ "lineGap": 0,
14111
+ "unitsPerEm": 1000,
14112
+ "xWidthAvg": 442
14113
+ },
14114
+ "Redaction 100": {
14115
+ "familyName": "Redaction 100",
14116
+ "category": "display",
14117
+ "ascent": 900,
14118
+ "descent": -300,
14119
+ "lineGap": 0,
14120
+ "unitsPerEm": 1000,
14121
+ "xWidthAvg": 436
14122
+ },
14123
+ "Redaction 20": {
14124
+ "familyName": "Redaction 20",
14125
+ "category": "serif",
14126
+ "ascent": 900,
14127
+ "descent": -300,
14128
+ "lineGap": 0,
14129
+ "unitsPerEm": 1000,
14130
+ "xWidthAvg": 441
14131
+ },
14132
+ "Redaction 35": {
14133
+ "familyName": "Redaction 35",
14134
+ "category": "display",
14135
+ "ascent": 900,
14136
+ "descent": -300,
14137
+ "lineGap": 0,
14138
+ "unitsPerEm": 1000,
14139
+ "xWidthAvg": 442
14140
+ },
14141
+ "Redaction 50": {
14142
+ "familyName": "Redaction 50",
14143
+ "category": "display",
14144
+ "ascent": 900,
14145
+ "descent": -300,
14146
+ "lineGap": 0,
14147
+ "unitsPerEm": 1000,
14148
+ "xWidthAvg": 444
14149
+ },
14150
+ "Redaction 70": {
14151
+ "familyName": "Redaction 70",
14152
+ "category": "display",
14153
+ "ascent": 900,
14154
+ "descent": -300,
14155
+ "lineGap": 0,
14156
+ "unitsPerEm": 1000,
14157
+ "xWidthAvg": 443
14158
+ },
14078
14159
  "Reddit Mono": {
14079
14160
  "familyName": "Reddit Mono",
14080
14161
  "category": "monospace",
@@ -16471,13 +16552,22 @@
16471
16552
  },
16472
16553
  "Tiny5": {
16473
16554
  "familyName": "Tiny5",
16474
- "category": "sans-serif",
16555
+ "category": "display",
16475
16556
  "ascent": 896,
16476
16557
  "descent": -256,
16477
16558
  "lineGap": 0,
16478
16559
  "unitsPerEm": 1024,
16479
16560
  "xWidthAvg": 438
16480
16561
  },
16562
+ "Tiny5 Duo": {
16563
+ "familyName": "Tiny5 Duo",
16564
+ "category": "display",
16565
+ "ascent": 896,
16566
+ "descent": -256,
16567
+ "lineGap": 0,
16568
+ "unitsPerEm": 1024,
16569
+ "xWidthAvg": 640
16570
+ },
16481
16571
  "Tiro Bangla": {
16482
16572
  "familyName": "Tiro Bangla",
16483
16573
  "category": "serif",
@@ -17201,8 +17291,8 @@
17201
17291
  "Wavefont": {
17202
17292
  "familyName": "Wavefont",
17203
17293
  "category": "display",
17204
- "ascent": 1200,
17205
- "descent": -200,
17294
+ "ascent": 1300,
17295
+ "descent": -300,
17206
17296
  "lineGap": 0,
17207
17297
  "unitsPerEm": 1000,
17208
17298
  "xWidthAvg": 100
@@ -17324,6 +17414,15 @@
17324
17414
  "unitsPerEm": 1000,
17325
17415
  "xWidthAvg": 500
17326
17416
  },
17417
+ "Xmind": {
17418
+ "familyName": "Xmind",
17419
+ "category": "sans-serif",
17420
+ "ascent": 2053,
17421
+ "descent": -610,
17422
+ "lineGap": 0,
17423
+ "unitsPerEm": 2048,
17424
+ "xWidthAvg": 909
17425
+ },
17327
17426
  "Yaldevi": {
17328
17427
  "familyName": "Yaldevi",
17329
17428
  "category": "sans-serif",
@@ -17439,7 +17538,7 @@
17439
17538
  "descent": -288,
17440
17539
  "lineGap": 0,
17441
17540
  "unitsPerEm": 1000,
17442
- "xWidthAvg": 516
17541
+ "xWidthAvg": 501
17443
17542
  },
17444
17543
  "Young Serif": {
17445
17544
  "familyName": "Young Serif",
@@ -5,7 +5,7 @@ Update them to the latest Capsize revision from the Klenod repository root:
5
5
  bundle exec rake google_fonts:metrics:update
6
6
 
7
7
  Project: https://github.com/seek-oss/capsize
8
- Commit: 51946f815deeef7d9d97e0149659abdb50348099
8
+ Commit: 89b2a35dffe676f2fd06d6acb5e5880c33b15199
9
9
  Source: packages/metrics/src/entireMetricsCollection.json
10
10
 
11
11
  MIT License
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ require_relative "../hashing"
6
+
7
+ module Klenod
8
+ module Build
9
+ module Plugins
10
+ # Keeps the Ruby that a Markdown file compiles to on disk between runs.
11
+ # Compiling is most of the cost of loading a Markdown module, and the
12
+ # result depends only on the text and the plugin's options, so a file
13
+ # that has not changed is not compiled again.
14
+ #
15
+ # There is one entry per name, and a new key replaces it, so the
16
+ # directory does not grow as a file is edited.
17
+ class MarkdownCache
18
+ PARSER_GEMS = %w[kramdown kramdown-parser-gfm].freeze
19
+
20
+ # Everything that decides the result apart from the inputs: the code
21
+ # of this gem and the parser it runs. An edit to either makes every
22
+ # entry stale.
23
+ def self.compiler_key
24
+ @compiler_key ||=
25
+ Hashing.hexdigest(
26
+ [
27
+ *Dir[File.join(__dir__, "..", "**", "*.rb")].sort.map { Hashing.file_hexdigest(it) },
28
+ *PARSER_GEMS.map { Gem.loaded_specs[it]&.version.to_s }
29
+ ].join("\0")
30
+ )
31
+ end
32
+
33
+ def initialize(path)
34
+ @path = path.to_s
35
+ end
36
+
37
+ # `name` says which entry, `inputs` are the strings the result is
38
+ # compiled from. The block compiles them when the entry is missing or
39
+ # was written for other inputs.
40
+ def fetch(name, *inputs)
41
+ key = Hashing.hexdigest([self.class.compiler_key, *inputs].join("\0"))
42
+ path = File.join(@path, "#{Hashing.hexdigest(name)}.rb")
43
+
44
+ read(path, key) || write(path, key, yield)
45
+ end
46
+
47
+ private
48
+
49
+ def read(path, key)
50
+ stored_key, compiled = File.read(path, encoding: Encoding::UTF_8).split("\n", 2)
51
+ compiled if stored_key == key
52
+ rescue SystemCallError
53
+ nil
54
+ end
55
+
56
+ def write(path, key, compiled)
57
+ temp_path = "#{path}.tmp.#{$$}.#{object_id}"
58
+ FileUtils.mkdir_p(@path)
59
+ File.write(temp_path, "#{key}\n#{compiled}")
60
+ File.rename(temp_path, path)
61
+ compiled
62
+ rescue
63
+ FileUtils.rm_f(temp_path) if temp_path
64
+ raise
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -14,6 +14,7 @@ require_relative "class_names_runtime"
14
14
  require_relative "component_defaults"
15
15
  require_relative "data_plugin"
16
16
  require_relative "haml_plugin"
17
+ require_relative "markdown_cache"
17
18
  require_relative "markdown_compiler"
18
19
 
19
20
  module Klenod
@@ -58,10 +59,12 @@ module Klenod
58
59
 
59
60
  def initialize(
60
61
  component_base_class: DEFAULT_COMPONENT_BASE_CLASS,
61
- factory: DEFAULT_FACTORY
62
+ factory: DEFAULT_FACTORY,
63
+ cache_path: nil
62
64
  )
63
65
  @component_base_class = component_base_class
64
66
  @factory = factory
67
+ @cache = cache_path && MarkdownCache.new(cache_path)
65
68
  end
66
69
 
67
70
  def resolve(dependency, _context)
@@ -76,22 +79,9 @@ module Klenod
76
79
  return super unless module_id.extname == ".md"
77
80
 
78
81
  frontmatter, markdown_source = parse_frontmatter(code, module_id)
79
- builder = HamlPlugin::Transformer::RubyBuilder.new(profiler: context.profiler)
80
82
  dependency = markdown_components_dependency(module_id, context)
81
83
  class_names_dependency = class_names_runtime_dependency(module_id)
82
- components_source = components_source_for(dependency)
83
- render_source = MarkdownCompiler.new(factory: @factory, components_source: components_source).compile(markdown_source)
84
- component_class_name = component_class_name(module_id)
85
- class_names_source = "#{builder.import_call(class_names_dependency.id).source}.new({}.freeze)"
86
- generated =
87
- builder.component_source(
88
- component_class_name: component_class_name,
89
- component_base_class: @component_base_class,
90
- translations_source: "{}.freeze",
91
- ruby_source: "",
92
- render_source: render_source,
93
- styles_source: class_names_source
94
- )
84
+ generated = component_source_for(module_id, markdown_source, dependency, class_names_dependency, context)
95
85
  generated = "#{generated}\nDefault.const_set(:Frontmatter, #{frontmatter.inspect}.freeze)\n"
96
86
 
97
87
  TransformResult.new(
@@ -122,6 +112,34 @@ module Klenod
122
112
 
123
113
  private
124
114
 
115
+ # The cache entry is named after the file, so each file has one.
116
+ def component_source_for(module_id, markdown_source, dependency, class_names_dependency, context)
117
+ inputs = [
118
+ component_class_name(module_id),
119
+ components_source_for(dependency),
120
+ class_names_dependency.id,
121
+ markdown_source
122
+ ]
123
+ return compile_component(*inputs, context) unless @cache
124
+
125
+ @cache.fetch(context.absolute_path(module_id).to_s, @factory, @component_base_class, *inputs) do
126
+ compile_component(*inputs, context)
127
+ end
128
+ end
129
+
130
+ def compile_component(component_class_name, components_source, class_names_id, markdown_source, context)
131
+ builder = HamlPlugin::Transformer::RubyBuilder.new(profiler: context.profiler)
132
+
133
+ builder.component_source(
134
+ component_class_name: component_class_name,
135
+ component_base_class: @component_base_class,
136
+ translations_source: "{}.freeze",
137
+ ruby_source: "",
138
+ render_source: MarkdownCompiler.new(factory: @factory, components_source: components_source).compile(markdown_source),
139
+ styles_source: "#{builder.import_call(class_names_id).source}.new({}.freeze)"
140
+ )
141
+ end
142
+
125
143
  def parse_frontmatter(source, module_id)
126
144
  match = source.match(/\A---[ \t]*\r?\n(?<frontmatter>.*?\r?\n)---[ \t]*(?:\r?\n|\z)/m)
127
145
  return [{}, source] unless match
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Klenod
4
4
  module Build
5
- VERSION = "0.0.33"
5
+ VERSION = "0.0.34"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klenod-build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Alin
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.33
18
+ version: 0.0.34
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.33
25
+ version: 0.0.34
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: async
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -159,16 +159,22 @@ dependencies:
159
159
  name: prism
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  requirements:
162
- - - "~>"
162
+ - - ">="
163
163
  - !ruby/object:Gem::Version
164
164
  version: '1.9'
165
+ - - "<"
166
+ - !ruby/object:Gem::Version
167
+ version: '3.0'
165
168
  type: :runtime
166
169
  prerelease: false
167
170
  version_requirements: !ruby/object:Gem::Requirement
168
171
  requirements:
169
- - - "~>"
172
+ - - ">="
170
173
  - !ruby/object:Gem::Version
171
174
  version: '1.9'
175
+ - - "<"
176
+ - !ruby/object:Gem::Version
177
+ version: '3.0'
172
178
  - !ruby/object:Gem::Dependency
173
179
  name: protocol-url
174
180
  requirement: !ruby/object:Gem::Requirement
@@ -288,6 +294,7 @@ files:
288
294
  - lib/klenod/build/plugins/haml_plugin/transformer/ruby_builder.rb
289
295
  - lib/klenod/build/plugins/image_plugin.rb
290
296
  - lib/klenod/build/plugins/intl_plugin.rb
297
+ - lib/klenod/build/plugins/markdown_cache.rb
291
298
  - lib/klenod/build/plugins/markdown_compiler.rb
292
299
  - lib/klenod/build/plugins/markdown_plugin.rb
293
300
  - lib/klenod/build/plugins/router_plugin.rb