jekyll-tidy-json 1.1.0 → 1.2.0

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: e6b350d84387d649ec9ca591f5c2bbc56b8c5333eb8e9ffa5a709472714496c1
4
- data.tar.gz: 6e799e09705abafb510fcb01abb831c22da6355ea589b06348c4fb7e45407080
3
+ metadata.gz: 743cff63a7b0ed59e0696cd02bdb1b950be588188252a791cee1819800e78372
4
+ data.tar.gz: b9605dc665eae31688f7f42c5a6d898ab0d289b52b7ee954504d3956747fda41
5
5
  SHA512:
6
- metadata.gz: d9e2b1b0637e07ac9244db9ce04b5ff0c776769e36b262b5778e4b6462d435c40b4cdf74aeab5a5085e5443e2546a740594d488de8f0eff4a92fda1960950052
7
- data.tar.gz: 83d90fb02ce7e61d186731dd68dcda92d9ef63dd70731adcd4c219358f410efe3cb0d368375109261f68b7577f8ce88a4086614fc991b56b7a0b07e0ca9f4b93
6
+ metadata.gz: fd49755b9430689d3988c993061874b3251137a5983ac2c5a2bf868f2f32e3c646edd08a85784940e69516fefb859c45ca1cc1b802bcc6812f26cbd8134e03a9
7
+ data.tar.gz: 5bf48c6c393eca5a9507391f2c8d156263ef8a0776dde06cd86c0acf91b877c14820dfbd112a399a032f4844096c7c0d11210345c9572292d5f8a3bd265b062f
@@ -51,6 +51,13 @@ Available configuration options:
51
51
  | Description
52
52
  | Default setting
53
53
 
54
+ | `continue_on_error`
55
+ | If set to `false`, any malformed JSON encounter will raise error, preventing
56
+ site from being built. If set to `true`, all malformed files are exempted from
57
+ being tidied up with a meaningful warning being printed, but site generation
58
+ continues.
59
+ | `false`
60
+
54
61
  | `enabled`
55
62
  | Can be used to disable the plugin entirely by setting it to `false`.
56
63
  | `true`
@@ -1,4 +1,4 @@
1
- require_relative 'lib/jekyll/tidy_json/version'
1
+ require_relative "lib/jekyll/tidy_json/version"
2
2
 
3
3
  ALL_FILES_IN_GIT = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
4
4
 
@@ -15,12 +15,19 @@ module Jekyll
15
15
  end
16
16
 
17
17
  def tidy_page_or_document(page_or_document)
18
+ if should_tidy?(page_or_document.relative_path)
19
+ tidy_page_or_document!(page_or_document)
20
+ end
21
+ end
22
+
23
+ def tidy_page_or_document!(page_or_document)
18
24
  path = page_or_document.relative_path
19
25
 
20
- if should_tidy?(path)
21
- Jekyll.logger.debug("Tidy up JSON:", path)
22
- page_or_document.output = tidy_string(page_or_document.output)
23
- end
26
+ Jekyll.logger.debug("Tidy up JSON:", path)
27
+ page_or_document.output = tidy_string(page_or_document.output)
28
+ rescue JSON::ParserError
29
+ print_parse_error(!continue_on_error?, $!, path)
30
+ raise unless continue_on_error?
24
31
  end
25
32
 
26
33
  def tidy_string(string)
@@ -30,6 +37,10 @@ module Jekyll
30
37
  JSON.public_send meth, json
31
38
  end
32
39
 
40
+ def continue_on_error?
41
+ !!@continue_on_error
42
+ end
43
+
33
44
  def pretty?
34
45
  !!@pretty
35
46
  end
@@ -41,9 +52,17 @@ module Jekyll
41
52
  private
42
53
 
43
54
  def parse_plugin_config(pc)
55
+ @continue_on_error = pc.fetch("continue_on_error", false)
44
56
  @enabled = pc.fetch("enabled", true)
45
57
  @pretty = pc.fetch("pretty", false)
46
58
  end
59
+
60
+ def print_parse_error(is_fatal, exception, file_path)
61
+ logger = Jekyll.logger.public_method(is_fatal ? :error : :warn)
62
+
63
+ logger.("Malformed JSON at path:", file_path)
64
+ logger.(exception)
65
+ end
47
66
  end
48
67
  end
49
68
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module TidyJSON
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-tidy-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll