jektex 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daa553320105731fb20840fc40d211a73f576f6847b8b3de0019d72313ac0c97
4
- data.tar.gz: 4479c3dc694c196845460e4ed63263ad5bb900ed9b3a42fe68e4900001dfccda
3
+ metadata.gz: db3eb57993f08e73ede3ba763410029942df4d4320c9d659c2b28fabd5a49f4e
4
+ data.tar.gz: fd8756624b5ff039c66d0896c4c0316dfe4be10045ed412d80240ce17f2e98fd
5
5
  SHA512:
6
- metadata.gz: 42333a3f6325918d8e1da7c6dd983c3f8404d10b2ae84449076ba768846793ec992af35e6962ebde5c3ae2619dfc2f4c3211370d9c75f6f6883707fbdf355c03
7
- data.tar.gz: 24849a110d4ac120fcccab47f357d0c74ae8f7d640dbcd21c7741dc7cf88096aaef6afe088b99a486fe9589e6f67afa13703f09f395ad5c157f6b3ee542c8672
6
+ metadata.gz: 6645b4a77ccfd8919db211dca542ef3a98ae1dfc9740c74580d74b62f5e1cbaea9ca07dabe14518c3b2cec2b68cfc3406cb5d1ec3a8c840e86b07302acaf7249
7
+ data.tar.gz: 04b011d1f6e6a7dccc2de68f159ee74a0bdaf7944c7c39fb5d627942425c6665b98803abb601a696d50c1c6ac738cb629086c5149d1ffb8eec636e7e441c854b
data/README.md CHANGED
@@ -14,6 +14,7 @@ Enjoy comfort of latex and markdown without cluttering your site with bloated ja
14
14
  - Marks invalid syntax in document
15
15
  - Prints location of invalid expression during rendering
16
16
  - Tags places within the rendered documents with syntax errors
17
+ - Highly configurable but still having sensible defaults
17
18
 
18
19
  ## Usage
19
20
 
@@ -60,7 +61,16 @@ To clear cached expressions you have to delete `.jektex-cache` directory in your
60
61
  project directory.
61
62
 
62
63
  **Disabling cache**
63
- You can disable caching with `disable_disk_cache = false` in `_config.yml`.
64
+ You can disable caching with `disable_disk_cache = false` in `_config.yml`. Cache is
65
+ enabled by default.
66
+
67
+ **Setting cache location**
68
+ By default jektex cache will be saved in `.jekyll-cache` directory. This results in its
69
+ deletion when you call `jekyll clean`. To prevent cache deletion or you just want to
70
+ change location of cache from another reason you can achieve that specifying
71
+ `jektex_cache_dir` in `_config.yml`.
72
+
73
+ For example: `jektex_cache_dir: ".jektex-cache"`
64
74
 
65
75
  ## Installation
66
76
  This plugin is available as a [RubyGem](https://rubygems.org/gems/jektex).
data/lib/jektex/jektex.rb CHANGED
@@ -3,14 +3,14 @@ require 'digest'
3
3
  require 'htmlentities'
4
4
 
5
5
 
6
- PATH_TO_JS = __dir__ + "/katex.min.js"
7
- CACHE_DIR = "./.jektex-cache/"
6
+ PATH_TO_JS = File.join(__dir__, "/katex.min.js")
7
+ DEFAULT_CACHE_DIR = ".jekyll-cache"
8
8
  CACHE_FILE = "jektex-cache.marshal"
9
- PATH_TO_CACHE = CACHE_DIR + CACHE_FILE
10
9
  KATEX = ExecJS.compile(open(PATH_TO_JS).read)
11
10
  PARSE_ERROR_PLACEHOLDER = "<b style='color: red;'>PARSE ERROR</b>"
12
11
  $global_macros = Hash.new
13
12
  $count_newly_generated_expressions = 0
13
+ $path_to_cache = File.join(DEFAULT_CACHE_DIR, CACHE_FILE)
14
14
  $cache = nil
15
15
  $disable_disk_cache = false
16
16
 
@@ -51,7 +51,7 @@ def escape_method( type, string, doc_path )
51
51
  {displayMode: @display, macros: $global_macros})
52
52
  rescue SystemExit, Interrupt
53
53
  # save cache to disk
54
- File.open(PATH_TO_CACHE, "w"){|to_file| Marshal.dump($cache, to_file)}
54
+ File.open($path_to_cache, "w"){|to_file| Marshal.dump($cache, to_file)}
55
55
  # this stops jekyll being immune to interupts and kill command
56
56
  raise
57
57
  rescue Exception => e
@@ -80,6 +80,10 @@ Jekyll::Hooks.register :pages, :post_render do |page|
80
80
  page.output = convert(page)
81
81
  end
82
82
 
83
+ Jekyll::Hooks.register :documents, :post_render do |doc|
84
+ doc.output = convert(doc)
85
+ end
86
+
83
87
  Jekyll::Hooks.register :site, :after_init do |site|
84
88
  # load macros from config file
85
89
  if site.config["jektex-macros"] != nil
@@ -95,13 +99,19 @@ Jekyll::Hooks.register :site, :after_init do |site|
95
99
  ($global_macros.size == 1 ? "" : "s") + " loaded"
96
100
  end
97
101
 
102
+ # check if cache is disable in config
98
103
  if site.config["disable_disk_cache"] != nil
99
104
  $disable_disk_cache = site.config["disable_disk_cache"]
100
105
  end
101
106
 
107
+ # check if there is defined custom cache location in config
108
+ if site.config["jektex_cache_dir"] != nil
109
+ $path_to_cache = File.join(site.config["jektex_cache_dir"].to_s, CACHE_FILE)
110
+ end
111
+
102
112
  # load content of cache file if it exists
103
- if(File.exist?(PATH_TO_CACHE))
104
- $cache = File.open(PATH_TO_CACHE, "r"){|from_file| Marshal.load(from_file)}
113
+ if(File.exist?($path_to_cache))
114
+ $cache = File.open($path_to_cache, "r"){|from_file| Marshal.load(from_file)}
105
115
  else
106
116
  $cache = Hash.new
107
117
  end
@@ -118,7 +128,7 @@ Jekyll::Hooks.register :site, :post_write do
118
128
  # check if caching is enabled
119
129
  if $disable_disk_cache == false
120
130
  # save cache to disk
121
- Dir.mkdir(CACHE_DIR) unless File.exists?(CACHE_DIR)
122
- File.open(PATH_TO_CACHE, "w"){|to_file| Marshal.dump($cache, to_file)}
131
+ Dir.mkdir(File.dirname($path_to_cache)) unless File.exists?(File.dirname($path_to_cache))
132
+ File.open($path_to_cache, "w"){|to_file| Marshal.dump($cache, to_file)}
123
133
  end
124
134
  end
@@ -1,3 +1,3 @@
1
1
  module Jektex
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jektex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Černý