jekyll-tidy-json 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.adoc +87 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jekyll-tidy-json.gemspec +37 -0
- data/lib/jekyll-tidy-json.rb +5 -0
- data/lib/jekyll/tidy_json.rb +58 -0
- data/lib/jekyll/tidy_json/version.rb +5 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a100fe883b4f484897f0ea5d76dcdbfad084a12bd7c8576f950b1fbc80b4aa66
|
4
|
+
data.tar.gz: c311f572cacd7564f213558696f42b440d1c4e37b3e6f648c8ada464f8516a20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b95e847956a0994a986e20df431a47b6a2c1e88610352af202dcc3ab3d934828f28793039520bb244044f54e6a451efdc6be4659c8e851a5538d8891ffd2183b
|
7
|
+
data.tar.gz: 3466c5bbaab955fd2dd4e75b413aefac431d44a3ffcb7cd54fc963788636f315fd405ee1b133d6cb127d98744f76cd65aacf86b4b3aa2f641a8f84c2ef4fea6f
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ribose Inc.
|
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.adoc
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
= Jekyll-Tidy-JSON
|
2
|
+
|
3
|
+
ifdef::env-github[]
|
4
|
+
image:https://img.shields.io/gem/v/jekyll-tidy-json[
|
5
|
+
"Gem Version",
|
6
|
+
link="https://rubygems.org/gems/jekyll-tidy-json"]
|
7
|
+
image:https://img.shields.io/github/workflow/status/geolexica/jekyll-tidy-json/Tests[
|
8
|
+
"Build Status",
|
9
|
+
link="https://github.com/geolexica/jekyll-tidy-json/actions"]
|
10
|
+
endif::[]
|
11
|
+
|
12
|
+
A Jekyll plugin that cleans JSONs up.
|
13
|
+
|
14
|
+
It takes a JSON page and applies consistent formatting rules to it. If that
|
15
|
+
input is malformed, then raises an exception at site building time to prevent
|
16
|
+
you from deploying a buggy site.
|
17
|
+
|
18
|
+
If you use Liquid templates to build JSONs for your site, then you probably
|
19
|
+
really want it.
|
20
|
+
|
21
|
+
== Installation
|
22
|
+
|
23
|
+
Include this gem in your site's Gemfile under the `:jekyll_plugins group`:
|
24
|
+
|
25
|
+
[source,lang=sh]
|
26
|
+
----
|
27
|
+
group :jekyll_plugins do
|
28
|
+
gem "jekyll-tidy-json"
|
29
|
+
end
|
30
|
+
----
|
31
|
+
|
32
|
+
Visit https://jekyllrb.com/docs/plugins/installation/[Jekyll documentation]
|
33
|
+
for a detailed description or more installation options.
|
34
|
+
|
35
|
+
== Configuration
|
36
|
+
|
37
|
+
This plugin's behaviour is steered by "tidy_json" entry in site's `_config.yml`.
|
38
|
+
For example, following enables JSON prettifying:
|
39
|
+
|
40
|
+
[source,lang=yaml]
|
41
|
+
----
|
42
|
+
tidy_json:
|
43
|
+
pretty: true
|
44
|
+
----
|
45
|
+
|
46
|
+
Available configuration options:
|
47
|
+
|
48
|
+
[cols=3*,options="header"]
|
49
|
+
|===
|
50
|
+
| Option name
|
51
|
+
| Description
|
52
|
+
| Default setting
|
53
|
+
|
54
|
+
| `enabled`
|
55
|
+
| Can be used to disable the plugin entirely by setting it to `false`.
|
56
|
+
| `true`
|
57
|
+
|
58
|
+
| `pretty`
|
59
|
+
| If set to `true`, then JSONs will be prettified for readability sake. If
|
60
|
+
set to `false`, then all unnecessary spaces and new lines will be removed.
|
61
|
+
| `false`
|
62
|
+
|===
|
63
|
+
|
64
|
+
== TODO
|
65
|
+
|
66
|
+
This plugin is fairly complete. However, some enhancements would be welcome:
|
67
|
+
|
68
|
+
- more options for pretty formatting
|
69
|
+
- options for including/excluding JSON files
|
70
|
+
- JSON sanitizing features, perhaps by integrating
|
71
|
+
https://github.com/OWASP/json-sanitizer[json-sanitizer] by OWASP
|
72
|
+
- support for some improved JSON syntax like https://json5.org/[JSON5]
|
73
|
+
or http://www.relaxedjson.org/[Relaxed JSON] if any of them gets popular
|
74
|
+
enough
|
75
|
+
|
76
|
+
== Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/geolexica/jekyll-tidy-json.
|
79
|
+
|
80
|
+
== Credits
|
81
|
+
|
82
|
+
This gem is developed, maintained and funded by
|
83
|
+
https://www.ribose.com[Ribose Inc.]
|
84
|
+
|
85
|
+
== License
|
86
|
+
|
87
|
+
This gem is licensed under MIT license.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jekyll/tidy_json"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'lib/jekyll/tidy_json/version'
|
2
|
+
|
3
|
+
ALL_FILES_IN_GIT = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-tidy-json"
|
7
|
+
spec.version = Jekyll::TidyJSON::VERSION
|
8
|
+
spec.authors = ["Ribose Inc."]
|
9
|
+
spec.email = ["open.source@ribose.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Jekyll plugin that cleans JSONs up."
|
12
|
+
spec.description = spec.summary + " If you use Liquid templates to build " +
|
13
|
+
"JSONs for your site, then you probably really want it."
|
14
|
+
spec.homepage = "https://github.com/geolexica/jekyll-tidy-json"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.metadata = {
|
18
|
+
"bug_tracker_uri" => (spec.homepage + "/issues"),
|
19
|
+
"homepage_uri" => spec.homepage,
|
20
|
+
"source_code_uri" => spec.homepage,
|
21
|
+
}
|
22
|
+
|
23
|
+
spec.files = ALL_FILES_IN_GIT.reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features|.github)/}) ||
|
25
|
+
%w[.editorconfig .gitignore .rspec].include?(f)
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
33
|
+
|
34
|
+
spec.add_runtime_dependency "jekyll", ">= 3.8", "< 5"
|
35
|
+
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.9"
|
37
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
require_relative "tidy_json/version"
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module TidyJSON
|
8
|
+
class Processor
|
9
|
+
def initialize(config)
|
10
|
+
parse_plugin_config config.fetch("tidy_json", {})
|
11
|
+
end
|
12
|
+
|
13
|
+
def should_tidy?(path)
|
14
|
+
File.extname(path).downcase == ".json"
|
15
|
+
end
|
16
|
+
|
17
|
+
def tidy_page_or_document(page_or_document)
|
18
|
+
path = page_or_document.relative_path
|
19
|
+
|
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
|
24
|
+
end
|
25
|
+
|
26
|
+
def tidy_string(string)
|
27
|
+
return string if !enabled? || string.empty?
|
28
|
+
json = JSON.parse(string)
|
29
|
+
meth = self.pretty? ? :pretty_generate : :fast_generate
|
30
|
+
|
31
|
+
JSON.public_send meth, json
|
32
|
+
end
|
33
|
+
|
34
|
+
def pretty?
|
35
|
+
!!@pretty
|
36
|
+
end
|
37
|
+
|
38
|
+
def enabled?
|
39
|
+
!!@enabled
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def parse_plugin_config(pc)
|
45
|
+
@enabled = pc.fetch("enabled", true)
|
46
|
+
@pretty = pc.fetch("pretty", false)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Jekyll::Hooks.register :documents, :post_render do |doc|
|
53
|
+
Jekyll::TidyJSON::Processor.new(doc.site.config).tidy_page_or_document(doc)
|
54
|
+
end
|
55
|
+
|
56
|
+
Jekyll::Hooks.register :pages, :post_render do |page|
|
57
|
+
Jekyll::TidyJSON::Processor.new(page.site.config).tidy_page_or_document(page)
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-tidy-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.9'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.9'
|
47
|
+
description: A Jekyll plugin that cleans JSONs up. If you use Liquid templates to
|
48
|
+
build JSONs for your site, then you probably really want it.
|
49
|
+
email:
|
50
|
+
- open.source@ribose.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.adoc
|
58
|
+
- Rakefile
|
59
|
+
- bin/console
|
60
|
+
- bin/setup
|
61
|
+
- jekyll-tidy-json.gemspec
|
62
|
+
- lib/jekyll-tidy-json.rb
|
63
|
+
- lib/jekyll/tidy_json.rb
|
64
|
+
- lib/jekyll/tidy_json/version.rb
|
65
|
+
homepage: https://github.com/geolexica/jekyll-tidy-json
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
bug_tracker_uri: https://github.com/geolexica/jekyll-tidy-json/issues
|
70
|
+
homepage_uri: https://github.com/geolexica/jekyll-tidy-json
|
71
|
+
source_code_uri: https://github.com/geolexica/jekyll-tidy-json
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.3.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.0.3
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A Jekyll plugin that cleans JSONs up.
|
91
|
+
test_files: []
|