jekyll-antex 0.7.0 → 0.8.0
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 +53 -11
- data/lib/jekyll/antex/defaults.yml +1 -0
- data/lib/jekyll/antex/version.rb +1 -1
- data/lib/jekyll/antex.rb +2 -8
- 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: 38cc80b080df5998a00550b7046fa6518e8842d4b225abe15ff21c39ced1290b
|
4
|
+
data.tar.gz: 064c607a0b8d825356b22fb6f6837526fd536ca64b13bfa0dc9cb054e9f945bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '082e533cae85f3ec1ac9f8db5a1d80cf0f1574b876e6e37cf5e874a1ab7787e1aa606af2979e170818743391d4e06e8c05486947d0426b70970da43c48463dc1'
|
7
|
+
data.tar.gz: '08e6bdd8202cf293cfe4b93cdcdfc8103464559196b1362d1b76f9f5e5f073194effa619085f9913ca366bad1eff24573dd5b9be4ea43c20aaa54fc44eaaca48'
|
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,62 @@ 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
|
+
svg.remove_attribute('width')
|
71
|
+
svg.remove_attribute('height')
|
72
|
+
svg.set_attribute('style', style)
|
73
|
+
placeholder.add_next_sibling(svg)
|
74
|
+
placeholder.remove()
|
34
75
|
end
|
35
76
|
|
36
|
-
def self.
|
37
|
-
"<
|
77
|
+
def self.render_placeholder_tag(job)
|
78
|
+
"<object #{HASH_ATTR_NAME}='#{job.hash}'></object>"
|
38
79
|
end
|
39
80
|
|
40
|
-
def self.
|
81
|
+
def self.render_style_attribute_value(job_set_box, precision: 3)
|
41
82
|
<<~IMG_TAG.gsub(/(\s\s+)/m, ' ').strip!
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
83
|
+
margin: #{job_set_box.mt.round(precision)}ex
|
84
|
+
#{job_set_box.mr.round(precision)}ex
|
85
|
+
#{job_set_box.mb.round(precision)}ex
|
86
|
+
#{job_set_box.ml.round(precision)}ex;
|
87
|
+
height: #{job_set_box.th.round(precision)}ex;
|
88
|
+
width: #{job_set_box.wd.round(precision)}ex;
|
48
89
|
IMG_TAG
|
49
90
|
end
|
50
91
|
|
@@ -67,6 +108,7 @@ module Jekyll
|
|
67
108
|
private
|
68
109
|
|
69
110
|
def add_static_file(site, job)
|
111
|
+
return if job.options['inlining']
|
70
112
|
site.static_files << Jekyll::StaticFile.new(
|
71
113
|
site, *self.class.static_file_paths(job)
|
72
114
|
)
|
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'
|
@@ -36,13 +37,6 @@ module Jekyll
|
|
36
37
|
job.run!
|
37
38
|
jekyll_logger_writer << ("\b" * progress.length)
|
38
39
|
end
|
39
|
-
|
40
|
-
def self.inject_style_attributes(output)
|
41
|
-
output.gsub(/data-antex="(?<hash>.*?)"/) do
|
42
|
-
job = Jekyll::Antex.jobs[Regexp.last_match[:hash]]
|
43
|
-
Jekyll::Antex::Block.render_style_attribute(job.set_box)
|
44
|
-
end
|
45
|
-
end
|
46
40
|
end
|
47
41
|
end
|
48
42
|
|
@@ -63,6 +57,6 @@ Jekyll::Hooks.register :site, :post_render do |site|
|
|
63
57
|
Jekyll::Antex.gather_resources(site).each do |resource|
|
64
58
|
# NOTE: skip unrendered resources e.g. when using --incremental
|
65
59
|
next if resource.output.nil?
|
66
|
-
resource.output = Jekyll::Antex.
|
60
|
+
resource.output = Jekyll::Antex::Block.replace_placeholders(resource.output)
|
67
61
|
end
|
68
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.0
|
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-25 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: []
|