jekyll-antex 0.6.1 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/antex/block.rb +64 -11
- data/lib/jekyll/antex/defaults.yml +1 -0
- data/lib/jekyll/antex/version.rb +1 -1
- data/lib/jekyll/antex.rb +17 -14
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b5addd8c7dd7101a0e9c741f1841a84c7073c742c7b4f2edbb0817b5a38d76b
|
4
|
+
data.tar.gz: bc9649c9722b99f7785a69ca95555be020876ab488c71778b33d15469c2fb3f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9c47f9570936bffe9f87f6fb26c6944b84f9c8edacecc8e8a43b431fc4f42620f318c188c279cb5eace24d71a65a34f302b54bc2ae14d508ce737b2112570ac
|
7
|
+
data.tar.gz: 4718eae474054f548305faa64f60f47b7df9e7b5bff3eaa3097a5f666df6680ee512b5e3acf690a4104cbc75009279e3fd468be3d99344dfc1e475b909a5bb81
|
data/lib/jekyll/antex/block.rb
CHANGED
@@ -14,6 +14,8 @@ module Jekyll
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Block < Liquid::Block
|
17
|
+
HASH_ATTR_NAME = 'data-antex-job-hash'
|
18
|
+
|
17
19
|
def initialize(tag, markup, tokens)
|
18
20
|
@markup = markup
|
19
21
|
super
|
@@ -28,23 +30,73 @@ module Jekyll
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def self.render_html(job)
|
31
|
-
|
33
|
+
placeholder_tag = render_placeholder_tag job
|
32
34
|
classes = job.options['classes'].join(' ')
|
33
|
-
"<span class='#{classes}'>#{
|
35
|
+
"<span class='#{classes}'>#{placeholder_tag}</span>"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.replace_placeholders(content)
|
39
|
+
doc = Nokogiri::HTML.parse(content)
|
40
|
+
placeholders = doc.xpath("//object[@#{HASH_ATTR_NAME}]")
|
41
|
+
placeholders.each(&method(:replace_placeholder))
|
42
|
+
doc.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.replace_placeholder(placeholder)
|
46
|
+
job = Jekyll::Antex.jobs[placeholder[HASH_ATTR_NAME]]
|
47
|
+
if job.options['inlining']
|
48
|
+
replace_placeholder_with_svg(placeholder)
|
49
|
+
else
|
50
|
+
replace_placeholder_with_img(placeholder)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.replace_placeholder_with_img(placeholder)
|
55
|
+
job = Jekyll::Antex.jobs[placeholder[HASH_ATTR_NAME]]
|
56
|
+
style = render_style_attribute_value(job.set_box)
|
57
|
+
img = Nokogiri::XML::Node.new('img', placeholder.document)
|
58
|
+
src = Jekyll::Antex::Block.img_url(job)
|
59
|
+
img.set_attribute('src', src)
|
60
|
+
img.set_attribute('style', style)
|
61
|
+
placeholder.add_next_sibling(img)
|
62
|
+
placeholder.remove()
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.replace_placeholder_with_svg(placeholder)
|
66
|
+
job = Jekyll::Antex.jobs[placeholder[HASH_ATTR_NAME]]
|
67
|
+
style = render_style_attribute_value(job.set_box)
|
68
|
+
path = File.read(job.files['svg'])
|
69
|
+
svg = Nokogiri::XML(path).at_css('svg')
|
70
|
+
prefix_svg_symbols_ids(svg, placeholder[HASH_ATTR_NAME])
|
71
|
+
svg.remove_attribute('width')
|
72
|
+
svg.remove_attribute('height')
|
73
|
+
svg.set_attribute('style', style)
|
74
|
+
placeholder.add_next_sibling(svg)
|
75
|
+
placeholder.remove()
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.prefix_svg_symbols_ids(doc, pfx)
|
79
|
+
# NOTE: in theory String#insert is destructive but node attribute getter/setters must be doing something weird...
|
80
|
+
doc.css("defs > [id]").each do |node|
|
81
|
+
node[:id] = node[:id].insert(0, pfx + "-")
|
82
|
+
end
|
83
|
+
doc.css("use").each do |node|
|
84
|
+
node[:"xlink:href"] = node[:"xlink:href"].insert(1, pfx + "-")
|
85
|
+
end
|
34
86
|
end
|
35
87
|
|
36
|
-
def self.
|
37
|
-
"<
|
88
|
+
def self.render_placeholder_tag(job)
|
89
|
+
"<object #{HASH_ATTR_NAME}='#{job.hash}'></object>"
|
38
90
|
end
|
39
91
|
|
40
|
-
def self.
|
92
|
+
def self.render_style_attribute_value(job_set_box, precision: 3)
|
41
93
|
<<~IMG_TAG.gsub(/(\s\s+)/m, ' ').strip!
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
94
|
+
margin: #{job_set_box.mt.round(precision)}ex
|
95
|
+
#{job_set_box.mr.round(precision)}ex
|
96
|
+
#{job_set_box.mb.round(precision)}ex
|
97
|
+
#{job_set_box.ml.round(precision)}ex;
|
98
|
+
height: #{job_set_box.th.round(precision)}ex;
|
99
|
+
width: #{job_set_box.wd.round(precision)}ex;
|
48
100
|
IMG_TAG
|
49
101
|
end
|
50
102
|
|
@@ -67,6 +119,7 @@ module Jekyll
|
|
67
119
|
private
|
68
120
|
|
69
121
|
def add_static_file(site, job)
|
122
|
+
return if job.options['inlining']
|
70
123
|
site.static_files << Jekyll::StaticFile.new(
|
71
124
|
site, *self.class.static_file_paths(job)
|
72
125
|
)
|
data/lib/jekyll/antex/version.rb
CHANGED
data/lib/jekyll/antex.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'antex'
|
4
|
+
require 'nokogiri'
|
4
5
|
|
5
6
|
require 'jekyll/antex/version'
|
6
7
|
require 'jekyll/antex/dealiaser'
|
@@ -8,6 +9,17 @@ require 'jekyll/antex/block'
|
|
8
9
|
|
9
10
|
module Jekyll
|
10
11
|
module Antex
|
12
|
+
def self.gather_resources(site)
|
13
|
+
pages = site.pages
|
14
|
+
documents = site.collections.values.flat_map(&:docs)
|
15
|
+
[*pages, *documents].filter(&method(:allowed_resource?))
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.allowed_resource?(resource)
|
19
|
+
# TODO: perhaps this should be configurable
|
20
|
+
File.fnmatch('*.{html,md}', resource.relative_path, File::FNM_EXTGLOB)
|
21
|
+
end
|
22
|
+
|
11
23
|
def self.run_jobs
|
12
24
|
jekyll_antex_jobs = Jekyll::Antex.jobs
|
13
25
|
jobs_count = jekyll_antex_jobs.count
|
@@ -25,35 +37,26 @@ module Jekyll
|
|
25
37
|
job.run!
|
26
38
|
jekyll_logger_writer << ("\b" * progress.length)
|
27
39
|
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
40
|
end
|
36
41
|
end
|
37
42
|
|
38
43
|
# NOTE: I'm conflicted, but regexp flags in yaml must be easy to use.
|
39
44
|
SafeYAML::OPTIONS[:whitelisted_tags].push('!ruby/regexp')
|
40
45
|
|
41
|
-
Jekyll::Hooks.register :site, :pre_render do
|
46
|
+
Jekyll::Hooks.register :site, :pre_render do |site|
|
42
47
|
Jekyll::Antex.jobs = {}
|
43
|
-
|
44
|
-
|
45
|
-
# NOTE: we're not registering :posts since they are included in :documents.
|
46
|
-
Jekyll::Hooks.register [:documents, :pages], :pre_render do |resource|
|
48
|
+
Jekyll::Antex.gather_resources(site).each do |resource|
|
47
49
|
resource.content = Jekyll::Antex::Dealiaser.run(resource)
|
50
|
+
end
|
48
51
|
end
|
49
52
|
|
50
53
|
Liquid::Template.register_tag('antex', Jekyll::Antex::Block)
|
51
54
|
|
52
55
|
Jekyll::Hooks.register :site, :post_render do |site|
|
53
56
|
Jekyll::Antex.run_jobs
|
54
|
-
|
57
|
+
Jekyll::Antex.gather_resources(site).each do |resource|
|
55
58
|
# NOTE: skip unrendered resources e.g. when using --incremental
|
56
59
|
next if resource.output.nil?
|
57
|
-
resource.output = Jekyll::Antex.
|
60
|
+
resource.output = Jekyll::Antex::Block.replace_placeholders(resource.output)
|
58
61
|
end
|
59
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-antex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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: 2022-
|
11
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: antex
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 1.1.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: nokogiri
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: byebug
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +206,7 @@ homepage: https://github.com/paolobrasolin/antex
|
|
192
206
|
licenses:
|
193
207
|
- MIT
|
194
208
|
metadata: {}
|
195
|
-
post_install_message:
|
209
|
+
post_install_message:
|
196
210
|
rdoc_options: []
|
197
211
|
require_paths:
|
198
212
|
- lib
|
@@ -207,8 +221,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
221
|
- !ruby/object:Gem::Version
|
208
222
|
version: '0'
|
209
223
|
requirements: []
|
210
|
-
rubygems_version: 3.
|
211
|
-
signing_key:
|
224
|
+
rubygems_version: 3.2.3
|
225
|
+
signing_key:
|
212
226
|
specification_version: 4
|
213
227
|
summary: Universal TeX integration for Jekyll
|
214
228
|
test_files: []
|