cloudcannon-jekyll 0.3.4 → 1.0.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.
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- # Utility class to help generate files with no source file
5
4
  class PageWithoutAFile < Jekyll::Page
6
5
  def read_yaml(*)
7
6
  @data ||= {}
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+
5
+ module CloudCannonJekyll
6
+ module SafeJsonifyFilter
7
+ @simple_types = [
8
+ String,
9
+ Numeric,
10
+ Integer,
11
+ Float,
12
+ Date,
13
+ Time,
14
+ NilClass,
15
+ ].freeze
16
+
17
+ @document_types = [
18
+ Jekyll::Document,
19
+ Jekyll::Page,
20
+ Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
21
+ ].compact.freeze
22
+
23
+ def self.document_type?(input)
24
+ @document_types.include?(input.class)
25
+ end
26
+
27
+ def self.simple_type?(input)
28
+ @simple_types.include?(input.class) || [true, false].include?(input)
29
+ end
30
+
31
+ def self.static_file_to_json(input, depth)
32
+ out = [
33
+ "\"extname\": #{SafeJsonifyFilter.to_json(input.extname, depth + 1)}",
34
+ "\"path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
35
+ ]
36
+
37
+ # modified_time isn't defined in Jekyll 2.4.0
38
+ if input.respond_to? :modified_time
39
+ out.push("\"modified_time\": #{SafeJsonifyFilter.to_json(input.modified_time, depth + 1)}")
40
+ end
41
+
42
+ "{#{out.join(",")}}"
43
+ end
44
+
45
+ def self.document_data_to_json(data, out, prevent, depth)
46
+ prevent += %w(content output next previous excerpt)
47
+
48
+ data.map do |key, value|
49
+ unless prevent.include? key
50
+ out.push("\"#{key}\": #{SafeJsonifyFilter.to_json(value, depth + 1)}")
51
+ prevent.push(key)
52
+ end
53
+ end
54
+
55
+ "{#{out.join(",")}}"
56
+ end
57
+
58
+ def self.legacy_post_to_json(input, depth)
59
+ prevent = %w(dir name path url date id categories tags)
60
+
61
+ out = [
62
+ "\"dir\": #{SafeJsonifyFilter.to_json(input.dir, depth + 1)}",
63
+ "\"name\": #{SafeJsonifyFilter.to_json(input.name, depth + 1)}",
64
+ "\"path\": #{SafeJsonifyFilter.to_json(input.path, depth + 1)}",
65
+ "\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
66
+ "\"date\": #{SafeJsonifyFilter.to_json(input.date, depth + 1)}",
67
+ "\"id\": #{SafeJsonifyFilter.to_json(input.id, depth + 1)}",
68
+ "\"categories\": #{SafeJsonifyFilter.to_json(input.categories, depth + 1)}",
69
+ "\"tags\": #{SafeJsonifyFilter.to_json(input.tags, depth + 1)}",
70
+ ]
71
+
72
+ SafeJsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
73
+ end
74
+
75
+ def self.page_to_json(input, depth)
76
+ prevent = %w(dir name path url)
77
+
78
+ out = [
79
+ "\"dir\": #{SafeJsonifyFilter.to_json(input.dir, depth + 1)}",
80
+ "\"name\": #{SafeJsonifyFilter.to_json(input.name, depth + 1)}",
81
+ "\"path\": #{SafeJsonifyFilter.to_json(input.path, depth + 1)}",
82
+ "\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
83
+ ]
84
+
85
+ # Merge Jekyll Defaults into data for pages (missing at v3.8.5)
86
+ defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |h|
87
+ h.delete("date")
88
+ end
89
+
90
+ data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
91
+ SafeJsonifyFilter.document_data_to_json(data, out, prevent, depth)
92
+ end
93
+
94
+ def self.document_to_json(input, depth)
95
+ prevent = %w(dir id relative_path url collection)
96
+
97
+ out = [
98
+ "\"path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
99
+ "\"relative_path\": #{SafeJsonifyFilter.to_json(input.relative_path, depth + 1)}",
100
+ "\"url\": #{SafeJsonifyFilter.to_json(input.url, depth + 1)}",
101
+ ]
102
+
103
+ unless input.collection.nil?
104
+ out.push("\"collection\": #{SafeJsonifyFilter.to_json(input.collection.label, depth + 1)}")
105
+ end
106
+
107
+ # id isn't defined in Jekyll 2.4.0
108
+ out.push("\"id\": #{SafeJsonifyFilter.to_json(input.id, depth + 1)}") if input.respond_to? :id
109
+
110
+ SafeJsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
111
+ end
112
+
113
+ def self.array_to_json(input, depth)
114
+ array = input.map do |value|
115
+ SafeJsonifyFilter.to_json(value, depth + 1)
116
+ end
117
+
118
+ "[#{array.join(",")}]"
119
+ end
120
+
121
+ def self.hash_to_json(input, depth)
122
+ hash = input.map do |key, value|
123
+ "\"#{key}\": #{SafeJsonifyFilter.to_json(value, depth + 1)}"
124
+ end
125
+
126
+ "{#{hash.join(",")}}"
127
+ end
128
+
129
+ def self.to_json(input, depth)
130
+ if depth > 8 || (depth > 2 && SafeJsonifyFilter.document_type?(input))
131
+ '"MAXIMUM_DEPTH"'
132
+ elsif SafeJsonifyFilter.simple_type?(input)
133
+ input.to_json
134
+ elsif input.is_a?(Jekyll::StaticFile)
135
+ SafeJsonifyFilter.static_file_to_json(input, depth)
136
+ elsif input.is_a?(Jekyll::Page)
137
+ SafeJsonifyFilter.page_to_json(input, depth)
138
+ elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
139
+ SafeJsonifyFilter.legacy_post_to_json(input, depth)
140
+ elsif input.is_a?(Jekyll::Document)
141
+ SafeJsonifyFilter.document_to_json(input, depth)
142
+ elsif input.is_a?(Array)
143
+ SafeJsonifyFilter.array_to_json(input, depth)
144
+ elsif input.is_a?(Hash)
145
+ SafeJsonifyFilter.hash_to_json(input, depth)
146
+ else
147
+ "\"UNSUPPORTED:#{input.class}\""
148
+ end
149
+ end
150
+
151
+ def cc_static_files_jsonify(input)
152
+ out = []
153
+ input.each do |page|
154
+ next if page.extname != ".html" &&
155
+ page.extname != ".htm" &&
156
+ page.path != "/robots.txt" &&
157
+ page.path != "/sitemap.xml"
158
+
159
+ out.push(SafeJsonifyFilter.to_json(page, 1))
160
+ end
161
+
162
+ "[#{out.join(",")}]"
163
+ end
164
+
165
+ def cc_safe_jsonify(input)
166
+ SafeJsonifyFilter.to_json(input, 0)
167
+ end
168
+ end
169
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = "0.3.4"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -2,5 +2,6 @@
2
2
 
3
3
  set -ex
4
4
 
5
- $(dirname "$0")/test
5
+ bundle exec rspec "$@"
6
+ bundle exec rubocop -S
6
7
  bundle exec gem build cloudcannon-jekyll.gemspec
@@ -33,7 +33,5 @@ git fetch -t origin
33
33
 
34
34
  # Push tag and upload new gem
35
35
 
36
- git tag "$tag" &&
37
- git push origin master &&
38
- git push origin "$tag" &&
39
- gem push cloudcannon-jekyll-*.gem
36
+ gem push cloudcannon-jekyll-*.gem && git tag "$tag" &&
37
+ git push origin master && git push origin "$tag"
@@ -3,4 +3,3 @@
3
3
  set -ex
4
4
 
5
5
  bundle exec rspec "$@"
6
- bundle exec rubocop -S
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudcannon-jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CloudCannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-16 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 2.4.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4'
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,21 +29,7 @@ dependencies:
29
29
  version: 2.4.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '4'
33
- - !ruby/object:Gem::Dependency
34
- name: json_schemer
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: 0.2.4
40
- type: :development
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: 0.2.4
32
+ version: '5'
47
33
  - !ruby/object:Gem::Dependency
48
34
  name: rake
49
35
  requirement: !ruby/object:Gem::Requirement
@@ -78,28 +64,28 @@ dependencies:
78
64
  requirements:
79
65
  - - "~>"
80
66
  - !ruby/object:Gem::Version
81
- version: '0.80'
67
+ version: '0.71'
82
68
  type: :development
83
69
  prerelease: false
84
70
  version_requirements: !ruby/object:Gem::Requirement
85
71
  requirements:
86
72
  - - "~>"
87
73
  - !ruby/object:Gem::Version
88
- version: '0.80'
74
+ version: '0.71'
89
75
  - !ruby/object:Gem::Dependency
90
76
  name: rubocop-jekyll
91
77
  requirement: !ruby/object:Gem::Requirement
92
78
  requirements:
93
79
  - - "~>"
94
80
  - !ruby/object:Gem::Version
95
- version: '0.11'
81
+ version: '0.10'
96
82
  type: :development
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
- version: '0.11'
88
+ version: '0.10'
103
89
  description: Creates CloudCannon editor details for Jekyll
104
90
  email:
105
91
  - support@cloudcannon.com
@@ -107,9 +93,7 @@ executables: []
107
93
  extensions: []
108
94
  extra_rdoc_files: []
109
95
  files:
110
- - ".github/workflows/stale.yml"
111
96
  - ".gitignore"
112
- - ".reek.yml"
113
97
  - ".rspec"
114
98
  - ".rubocop.yml"
115
99
  - ".travis.yml"
@@ -120,21 +104,14 @@ files:
120
104
  - Rakefile
121
105
  - cloudcannon-jekyll.gemspec
122
106
  - lib/cloudcannon-jekyll.rb
123
- - lib/cloudcannon-jekyll/_cloudcannon/config-2.x.json
124
- - lib/cloudcannon-jekyll/_cloudcannon/config-3.0-4.x.json
125
- - lib/cloudcannon-jekyll/_cloudcannon/config.json
126
107
  - lib/cloudcannon-jekyll/_cloudcannon/details-2.x.json
127
- - lib/cloudcannon-jekyll/_cloudcannon/details-3.0-4.x.json
108
+ - lib/cloudcannon-jekyll/_cloudcannon/details-3.0.x.json
128
109
  - lib/cloudcannon-jekyll/_cloudcannon/details.json
129
110
  - lib/cloudcannon-jekyll/configuration.rb
130
111
  - lib/cloudcannon-jekyll/generator.rb
131
- - lib/cloudcannon-jekyll/jsonify-filter.rb
132
112
  - lib/cloudcannon-jekyll/page-without-a-file.rb
133
- - lib/cloudcannon-jekyll/reader.rb
134
- - lib/cloudcannon-jekyll/readers/data-reader.rb
135
- - lib/cloudcannon-jekyll/readers/old-data-reader.rb
113
+ - lib/cloudcannon-jekyll/safe-jsonify-filter.rb
136
114
  - lib/cloudcannon-jekyll/version.rb
137
- - script/ci-smoke-test
138
115
  - script/cibuild
139
116
  - script/release
140
117
  - script/test
@@ -157,7 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
134
  - !ruby/object:Gem::Version
158
135
  version: '0'
159
136
  requirements: []
160
- rubygems_version: 3.0.3
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.6.2
161
139
  signing_key:
162
140
  specification_version: 4
163
141
  summary: CloudCannon Jekyll integration
@@ -1,19 +0,0 @@
1
- name: Mark stale issues
2
-
3
- on:
4
- schedule:
5
- - cron: "30 1 * * *"
6
-
7
- jobs:
8
- stale:
9
-
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - uses: actions/stale@v1
14
- with:
15
- repo-token: ${{ secrets.GITHUB_TOKEN }}
16
- stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
17
- stale-issue-label: 'no-issue-activity'
18
- days-before-stale: 30
19
- days-before-close: 5
data/.reek.yml DELETED
@@ -1,6 +0,0 @@
1
- detectors:
2
- LongParameterList:
3
- max_params: 4 # Matches the Rubocop setting
4
-
5
- exclude_paths:
6
- - spec
@@ -1,36 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- {% if config.timezone %}"timezone": {{ config.timezone | cc_jsonify }},{% endif %}
8
- "include": {{ config.include | cc_jsonify }},
9
- "exclude": {{ config.exclude | cc_jsonify }},
10
- {% if config.baseurl %}"base-url": {{ config.baseurl | cc_jsonify }},{% endif %}
11
- "collections": {{ collections | cc_jsonify: 'collections' }},
12
- {% if config._comments %}"comments": {{ config._comments | cc_jsonify }},{% endif %}
13
- {% if config._options %}"input-options": {{ config._options | cc_jsonify }},{% endif %}
14
- {% if config.defaults %}"defaults": {{ config.defaults | cc_jsonify }},{% endif %}
15
- {% if config._editor %}"editor": {
16
- "default-path": {{ config._editor.default_path | cc_jsonify }}
17
- },{% endif %}
18
- {% if config._source_editor %}"source-editor": {
19
- "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
20
- "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
21
- "theme": {{ config._source_editor.theme | cc_jsonify }}
22
- },{% endif %}
23
- {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
24
- "paths": {
25
- "uploads": {{ config.uploads_dir | cc_jsonify }},
26
- "plugins": {{ config.plugins_dir | cc_jsonify }},
27
- "data": {{ config.data_dir | cc_jsonify }},
28
- "pages": "",
29
- "collections": {{ config.collections_dir | cc_jsonify }},
30
- "includes": {{ config.includes_dir | cc_jsonify }},
31
- "layouts": {{ config.layouts_dir | cc_jsonify }}
32
- },
33
- {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
34
- {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
35
- "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
36
- }
@@ -1,36 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- {% if config.timezone %}"timezone": {{ config.timezone | cc_jsonify }},{% endif %}
8
- "include": {{ config.include | cc_jsonify }},
9
- "exclude": {{ config.exclude | cc_jsonify }},
10
- {% if config.baseurl %}"base-url": {{ config.baseurl | cc_jsonify }},{% endif %}
11
- "collections": {{ collections | cc_jsonify: 'collections' }},
12
- {% if config._comments %}"comments": {{ config._comments | cc_jsonify }},{% endif %}
13
- {% if config._options %}"input-options": {{ config._options | cc_jsonify }},{% endif %}
14
- {% if config.defaults %}"defaults": {{ config.defaults | cc_jsonify }},{% endif %}
15
- {% if config._editor %}"editor": {
16
- "default-path": {{ config._editor.default_path | cc_jsonify }}
17
- },{% endif %}
18
- {% if config._source_editor %}"source-editor": {
19
- "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
20
- "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
21
- "theme": {{ config._source_editor.theme | cc_jsonify }}
22
- },{% endif %}
23
- {% if config._explore %}"explore": {{ config._explore | cc_jsonify }},{% endif %}
24
- "paths": {
25
- "uploads": {{ config.uploads_dir | cc_jsonify }},
26
- "plugins": {{ config.plugins_dir | cc_jsonify }},
27
- "data": {{ config.data_dir | cc_jsonify }},
28
- "pages": "",
29
- "collections": {{ config.collections_dir | cc_jsonify }},
30
- "includes": {{ config.includes_dir | cc_jsonify }},
31
- "layouts": {{ config.layouts_dir | cc_jsonify }}
32
- },
33
- {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
34
- {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
35
- "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
36
- }
@@ -1,57 +0,0 @@
1
- {
2
- "time": {{ site.time | date_to_xmlschema | cc_jsonify }},
3
- "cloudcannon": {
4
- "name": "cloudcannon-jekyll",
5
- "version": {{ gem_version | cc_jsonify }}
6
- },
7
- {% if config.timezone -%}
8
- "timezone": {{ config.timezone | cc_jsonify }},
9
- {%- endif %}
10
- "include": {{ config.include | cc_jsonify }},
11
- "exclude": {{ config.exclude | cc_jsonify }},
12
- {% if config.baseurl -%}
13
- "base-url": {{ config.baseurl | cc_jsonify }},
14
- {%- endif %}
15
- "collections": {{ collections | cc_jsonify: 'collections' }},
16
- {% if config._comments -%}
17
- "comments": {{ config._comments | cc_jsonify }},
18
- {%- endif %}
19
- {% if config._options -%}
20
- "input-options": {{ config._options | cc_jsonify }},
21
- {%- endif %}
22
- {% if config.defaults -%}
23
- "defaults": {{ config.defaults | cc_jsonify }},
24
- {%- endif %}
25
- {% if config._editor -%}
26
- "editor": {
27
- "default-path": {{ config._editor.default_path | cc_jsonify }}
28
- },
29
- {%- endif %}
30
- {% if config._source_editor -%}
31
- "source-editor": {
32
- "tab-size": {{ config._source_editor.tab_size | cc_jsonify }},
33
- "show-gutter": {{ config._source_editor.show_gutter | cc_jsonify }},
34
- "theme": {{ config._source_editor.theme | cc_jsonify }}
35
- },
36
- {%- endif %}
37
- {% if config._explore -%}
38
- "explore": {{ config._explore | cc_jsonify }},
39
- {%- endif %}
40
- "paths": {
41
- "uploads": {{ config.uploads_dir | cc_jsonify }},
42
- "plugins": {{ config.plugins_dir | cc_jsonify }},
43
- "data": {{ config.data_dir | cc_jsonify }},
44
- "pages": "",
45
- "collections": {{ config.collections_dir | cc_jsonify }},
46
- "includes": {{ config.includes_dir | cc_jsonify }},
47
- "layouts": {{ config.layouts_dir | cc_jsonify }}
48
- },
49
- {% if config._array_structures -%}
50
- "array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},
51
- {%- endif %}
52
- {% assign select_data = config | cc_select_data_jsonify -%}
53
- {% if select_data -%}
54
- "select-data": {{ select_data }},
55
- {%- endif %}
56
- "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
57
- }