jekyll-euclid 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: 743add07e4ef9648d4b86ee1ad3a4a4878d1cf2f72b268c316cc36d523a9eefe
4
+ data.tar.gz: 67d1cc710682a731d44f9a6d5a9f7cfeb46a9b0af00bda434c873df7f11cf471
5
+ SHA512:
6
+ metadata.gz: 198f52f27b9e9d46df571a923fc5db49e92c0c003fcf2f5cb379fb09ccd8c2eda4c850df2f3e5ecad2031657f8cb69a5ee5b8a4bea66acc958c87af2b6215c11
7
+ data.tar.gz: 9c438ee3d1a503c88da8e45bd3ed60188e7906faeaffc16b1ccd4050f1e620ea192ec2e544b3633d07ba6e761d8044829cf82cf8197598630741568fcacf677c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-09-27
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Guilherme
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Jekyll::Euclid
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jekyll/euclid`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-euclid.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,148 @@
1
+ module Jekyll
2
+ module Converters
3
+ class EuclidConverter < Converter
4
+ safe true
5
+ priority :highest
6
+
7
+ def matches(ext)
8
+ ext =~ /^\.euclid$/i
9
+ end
10
+
11
+ def output_ext(ext)
12
+ ".html"
13
+ end
14
+
15
+ def replace_theorem(content)
16
+ @theorem_counter += 1
17
+
18
+ "**Theorem #{@theorem_counter}:** *#{content[8..-6].strip}*"
19
+ end
20
+
21
+ def replace_lemma(content)
22
+ @theorem_counter += 1
23
+
24
+ "**Lemma #{@theorem_counter}:** *#{content[6..-6].strip}*"
25
+ end
26
+
27
+ def replace_corollary(content)
28
+ @corollary_counter += 1
29
+
30
+ "**Corollary #{@theorem_counter}.#{@corollary_counter}:** *#{content[10..-6].strip}*"
31
+ end
32
+
33
+ def replace_axiom(content)
34
+ @axiom_counter += 1
35
+
36
+ "**Axiom #{@axiom_counter}:** *#{content[6..-6].strip}*"
37
+ end
38
+
39
+ def replace_definition(content)
40
+ @definition_counter += 1
41
+
42
+ "**Definition #{@definition_counter}:** *#{content[11..-6].strip}*"
43
+ end
44
+
45
+ def replace_proof(content)
46
+ "*Proof.* #{content[7..-6]}"
47
+ end
48
+
49
+ def get_term_index(content)
50
+ theorem_index = content.index("\\theorem") || 999999
51
+ lemma_index = content.index("\\lemma") || 999999
52
+ corollary_index = content.index("\\corollary") || 999999
53
+
54
+ if theorem_index < lemma_index && theorem_index < corollary_index
55
+ return theorem_index, "\\theorem"
56
+ elsif lemma_index < corollary_index
57
+ return lemma_index, "\\lemma"
58
+ elsif corollary_index < 999999
59
+ return corollary_index, "\\corollary"
60
+ end
61
+
62
+ return -1, nil
63
+ end
64
+
65
+ def replace_theorem_terms(content, term)
66
+ case term
67
+ when "\\theorem"
68
+ replace_theorem(content)
69
+ when "\\lemma"
70
+ replace_lemma(content)
71
+ when "\\corollary"
72
+ replace_corollary(content)
73
+ end
74
+ end
75
+
76
+ def replace_theorems(content)
77
+ @theorem_counter = 0
78
+
79
+ term_index, term = get_term_index(content)
80
+
81
+ if term != "\\corollary"
82
+ @corollary_counter = 0
83
+ end
84
+
85
+ end_index = content[term_index..-1].index("\\end") + term_index
86
+
87
+ while term_index > 0
88
+ term_content = content[term_index..(end_index + 3)]
89
+ content = content[0..(term_index - 1)] + replace_theorem_terms(term_content, term) + content[(end_index + 4)..-1]
90
+
91
+ term_index, term = get_term_index(content)
92
+
93
+ if term_index == -1
94
+ break
95
+ end
96
+
97
+ end_index = content[term_index..-1].index("\\end") + term_index
98
+ end
99
+
100
+ content
101
+ end
102
+
103
+ def replace_term(term, content, replace_method)
104
+ term_index = content.index(term)
105
+ end_index = content[term_index..-1].index("\\end") + term_index
106
+
107
+ while term_index > 0
108
+ term_content = content[term_index..(end_index + 3)]
109
+ content = content[0..(term_index - 1)] + replace_method.call(term_content) + content[(end_index + 4)..-1]
110
+ term_index = content.index(term)
111
+
112
+ if term_index.nil?
113
+ break
114
+ end
115
+
116
+ end_index = content[term_index..-1].index("\\end") + term_index
117
+
118
+ end
119
+
120
+ content
121
+ end
122
+
123
+ def replace_axioms(content)
124
+ @axiom_counter = 0
125
+ replace_term("\\axiom", content, method(:replace_axiom))
126
+ end
127
+
128
+ def replace_definitions(content)
129
+ @definition_counter = 0
130
+ replace_term("\\definition", content, method(:replace_definition))
131
+ end
132
+
133
+ def replace_proofs(content)
134
+ replace_term("\\proof", content, method(:replace_proof))
135
+ end
136
+
137
+ def convert(content)
138
+ content = replace_theorems(content)
139
+ content = replace_axioms(content)
140
+ content = replace_definitions(content)
141
+ content = replace_proofs(content)
142
+
143
+
144
+ Jekyll::Converters::Markdown::KramdownParser.new(Jekyll.configuration()).convert(content)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Euclid
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require "jekyll-euclid/version"
@@ -0,0 +1,6 @@
1
+ module Jekyll
2
+ module Euclid
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-euclid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Nakayama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a very simple attempt trying to mimic some of the behaviour found
14
+ in LaTex theoremsi system.
15
+ email:
16
+ - gui@tonkatsuengineering.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/jekyll-euclid.rb
28
+ - lib/jekyll-euclid/version.rb
29
+ - lib/jekyll/converters/euclid.rb
30
+ - sig/jekyll/euclid.rbs
31
+ homepage: https://github.com/GNakayama/jekyll-euclid
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ homepage_uri: https://github.com/GNakayama/jekyll-euclid
36
+ source_code_uri: https://github.com/GNakayama/jekyll-euclid
37
+ changelog_uri: https://github.com/GNakayama/jekyll-euclid/blob/master/CHANGELOG.md
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.4.19
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Preprocess .euclid files.
57
+ test_files: []