jekyll-antex 0.4.0 → 0.6.1

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: b8af04a4d3122b7e58926aed907120b7bef5e4d5cfb660be03c625f1e0ec48d4
4
- data.tar.gz: 4066bd201baba8f6bdcf724f38ea8991eb011da58f1da13831d32547781ade9c
3
+ metadata.gz: 7d7e55a185748b2e917234281bb7f2242ddc40a4d36a81da3c82c63e394fa1f5
4
+ data.tar.gz: e5f4058b0c13c5a0397fb181a9c1fc6c266b9ea1957d3265a35dbbdb6592cee5
5
5
  SHA512:
6
- metadata.gz: 86ebce737fc0c681b040f329d46aee48198d528a25e0bab5bbbecebc5da5215fb5f462bd385a5f211e97063b45639feaf76cfa0343ac19ec7fd28ccf0091c530
7
- data.tar.gz: 381bc28893d16e442f07567eddee15b08bab1eed15387eb4b3793dbc8e35949a61dcaa0d79e98b1716db5268762d99c6e91304c806a81e914eeaaf111658eee3
6
+ metadata.gz: f7d87025ca79d0f2bd6aa8e2f0f66d8c7fb1f2d5683bc24f01c5fbace55b6bc069b07e15f93cb78fdd41b9abc8f4809f7b48d4f96f9f404c8eb23d7aa99882ee
7
+ data.tar.gz: babab2523a37de3b562008177980c36f37e7c8588c2de46888d9b428683e3c608e8fe012cefc3aba0891b9fc411dc79bac2f6dec4e50fdd9ae4b2de6e0888ad6
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
1
  # jekyll-antex
2
2
 
3
- [![Build Status](https://travis-ci.org/paolobrasolin/jekyll-antex.svg?branch=master)](https://travis-ci.org/paolobrasolin/jekyll-antex)
4
- [![Gem Version](https://badge.fury.io/rb/jekyll-antex.svg)](https://badge.fury.io/rb/jekyll-antex)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![CI tests status badge][build-shield]][build-url]
4
+ [![Latest release badge][rubygems-shield]][rubygems-url]
5
+ [![License badge][license-shield]][license-url]
6
+ [![Maintainability badge][cc-maintainability-shield]][cc-maintainability-url]
7
+ [![Test coverage badge][cc-coverage-shield]][cc-coverage-url]
6
8
 
7
- [![Code Climate](https://codeclimate.com/github/paolobrasolin/jekyll-antex/badges/gpa.svg)](https://codeclimate.com/github/paolobrasolin/jekyll-antex)
8
- [![Test Coverage](https://codeclimate.com/github/paolobrasolin/jekyll-antex/badges/coverage.svg)](https://codeclimate.com/github/paolobrasolin/jekyll-antex/coverage)
9
- [![Inline docs](http://inch-ci.org/github/paolobrasolin/jekyll-antex.svg?branch=master)](http://inch-ci.org/github/paolobrasolin/jekyll-antex)
10
- [![Issue Count](https://codeclimate.com/github/paolobrasolin/jekyll-antex/badges/issue_count.svg)](https://codeclimate.com/github/paolobrasolin/jekyll-antex)
9
+ [build-shield]: https://img.shields.io/github/workflow/status/paolobrasolin/jekyll-antex/CI/main?label=tests&logo=github
10
+ [build-url]: https://github.com/paolobrasolin/jekyll-antex/actions/workflows/main.yml "CI tests status"
11
+ [rubygems-shield]: https://img.shields.io/gem/v/jekyll-antex?logo=ruby
12
+ [rubygems-url]: https://rubygems.org/gems/jekyll-antex "Latest release"
13
+ [license-shield]: https://img.shields.io/github/license/paolobrasolin/jekyll-antex
14
+ [license-url]: https://github.com/paolobrasolin/jekyll-antex/blob/main/LICENSE "License"
15
+ [cc-maintainability-shield]: https://img.shields.io/codeclimate/maintainability/paolobrasolin/jekyll-antex?logo=codeclimate
16
+ [cc-maintainability-url]: https://codeclimate.com/github/paolobrasolin/jekyll-antex "Maintainability"
17
+ [cc-coverage-shield]: https://img.shields.io/codeclimate/coverage/paolobrasolin/jekyll-antex?logo=codeclimate&label=test%20coverage
18
+ [cc-coverage-url]: https://codeclimate.com/github/paolobrasolin/jekyll-antex/coverage "Test coverage"
@@ -7,7 +7,6 @@ module Jekyll
7
7
  class InvalidRegexp < Error; end
8
8
 
9
9
  Alias = Struct.new(:priority, :regexp, :options, keyword_init: true) do
10
-
11
10
  def initialize(*args)
12
11
  super
13
12
  validate_regexp!
@@ -17,6 +16,7 @@ module Jekyll
17
16
 
18
17
  def validate_regexp!
19
18
  return if regexp.names.include? 'code'
19
+
20
20
  raise InvalidRegexp, <<~MESSAGE
21
21
  The regexp #{regexp.inspect} is missing the required named matching group "code".
22
22
  MESSAGE
@@ -9,6 +9,10 @@ require 'jekyll/antex/options'
9
9
 
10
10
  module Jekyll
11
11
  module Antex
12
+ class << self
13
+ attr_accessor :jobs
14
+ end
15
+
12
16
  class Block < Liquid::Block
13
17
  def initialize(tag, markup, tokens)
14
18
  @markup = markup
@@ -18,54 +22,56 @@ module Jekyll
18
22
  def render(context)
19
23
  options = build_options registers: context.registers, markup: @markup
20
24
  job = ::Antex::Job.new snippet: super, options: options
21
- job.run!
25
+ Jekyll::Antex.jobs.store(job.hash, job)
22
26
  add_static_file context.registers[:site], job
23
- render_html job
27
+ self.class.render_html(job)
24
28
  end
25
29
 
26
- private
27
-
28
- def render_html(job)
29
- img_tag = render_img_tag src: img_url(job),
30
- set_box: job.set_box
30
+ def self.render_html(job)
31
+ img_tag = render_img_tag job
31
32
  classes = job.options['classes'].join(' ')
32
33
  "<span class='#{classes}'>#{img_tag}</span>"
33
34
  end
34
35
 
35
- def render_img_tag(src:, set_box:, precision: 3)
36
- <<~IMG_TAG.gsub(/(\s\s+)/m, ' ').strip!
37
- <img style='margin: #{set_box.mt.round(precision)}ex
38
- #{set_box.mr.round(precision)}ex
39
- #{set_box.mb.round(precision)}ex
40
- #{set_box.ml.round(precision)}ex;
41
- height: #{set_box.th.round(precision)}ex;
42
- width: #{set_box.wd.round(precision)}ex;'
43
- src='#{src}' />
44
- IMG_TAG
36
+ def self.render_img_tag(job)
37
+ "<img data-antex='#{job.hash}' src='#{img_url(job)}' />"
45
38
  end
46
39
 
47
- def add_static_file(site, job)
48
- site.static_files << Jekyll::StaticFile.new(
49
- site, *static_file_paths(job)
50
- )
40
+ def self.render_style_attribute(job_set_box, precision: 3)
41
+ <<~IMG_TAG.gsub(/(\s\s+)/m, ' ').strip!
42
+ style='margin: #{job_set_box.mt.round(precision)}ex
43
+ #{job_set_box.mr.round(precision)}ex
44
+ #{job_set_box.mb.round(precision)}ex
45
+ #{job_set_box.ml.round(precision)}ex;
46
+ height: #{job_set_box.th.round(precision)}ex;
47
+ width: #{job_set_box.wd.round(precision)}ex;'
48
+ IMG_TAG
51
49
  end
52
50
 
53
- def img_url(job)
51
+ def self.img_url(job)
54
52
  _, dest_dir, filename = static_file_paths job
55
53
  url_path_prefix = job.options['url_path_prefix'] || '/'
56
54
  File.join url_path_prefix, dest_dir, filename
57
55
  end
58
56
 
59
- def static_file_paths(job)
60
- work_dir_prefix = %r{^#{Regexp.escape job.dirs['work']}(?=\/|$)}
57
+ def self.static_file_paths(job)
58
+ work_dir_prefix = %r{^#{Regexp.escape job.dirs['work']}(?=/|$)}
61
59
  # base, dir, name
62
60
  [
63
61
  job.dirs['work'],
64
- job.dirs['dest'].sub(work_dir_prefix, '').sub(%r{^\/}, ''),
62
+ job.dirs['dest'].sub(work_dir_prefix, '').sub(%r{^/}, ''),
65
63
  File.basename(job.files['svg'])
66
64
  ]
67
65
  end
68
66
 
67
+ private
68
+
69
+ def add_static_file(site, job)
70
+ site.static_files << Jekyll::StaticFile.new(
71
+ site, *self.class.static_file_paths(job)
72
+ )
73
+ end
74
+
69
75
  def build_options(registers:, markup:)
70
76
  Jekyll::Antex::Options.build Jekyll::Antex::Options::DEFAULTS,
71
77
  registers[:site].config['antex'] || {},
@@ -75,5 +81,3 @@ module Jekyll
75
81
  end
76
82
  end
77
83
  end
78
-
79
- Liquid::Template.register_tag('antex', Jekyll::Antex::Block)
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/antex/alias'
4
+ require 'jekyll/antex/guard'
5
+ require 'jekyll/antex/stasher'
6
+ require 'jekyll/antex/options'
7
+
8
+ module Jekyll
9
+ module Antex
10
+ module Dealiaser
11
+ def self.run(resource)
12
+ options = build_options(resource)
13
+ guarder = build_guarder(options)
14
+ aliaser = build_aliaser(options)
15
+ content = aliaser.lift(guarder.lift(resource.content))
16
+ aliaser.bake(&method(:dealias_tag))
17
+ guarder.drop(aliaser.drop(content))
18
+ end
19
+
20
+ def self.build_options(resource)
21
+ Jekyll::Antex::Options.build(
22
+ Jekyll::Antex::Options::DEFAULTS,
23
+ resource.site.config['antex'] || {},
24
+ resource.data['antex'] || {}
25
+ )
26
+ end
27
+
28
+ def self.build_guarder(options)
29
+ Jekyll::Antex::Stasher.new(
30
+ options['guards'].values.reject { |value| value == false }.map(&Guard.method(:new))
31
+ )
32
+ end
33
+
34
+ def self.build_aliaser(options)
35
+ Jekyll::Antex::Stasher.new(
36
+ options['aliases'].values.reject { |value| value == false }.map(&Alias.method(:new))
37
+ )
38
+ end
39
+
40
+ def self.dealias_tag(match, matcher)
41
+ markup = YAML.safe_load match[:markup] if match.names.include?('markup')
42
+ markup = YAML.dump Options.build(matcher.options || {}, markup || {})
43
+ code = match['code']
44
+ "{% antex #{markup} %}#{code}{% endantex %}"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
- require 'jekyll/utils'
4
+ require 'jekyll'
5
5
 
6
6
  module Jekyll
7
7
  module Antex
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Antex
5
- VERSION = '0.4.0'
5
+ VERSION = '0.6.1'
6
6
  end
7
7
  end
data/lib/jekyll/antex.rb CHANGED
@@ -3,10 +3,57 @@
3
3
  require 'antex'
4
4
 
5
5
  require 'jekyll/antex/version'
6
- require 'jekyll/antex/error'
7
- require 'jekyll/antex/options'
8
- require 'jekyll/antex/guard'
9
- require 'jekyll/antex/stasher'
10
- require 'jekyll/antex/alias'
11
- require 'jekyll/antex/generator'
6
+ require 'jekyll/antex/dealiaser'
12
7
  require 'jekyll/antex/block'
8
+
9
+ module Jekyll
10
+ module Antex
11
+ def self.run_jobs
12
+ jekyll_antex_jobs = Jekyll::Antex.jobs
13
+ jobs_count = jekyll_antex_jobs.count
14
+ jekyll_logger_writer = Jekyll.logger.writer
15
+ jekyll_logger_writer << 'Compiling TeX: '.rjust(20)
16
+ jekyll_antex_jobs.values.each_with_index do |job, index|
17
+ run_job(job, index, jobs_count, jekyll_logger_writer)
18
+ end
19
+ jekyll_logger_writer << "#{jobs_count} jobs completed.\n"
20
+ end
21
+
22
+ def self.run_job(job, index, jobs_count, jekyll_logger_writer)
23
+ progress = "job #{index.next.to_s.rjust(jobs_count.to_s.length)} of #{jobs_count} "
24
+ jekyll_logger_writer << progress
25
+ job.run!
26
+ jekyll_logger_writer << ("\b" * progress.length)
27
+ end
28
+
29
+ def self.inject_style_attributes(output)
30
+ output.gsub(/data-antex="(?<hash>.*?)"/) do
31
+ job = Jekyll::Antex.jobs[Regexp.last_match[:hash]]
32
+ Jekyll::Antex::Block.render_style_attribute(job.set_box)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ # NOTE: I'm conflicted, but regexp flags in yaml must be easy to use.
39
+ SafeYAML::OPTIONS[:whitelisted_tags].push('!ruby/regexp')
40
+
41
+ Jekyll::Hooks.register :site, :pre_render do
42
+ Jekyll::Antex.jobs = {}
43
+ end
44
+
45
+ # NOTE: we're not registering :posts since they are included in :documents.
46
+ Jekyll::Hooks.register [:documents, :pages], :pre_render do |resource|
47
+ resource.content = Jekyll::Antex::Dealiaser.run(resource)
48
+ end
49
+
50
+ Liquid::Template.register_tag('antex', Jekyll::Antex::Block)
51
+
52
+ Jekyll::Hooks.register :site, :post_render do |site|
53
+ Jekyll::Antex.run_jobs
54
+ [*site.pages, *site.documents].each do |resource|
55
+ # NOTE: skip unrendered resources e.g. when using --incremental
56
+ next if resource.output.nil?
57
+ resource.output = Jekyll::Antex.inject_style_attributes(resource.output)
58
+ end
59
+ end
metadata CHANGED
@@ -1,155 +1,175 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-antex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Brasolin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-11 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jekyll
14
+ name: antex
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.8'
19
+ version: 0.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.8'
26
+ version: 0.1.3
27
27
  - !ruby/object:Gem::Dependency
28
- name: antex
28
+ name: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: kramdown-parser-gfm
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '0.1'
53
+ version: 1.1.0
34
54
  type: :runtime
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '0.1'
60
+ version: 1.1.0
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: byebug
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '10'
67
+ version: 11.1.3
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '10'
74
+ version: 11.1.3
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: guard
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '2'
81
+ version: 2.18.0
62
82
  type: :development
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: '2'
88
+ version: 2.18.0
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: guard-rspec
71
91
  requirement: !ruby/object:Gem::Requirement
72
92
  requirements:
73
93
  - - "~>"
74
94
  - !ruby/object:Gem::Version
75
- version: '4'
95
+ version: 4.7.3
76
96
  type: :development
77
97
  prerelease: false
78
98
  version_requirements: !ruby/object:Gem::Requirement
79
99
  requirements:
80
100
  - - "~>"
81
101
  - !ruby/object:Gem::Version
82
- version: '4'
102
+ version: 4.7.3
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: reek
85
105
  requirement: !ruby/object:Gem::Requirement
86
106
  requirements:
87
107
  - - "~>"
88
108
  - !ruby/object:Gem::Version
89
- version: '4'
109
+ version: 6.0.6
90
110
  type: :development
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
- version: '4'
116
+ version: 6.0.6
97
117
  - !ruby/object:Gem::Dependency
98
118
  name: rspec
99
119
  requirement: !ruby/object:Gem::Requirement
100
120
  requirements:
101
121
  - - "~>"
102
122
  - !ruby/object:Gem::Version
103
- version: '3'
123
+ version: 3.10.0
104
124
  type: :development
105
125
  prerelease: false
106
126
  version_requirements: !ruby/object:Gem::Requirement
107
127
  requirements:
108
128
  - - "~>"
109
129
  - !ruby/object:Gem::Version
110
- version: '3'
130
+ version: 3.10.0
111
131
  - !ruby/object:Gem::Dependency
112
132
  name: rubocop
113
133
  requirement: !ruby/object:Gem::Requirement
114
134
  requirements:
115
135
  - - "~>"
116
136
  - !ruby/object:Gem::Version
117
- version: '0.52'
137
+ version: 1.22.3
118
138
  type: :development
119
139
  prerelease: false
120
140
  version_requirements: !ruby/object:Gem::Requirement
121
141
  requirements:
122
142
  - - "~>"
123
143
  - !ruby/object:Gem::Version
124
- version: '0.52'
144
+ version: 1.22.3
125
145
  - !ruby/object:Gem::Dependency
126
146
  name: simplecov
127
147
  requirement: !ruby/object:Gem::Requirement
128
148
  requirements:
129
149
  - - "~>"
130
150
  - !ruby/object:Gem::Version
131
- version: '0.16'
151
+ version: 0.21.2
132
152
  type: :development
133
153
  prerelease: false
134
154
  version_requirements: !ruby/object:Gem::Requirement
135
155
  requirements:
136
156
  - - "~>"
137
157
  - !ruby/object:Gem::Version
138
- version: '0.16'
158
+ version: 0.21.2
139
159
  - !ruby/object:Gem::Dependency
140
160
  name: yard
141
161
  requirement: !ruby/object:Gem::Requirement
142
162
  requirements:
143
163
  - - "~>"
144
164
  - !ruby/object:Gem::Version
145
- version: '0.9'
165
+ version: 0.9.26
146
166
  type: :development
147
167
  prerelease: false
148
168
  version_requirements: !ruby/object:Gem::Requirement
149
169
  requirements:
150
170
  - - "~>"
151
171
  - !ruby/object:Gem::Version
152
- version: '0.9'
172
+ version: 0.9.26
153
173
  description: 'Jekyll-anTeX implements universal TeX support in Jekyll to embed and
154
174
  render arbitrary code using any engine and dialect. '
155
175
  email: paolo.brasolin@gmail.com
@@ -157,14 +177,13 @@ executables: []
157
177
  extensions: []
158
178
  extra_rdoc_files: []
159
179
  files:
160
- - LICENSE.txt
161
180
  - README.md
162
181
  - lib/jekyll/antex.rb
163
182
  - lib/jekyll/antex/alias.rb
164
183
  - lib/jekyll/antex/block.rb
184
+ - lib/jekyll/antex/dealiaser.rb
165
185
  - lib/jekyll/antex/defaults.yml
166
186
  - lib/jekyll/antex/error.rb
167
- - lib/jekyll/antex/generator.rb
168
187
  - lib/jekyll/antex/guard.rb
169
188
  - lib/jekyll/antex/options.rb
170
189
  - lib/jekyll/antex/stasher.rb
@@ -173,7 +192,7 @@ homepage: https://github.com/paolobrasolin/antex
173
192
  licenses:
174
193
  - MIT
175
194
  metadata: {}
176
- post_install_message:
195
+ post_install_message:
177
196
  rdoc_options: []
178
197
  require_paths:
179
198
  - lib
@@ -181,16 +200,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
200
  requirements:
182
201
  - - ">="
183
202
  - !ruby/object:Gem::Version
184
- version: '2.5'
203
+ version: '2.6'
185
204
  required_rubygems_version: !ruby/object:Gem::Requirement
186
205
  requirements:
187
206
  - - ">="
188
207
  - !ruby/object:Gem::Version
189
208
  version: '0'
190
209
  requirements: []
191
- rubyforge_project:
192
- rubygems_version: 2.7.6
193
- signing_key:
210
+ rubygems_version: 3.1.4
211
+ signing_key:
194
212
  specification_version: 4
195
213
  summary: Universal TeX integration for Jekyll
196
214
  test_files: []
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 Paolo Brasolin
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'jekyll'
4
- require 'jekyll/utils'
5
-
6
- require 'jekyll/antex/alias'
7
- require 'jekyll/antex/guard'
8
- require 'jekyll/antex/stasher'
9
- require 'jekyll/antex/options'
10
-
11
- # NOTE: I'm pretty conflicted about this.
12
- SafeYAML::OPTIONS[:whitelisted_tags].push('!ruby/regexp')
13
-
14
- module Jekyll
15
- module Antex
16
- class Generator < Jekyll::Generator
17
- def generate(site)
18
- site.pages.each do |page|
19
- dealias_resource_content! site: site, resource: page
20
- end
21
-
22
- # NOTE: jekyll deprecated direct access to site.posts.each
23
- site.posts.docs.each do |post|
24
- dealias_resource_content! site: site, resource: post
25
- end
26
- end
27
-
28
- private
29
-
30
- def dealias_resource_content!(site:, resource:)
31
- options = build_options site: site, resource: resource
32
- guardian = Jekyll::Antex::Stasher.new(build_guards(options['guards']))
33
- dealiaser = Jekyll::Antex::Stasher.new(build_aliases(options['aliases']))
34
- resource.content = guardian.lift(resource.content)
35
- resource.content = dealiaser.lift(resource.content)
36
- dealiaser.bake(&self.class.method(:dealias_tag))
37
- resource.content = dealiaser.drop(resource.content)
38
- resource.content = guardian.drop(resource.content)
39
- end
40
-
41
- def build_options(site:, resource:)
42
- Jekyll::Antex::Options.build Jekyll::Antex::Options::DEFAULTS,
43
- site.config['antex'] || {},
44
- resource.data['antex'] || {}
45
- end
46
-
47
- def build_guards(options_hash)
48
- options_hash.values.map do |args|
49
- Guard.new Jekyll::Utils.symbolize_hash_keys(args)
50
- end
51
- end
52
-
53
- def build_aliases(options_hash)
54
- options_hash.values.map do |args|
55
- Alias.new Jekyll::Utils.symbolize_hash_keys(args)
56
- end
57
- end
58
-
59
- def self.dealias_tag(match, matcher)
60
- markup = YAML.safe_load match[:markup] if match.names.include?('markup')
61
- markup = YAML.dump Options.build(matcher.options || {}, markup || {})
62
- code = match['code']
63
- "{% antex #{markup} %}#{code}{% endantex %}"
64
- end
65
- end
66
- end
67
- end