al_math 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6100b2d816b9358fc08c305fe44ebf08176a6fb3d374fcc9ecff853232039fbf
4
+ data.tar.gz: 8ee3574df9a8aa2c1bb7b05376c75c4ca9988cef8c57e287cacfb3780e0d4d2a
5
+ SHA512:
6
+ metadata.gz: de57b560084e6098a0ddbbb67c12c7723d14a6641af54c5edb5d1582406928d7771e0415f410517f3527591e49b617366cfd9efa5ca1e90925e5e8a789a13a2d
7
+ data.tar.gz: 3277f6587721a9c9802ff5bf86139b379f85901af96c3d6be87501ac3a73b4346c435eccb0d74760c75a04e3385cff792565037270fe090d1b8d7394c80eccb7
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-02-07
4
+ - Initial gem release.
5
+ - Added standalone math script/style tags and assets (MathJax, pseudocode, TikZJax).
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Maruan Al-Shedivat.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Al-Math
2
+
3
+ A Jekyll plugin that provides math-related assets and script loading.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'al_math'
9
+ ```
10
+
11
+ Enable in `_config.yml`:
12
+
13
+ ```yaml
14
+ plugins:
15
+ - al_math
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```liquid
21
+ {% al_math_styles %}
22
+ {% al_math_scripts %}
23
+ ```
data/lib/al_math.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'jekyll'
2
+
3
+ module AlMath
4
+ PLUGIN_NAME = 'al_math'
5
+ ASSETS_DIR = 'assets'
6
+
7
+ class PluginStaticFile < Jekyll::StaticFile; end
8
+
9
+ class AssetsGenerator < Jekyll::Generator
10
+ safe true
11
+ priority :low
12
+
13
+ def generate(site)
14
+ plugin_lib_path = File.expand_path('.', __dir__)
15
+ Dir.glob(File.join(plugin_lib_path, ASSETS_DIR, PLUGIN_NAME, '**', '*')).each do |source_path|
16
+ next if File.directory?(source_path)
17
+
18
+ relative_dir = File.dirname(source_path).sub("#{plugin_lib_path}/", '')
19
+ site.static_files << PluginStaticFile.new(site, plugin_lib_path, relative_dir, File.basename(source_path))
20
+ end
21
+ end
22
+ end
23
+
24
+ class MathStylesTag < Liquid::Tag
25
+ def render(context)
26
+ site = context.registers[:site]
27
+ page = context.registers[:page] || context['page'] || {}
28
+ return '' unless site
29
+ return '' unless truthy?(page['tikzjax'])
30
+
31
+ baseurl = site.config['baseurl'] || ''
32
+ %(<link defer rel="stylesheet" type="text/css" href="#{baseurl}/assets/al_math/css/tikzjax.min.css">)
33
+ end
34
+
35
+ private
36
+
37
+ def truthy?(value)
38
+ value == true || value.to_s == 'true'
39
+ end
40
+ end
41
+
42
+ class MathScriptsTag < Liquid::Tag
43
+ def render(context)
44
+ site = context.registers[:site]
45
+ page = context.registers[:page] || context['page'] || {}
46
+ return '' unless site
47
+
48
+ cfg = site.config
49
+ libs = cfg['third_party_libraries'] || {}
50
+ baseurl = cfg['baseurl'] || ''
51
+ out = []
52
+
53
+ if truthy?(cfg['enable_math'])
54
+ out << %(<script defer type="text/javascript" id="MathJax-script" src="#{libs.dig('mathjax', 'url', 'js')}" integrity="#{libs.dig('mathjax', 'integrity', 'js')}" crossorigin="anonymous"></script>)
55
+ if truthy?(page['pseudocode'])
56
+ out << %(<script src="#{baseurl}/assets/al_math/js/pseudocode-setup.js"></script>)
57
+ out << %(<script type="text/javascript" src="#{libs.dig('pseudocode', 'url', 'js')}" integrity="#{libs.dig('pseudocode', 'integrity', 'js')}" crossorigin="anonymous"></script>)
58
+ else
59
+ out << %(<script src="#{baseurl}/assets/al_math/js/mathjax-setup.js"></script>)
60
+ out << %(<script defer src="#{libs.dig('polyfill', 'url', 'js')}" crossorigin="anonymous"></script>)
61
+ end
62
+ end
63
+
64
+ if truthy?(page['tikzjax'])
65
+ out << %(<script defer src="#{baseurl}/assets/al_math/js/tikzjax.min.js" type="text/javascript"></script>)
66
+ end
67
+
68
+ out.join("\n")
69
+ end
70
+
71
+ private
72
+
73
+ def truthy?(value)
74
+ value == true || value.to_s == 'true'
75
+ end
76
+ end
77
+ end
78
+
79
+ Liquid::Template.register_tag('al_math_styles', AlMath::MathStylesTag)
80
+ Liquid::Template.register_tag('al_math_scripts', AlMath::MathScriptsTag)