jekyll-admin 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -1
  3. data/lib/jekyll-admin.rb +14 -13
  4. data/lib/jekyll-admin/apiable.rb +71 -10
  5. data/lib/jekyll-admin/data_file.rb +19 -16
  6. data/lib/jekyll-admin/directory.rb +24 -26
  7. data/lib/jekyll-admin/file_helper.rb +14 -0
  8. data/lib/jekyll-admin/path_helper.rb +8 -1
  9. data/lib/jekyll-admin/public/12f0820c451bdc75f4d1ef97732bf6e8.woff +0 -0
  10. data/lib/jekyll-admin/public/{03945ac4fc7fdefc44bc110bf1ba2393.svg → 792dcd18baf5f544aabcad1883d673c2.svg} +14 -8
  11. data/lib/jekyll-admin/public/{bfc14ac982326f7d0b1340e20d3e0c37.ttf → bc7c4a59f924cf037aad6e1f9edba366.eot} +0 -0
  12. data/lib/jekyll-admin/public/bundle.js +27 -17
  13. data/lib/jekyll-admin/public/bundle.js.map +1 -1
  14. data/lib/jekyll-admin/public/{e44520ab9079ea7633bfa874bed5d21d.eot → eceddf474df95d8d4a7e316668c3be85.ttf} +0 -0
  15. data/lib/jekyll-admin/public/styles.css +103 -2
  16. data/lib/jekyll-admin/public/styles.css.map +1 -1
  17. data/lib/jekyll-admin/server.rb +21 -12
  18. data/lib/jekyll-admin/server/{collection.rb → collections.rb} +11 -4
  19. data/lib/jekyll-admin/server/configuration.rb +5 -2
  20. data/lib/jekyll-admin/server/data.rb +3 -1
  21. data/lib/jekyll-admin/server/{draft.rb → drafts.rb} +8 -3
  22. data/lib/jekyll-admin/server/{page.rb → pages.rb} +22 -4
  23. data/lib/jekyll-admin/server/site_meta.rb +25 -0
  24. data/lib/jekyll-admin/server/static_files.rb +83 -0
  25. data/lib/jekyll-admin/static_server.rb +3 -1
  26. data/lib/jekyll-admin/urlable.rb +4 -0
  27. data/lib/jekyll-admin/version.rb +3 -1
  28. data/lib/jekyll/commands/serve.rb +2 -0
  29. metadata +14 -14
  30. data/lib/jekyll-admin/page_without_a_file.rb +0 -7
  31. data/lib/jekyll-admin/public/99adb54b0f30c0758bb4cb9ed5b80aa8.woff +0 -0
  32. data/lib/jekyll-admin/server/static_file.rb +0 -61
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ # Jekyll::Site instance method names that return a Hash.
6
+ META_KEYS = [:categories, :layouts, :tags].freeze
7
+ private_constant :META_KEYS
8
+
9
+ namespace "/site_meta" do
10
+ get "/?" do
11
+ json site_meta
12
+ end
13
+
14
+ private
15
+
16
+ # Stash a Hash generated with pre-determined keys.
17
+ def site_meta
18
+ @site_meta ||= META_KEYS.zip(META_KEYS.map { |k| site.send(k).keys }).to_h
19
+ end
20
+
21
+ # Reset memoization of `#site_meta` when the site regenerates
22
+ Jekyll::Hooks.register(:site, :after_reset) { @site_meta = nil }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ namespace "/static_files" do
6
+ # End-point to retrieve all static-files in site
7
+ get "/index" do
8
+ json site.static_files.map(&:to_api)
9
+ end
10
+
11
+ # End-point to retrieve individual directories that contain static-files
12
+ get "/?*" do
13
+ render_404 unless File.exist?(path)
14
+
15
+ if requested_file
16
+ json requested_file.to_api(:include_content => true)
17
+ else
18
+ json entries.map(&:to_api)
19
+ end
20
+ end
21
+
22
+ put "/*" do
23
+ if renamed?
24
+ ensure_requested_file
25
+ delete_file_without_process path
26
+ end
27
+
28
+ write_file(write_path, static_file_body)
29
+ json written_file.to_api(:include_content => true)
30
+ end
31
+
32
+ delete "/*" do
33
+ ensure_requested_file
34
+ delete_file path
35
+ content_type :json
36
+ status 200
37
+ halt
38
+ end
39
+
40
+ private
41
+
42
+ # returns relative path of root level directories that contain static files
43
+ def dirs_at_root
44
+ static_files.map do |file|
45
+ File.dirname(file.path.sub("#{site.source}/", "")).split("/")[0]
46
+ end.uniq
47
+ end
48
+
49
+ def directory_files
50
+ static_files.find_all do |file|
51
+ sanitized_path(File.dirname(file.path)) == directory_path
52
+ end
53
+ end
54
+
55
+ def entries
56
+ splat = params["splat"].first
57
+ args = {
58
+ :base => site.source,
59
+ :content_type => "static_files",
60
+ :splat => splat,
61
+ }
62
+ # get all directories inside the requested directory
63
+ directory = JekyllAdmin::Directory.new(directory_path, args)
64
+ directories = directory.directories
65
+
66
+ # exclude root level directories which do not have static files
67
+ directories = directories.select { |d| dirs_at_root.include? d.name.to_s } if splat.empty?
68
+ directories.concat(directory_files)
69
+ end
70
+
71
+ def static_file_body
72
+ raw_content = request_payload["raw_content"]
73
+ return raw_content if raw_content.is_a?(String) && raw_content != ""
74
+
75
+ Base64.decode64 request_payload["encoded_content"].to_s
76
+ end
77
+
78
+ def static_files
79
+ site.static_files.select { |f| f.path.start_with? site.source }
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllAdmin
2
4
  class StaticServer < Sinatra::Base
3
5
  set :public_dir, File.expand_path("./public", File.dirname(__FILE__))
4
6
 
5
- MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build.".freeze
7
+ MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build."
6
8
 
7
9
  # Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
8
10
  get "/*" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllAdmin
2
4
  # Abstract module to be included in Convertible and Document to provide
3
5
  # additional, URL-specific functionality without duplicating logic
@@ -33,6 +35,7 @@ module JekyllAdmin
33
35
  # Note: we can't use a case statement here, because === doesn't like includes
34
36
  #
35
37
  # rubocop:disable Metrics/CyclomaticComplexity
38
+ # rubocop:disable Metrics/PerceivedComplexity
36
39
  def resource_path
37
40
  if is_a?(Jekyll::Document) && draft?
38
41
  "/#{relative_path.sub(%r!\A_!, "")}"
@@ -48,6 +51,7 @@ module JekyllAdmin
48
51
  "/pages/#{relative_path}"
49
52
  end
50
53
  end
54
+ # rubocop:enable Metrics/PerceivedComplexity
51
55
  # rubocop:enable Metrics/CyclomaticComplexity
52
56
 
53
57
  # URI.join doesn't like joining two relative paths, and File.join may join
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllAdmin
2
- VERSION = "0.9.0".freeze
4
+ VERSION = "0.10.0"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Commands
3
5
  class Serve < Command
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mert Kahyaoğlu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-09-27 00:00:00.000000000 Z
12
+ date: 2020-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -17,7 +17,7 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3.3'
20
+ version: '3.7'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
23
  version: '5.0'
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: '3.3'
30
+ version: '3.7'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5.0'
@@ -158,36 +158,36 @@ files:
158
158
  - lib/jekyll-admin/data_file.rb
159
159
  - lib/jekyll-admin/directory.rb
160
160
  - lib/jekyll-admin/file_helper.rb
161
- - lib/jekyll-admin/page_without_a_file.rb
162
161
  - lib/jekyll-admin/path_helper.rb
163
- - lib/jekyll-admin/public/03945ac4fc7fdefc44bc110bf1ba2393.svg
164
162
  - lib/jekyll-admin/public/059514c92565e4045da1a69525dd9ec0.ttf
163
+ - lib/jekyll-admin/public/12f0820c451bdc75f4d1ef97732bf6e8.woff
165
164
  - lib/jekyll-admin/public/1dc35d25e61d819a9c357074014867ab.ttf
166
165
  - lib/jekyll-admin/public/24c601e721ebd8279d38e2cfa0d01bc6.svg
167
166
  - lib/jekyll-admin/public/25a32416abee198dd821b0b17a198a8f.eot
168
167
  - lib/jekyll-admin/public/33a752211d05af6684e26ec63c2ed965.gif
169
168
  - lib/jekyll-admin/public/55131026930a0cd4539d1e2fdb92722d.ttf
169
+ - lib/jekyll-admin/public/792dcd18baf5f544aabcad1883d673c2.svg
170
170
  - lib/jekyll-admin/public/8b4968b70019a0551a72940c5a2020d3.png
171
171
  - lib/jekyll-admin/public/8ea28ca3bfdf27145068e81dd07a34c6.png
172
- - lib/jekyll-admin/public/99adb54b0f30c0758bb4cb9ed5b80aa8.woff
173
172
  - lib/jekyll-admin/public/a770b6797b68e3f8920e473eb824bac0.gif
174
- - lib/jekyll-admin/public/bfc14ac982326f7d0b1340e20d3e0c37.ttf
173
+ - lib/jekyll-admin/public/bc7c4a59f924cf037aad6e1f9edba366.eot
175
174
  - lib/jekyll-admin/public/bundle.js
176
175
  - lib/jekyll-admin/public/bundle.js.map
177
176
  - lib/jekyll-admin/public/c8ddf1e5e5bf3682bc7bebf30f394148.woff
178
- - lib/jekyll-admin/public/e44520ab9079ea7633bfa874bed5d21d.eot
179
177
  - lib/jekyll-admin/public/e6cf7c6ec7c2d6f670ae9d762604cb0b.woff2
178
+ - lib/jekyll-admin/public/eceddf474df95d8d4a7e316668c3be85.ttf
180
179
  - lib/jekyll-admin/public/favicon.ico
181
180
  - lib/jekyll-admin/public/index.html
182
181
  - lib/jekyll-admin/public/styles.css
183
182
  - lib/jekyll-admin/public/styles.css.map
184
183
  - lib/jekyll-admin/server.rb
185
- - lib/jekyll-admin/server/collection.rb
184
+ - lib/jekyll-admin/server/collections.rb
186
185
  - lib/jekyll-admin/server/configuration.rb
187
186
  - lib/jekyll-admin/server/data.rb
188
- - lib/jekyll-admin/server/draft.rb
189
- - lib/jekyll-admin/server/page.rb
190
- - lib/jekyll-admin/server/static_file.rb
187
+ - lib/jekyll-admin/server/drafts.rb
188
+ - lib/jekyll-admin/server/pages.rb
189
+ - lib/jekyll-admin/server/site_meta.rb
190
+ - lib/jekyll-admin/server/static_files.rb
191
191
  - lib/jekyll-admin/static_server.rb
192
192
  - lib/jekyll-admin/urlable.rb
193
193
  - lib/jekyll-admin/version.rb
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: 2.3.0
209
209
  required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  requirements:
211
211
  - - ">="
@@ -1,7 +0,0 @@
1
- module JekyllAdmin
2
- class PageWithoutAFile < Jekyll::Page
3
- def read_yaml(*)
4
- @data ||= {}
5
- end
6
- end
7
- end
@@ -1,61 +0,0 @@
1
- module JekyllAdmin
2
- class Server < Sinatra::Base
3
- namespace "/static_files" do
4
- get do
5
- json static_files.map(&:to_api)
6
- end
7
-
8
- get "/*" do
9
- if requested_file
10
- json requested_file.to_api(:include_content => true)
11
- elsif !static_files_for_path.empty?
12
- json static_files_for_path.map(&:to_api)
13
- else
14
- render_404
15
- end
16
- end
17
-
18
- put "/*" do
19
- if renamed?
20
- ensure_requested_file
21
- delete_file_without_process path
22
- end
23
-
24
- write_file(write_path, static_file_body)
25
- json written_file.to_api(:include_content => true)
26
- end
27
-
28
- delete "/*" do
29
- ensure_requested_file
30
- delete_file path
31
- content_type :json
32
- status 200
33
- halt
34
- end
35
-
36
- private
37
-
38
- def static_file_body
39
- if !request_payload["raw_content"].to_s.empty?
40
- request_payload["raw_content"].to_s
41
- else
42
- Base64.decode64 request_payload["encoded_content"].to_s
43
- end
44
- end
45
-
46
- def static_files
47
- site.static_files
48
- end
49
-
50
- def file_list_dir(path) end
51
-
52
- def static_files_for_path
53
- # Joined with / to ensure user can't do partial paths
54
- base_path = File.join(path, "/")
55
- static_files.select do |f|
56
- f.path.start_with? base_path
57
- end
58
- end
59
- end
60
- end
61
- end