weaver 0.9.9 → 0.9.11

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: f1fd8409e68051036b8d1f4744ab44b7370d22b8f407b504144587f63af10a20
4
- data.tar.gz: ac79870b5e8ef48d98d3e0d901c6c87719ac6096070e219d5ca3207fb3d45bb2
3
+ metadata.gz: e9783796e6634d6bcf752a441dfa26bc5e4cd268b48fe0de848f8ec8e5f94b90
4
+ data.tar.gz: 0cd59698543c171bf7471415470be4f386f34bf787949434b0ead02e6ea7e3c9
5
5
  SHA512:
6
- metadata.gz: 8810e33d65bf2e81ff11ca83a48217952c7b275da326bbf4791c7416605fdf45ff6428b55816ebd9b0b4a1733f614479c07d79a281ca2f35d0c562f5263467c8
7
- data.tar.gz: b0427c0bc90823f6d57c8fa26f5d4ab19c5f314a13fe082e8c50284452e18cf748b014ab54b154d1b23991749b90526dd87e4615512a39e0348af3e35adc4288
6
+ metadata.gz: 9f6a9d060ad3483eb92cb25eecb30d2f732c87581b808483d1535e88c20212c49a6775c9cc23af7479e08d082f557d2585411d3af732c06f33c615f5d86b2430
7
+ data.tar.gz: 9d69cce3eb98324d257dd8d69eb66b878a6c529a2cf6f553f774dbd08d62368f3003d74edbbf5525a7dc5b247129e7b4ab6f7ba038a2c3f1f491d1373ddc9b2a
data/exe/weaver CHANGED
@@ -11,6 +11,15 @@ class Website < Sinatra::Base
11
11
  set :bind, '0.0.0.0'
12
12
  set :port, ENV['PORT'] || 4567
13
13
  set :host_authorization, { permitted_hosts: [] }
14
+ mime_type :webmanifest, 'application/manifest+json'
15
+
16
+ # Files in the project's root/ directory are served at the top of the site (and
17
+ # `weaver build` copies them there): favicons, robots.txt, CNAME, service workers...
18
+ def root_file(path)
19
+ root = File.expand_path('root')
20
+ file = File.expand_path(path, root)
21
+ file if file.start_with?("#{root}/") && File.file?(file)
22
+ end
14
23
 
15
24
  def getWeavefile(viewname)
16
25
  pathToFile = viewname.split('/').delete_if(&:empty?)
@@ -40,6 +49,10 @@ class Website < Sinatra::Base
40
49
  end
41
50
 
42
51
  get '/*' do
52
+ if (file = root_file(params[:splat].first))
53
+ return send_file(file, disposition: 'inline')
54
+ end
55
+
43
56
  if params[:splat].first.start_with? 'images/'
44
57
  return send_file(params[:splat].first, disposition: 'inline')
45
58
  end
@@ -102,6 +115,7 @@ def build!(_args)
102
115
  FileUtils.rm_rf buildDir
103
116
  FileUtils.cp_r(File.join(Gem.loaded_specs['weaver'].full_gem_path, 'data', 'weaver'), buildDir, preserve: preserve)
104
117
  FileUtils.cp_r('images', buildDir, preserve: preserve) if Dir.exist? 'images'
118
+ FileUtils.cp_r('root/.', buildDir, preserve: preserve) if Dir.exist? 'root'
105
119
  if Dir.exist? 'js'
106
120
  Dir['js/**/*.*'].each do |x|
107
121
  FileUtils.mkdir_p File.dirname(File.join(buildDir, x))
@@ -99,6 +99,29 @@ module Weaver
99
99
  @top_content = elem.generate
100
100
  end
101
101
 
102
+ MATH_MARKER = '$$$MATH$$$'
103
+
104
+ # MathJax is large and keeps fetching files as it runs, so only pages that
105
+ # actually contain math (see Elements#math) load it
106
+ def uses_math?
107
+ [@content, @top_content, @background.generate].any? { |html| html.to_s.include?(MATH_MARKER) }
108
+ end
109
+
110
+ def mathjax_scripts(mod)
111
+ return '' unless uses_math?
112
+
113
+ <<~MATHJAX
114
+ <script type="text/x-mathjax-config">
115
+ MathJax.Hub.Config({
116
+ asciimath2jax: {
117
+ delimiters: [['#{MATH_MARKER}','$$$ENDMATH$$$']]
118
+ }
119
+ });
120
+ </script>
121
+ <script src="#{mod}js/MathJax/MathJax.js?config=AM_HTMLorMML-full" async></script>
122
+ MATHJAX
123
+ end
124
+
102
125
  def generate_meta_tags
103
126
  content = ""
104
127
  @meta_tags.each do |x|
@@ -241,15 +264,7 @@ mixpanel.init("' + @global_settings[:mixpanel_token] + '");</script><!-- end Mix
241
264
  <script src="#{mod}js/bootstrap.min.js"></script>
242
265
  <script src="#{mod}js/plugins/metisMenu/jquery.metisMenu.js"></script>
243
266
  <script src="#{mod}js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
244
- <script type="text/x-mathjax-config">
245
- MathJax.Hub.Config({
246
- asciimath2jax: {
247
- delimiters: [['$$$MATH$$$','$$$ENDMATH$$$']]
248
- }
249
- });
250
- </script>
251
- <script src="#{mod}js/MathJax/MathJax.js?config=AM_HTMLorMML-full" async></script>
252
-
267
+ #{mathjax_scripts(mod)}
253
268
  #{extra_scripts}
254
269
 
255
270
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaver
4
- VERSION = '0.9.9'
4
+ VERSION = '0.9.11'
5
5
  end
data/spec/page_spec.rb CHANGED
@@ -15,4 +15,27 @@ describe Weaver::Page do
15
15
  it 'does not emit the non-standard contents attribute' do
16
16
  expect(html).not_to include('contents=')
17
17
  end
18
+
19
+ describe 'MathJax' do
20
+ def page_html(&block)
21
+ Weaver::EmptyPage.new('Title', { root: '/' }, {}, &block).generate(0)
22
+ end
23
+
24
+ it 'is left out of pages without math' do
25
+ html = page_html { p 'no maths here' }
26
+ expect(html).not_to include('MathJax')
27
+ end
28
+
29
+ it 'is loaded on pages that use math' do
30
+ html = page_html { math 'x^2 + y^2' }
31
+ expect(html).to include('$$$MATH$$$x^2 + y^2$$$ENDMATH$$$')
32
+ expect(html).to include('<script type="text/x-mathjax-config">')
33
+ expect(html).to include('js/MathJax/MathJax.js?config=AM_HTMLorMML-full')
34
+ end
35
+
36
+ it 'is loaded when math sits in a nested element' do
37
+ html = page_html { div { span { math '\\frac{1}{2}' } } }
38
+ expect(html).to include('js/MathJax/MathJax.js')
39
+ end
40
+ end
18
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Siaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-16 00:00:00.000000000 Z
11
+ date: 2026-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport