jekyll-admin 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +21 -21
  3. data/README.md +94 -94
  4. data/lib/jekyll-admin.rb +47 -47
  5. data/lib/jekyll-admin/apiable.rb +224 -224
  6. data/lib/jekyll-admin/data_file.rb +106 -106
  7. data/lib/jekyll-admin/directory.rb +72 -72
  8. data/lib/jekyll-admin/file_helper.rb +91 -91
  9. data/lib/jekyll-admin/path_helper.rb +87 -87
  10. data/lib/jekyll-admin/public/asset-manifest.json +27 -0
  11. data/lib/jekyll-admin/public/index.html +1 -13
  12. data/lib/jekyll-admin/public/precache-manifest.52de67482747a1012d0d27a209b930d0.js +78 -0
  13. data/lib/jekyll-admin/public/service-worker.js +39 -0
  14. data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css +2 -0
  15. data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css.map +1 -0
  16. data/lib/jekyll-admin/public/static/css/main.223e267c.chunk.css +5 -0
  17. data/lib/jekyll-admin/public/static/css/main.223e267c.chunk.css.map +1 -0
  18. data/lib/jekyll-admin/public/static/js/2.49911da2.chunk.js +3 -0
  19. data/lib/jekyll-admin/public/static/js/2.49911da2.chunk.js.LICENSE.txt +67 -0
  20. data/lib/jekyll-admin/public/static/js/2.49911da2.chunk.js.map +1 -0
  21. data/lib/jekyll-admin/public/static/js/main.dd81e877.chunk.js +2 -0
  22. data/lib/jekyll-admin/public/static/js/main.dd81e877.chunk.js.map +1 -0
  23. data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js +2 -0
  24. data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js.map +1 -0
  25. data/lib/jekyll-admin/public/{1dc35d25e61d819a9c357074014867ab.ttf → static/media/fontawesome-webfont.1dc35d25.ttf} +0 -0
  26. data/lib/jekyll-admin/public/{25a32416abee198dd821b0b17a198a8f.eot → static/media/fontawesome-webfont.25a32416.eot} +0 -0
  27. data/lib/jekyll-admin/public/{c8ddf1e5e5bf3682bc7bebf30f394148.woff → static/media/fontawesome-webfont.c8ddf1e5.woff} +0 -0
  28. data/lib/jekyll-admin/public/{24c601e721ebd8279d38e2cfa0d01bc6.svg → static/media/fontawesome-webfont.d7c63908.svg} +684 -684
  29. data/lib/jekyll-admin/public/{e6cf7c6ec7c2d6f670ae9d762604cb0b.woff2 → static/media/fontawesome-webfont.e6cf7c6e.woff2} +0 -0
  30. data/lib/jekyll-admin/public/{55131026930a0cd4539d1e2fdb92722d.ttf → static/media/lato-bold.55131026.ttf} +0 -0
  31. data/lib/jekyll-admin/public/{059514c92565e4045da1a69525dd9ec0.ttf → static/media/lato-regular.059514c9.ttf} +0 -0
  32. data/lib/jekyll-admin/public/{a770b6797b68e3f8920e473eb824bac0.gif → static/media/loader-big.a770b679.gif} +0 -0
  33. data/lib/jekyll-admin/public/{12f0820c451bdc75f4d1ef97732bf6e8.woff → static/media/rw-widgets.12f0820c.woff} +0 -0
  34. data/lib/jekyll-admin/public/{792dcd18baf5f544aabcad1883d673c2.svg → static/media/rw-widgets.792dcd18.svg} +0 -0
  35. data/lib/jekyll-admin/public/{bc7c4a59f924cf037aad6e1f9edba366.eot → static/media/rw-widgets.bc7c4a59.eot} +0 -0
  36. data/lib/jekyll-admin/public/{eceddf474df95d8d4a7e316668c3be85.ttf → static/media/rw-widgets.eceddf47.ttf} +0 -0
  37. data/lib/jekyll-admin/server.rb +108 -108
  38. data/lib/jekyll-admin/server/collections.rb +89 -89
  39. data/lib/jekyll-admin/server/configuration.rb +60 -60
  40. data/lib/jekyll-admin/server/data.rb +84 -84
  41. data/lib/jekyll-admin/server/drafts.rb +114 -114
  42. data/lib/jekyll-admin/server/pages.rb +109 -109
  43. data/lib/jekyll-admin/server/site_meta.rb +25 -25
  44. data/lib/jekyll-admin/server/static_files.rb +83 -83
  45. data/lib/jekyll-admin/static_server.rb +26 -26
  46. data/lib/jekyll-admin/urlable.rb +75 -75
  47. data/lib/jekyll-admin/version.rb +5 -5
  48. data/lib/jekyll/commands/serve.rb +30 -30
  49. metadata +30 -22
  50. data/lib/jekyll-admin/public/33a752211d05af6684e26ec63c2ed965.gif +0 -0
  51. data/lib/jekyll-admin/public/8b4968b70019a0551a72940c5a2020d3.png +0 -0
  52. data/lib/jekyll-admin/public/8ea28ca3bfdf27145068e81dd07a34c6.png +0 -0
  53. data/lib/jekyll-admin/public/bundle.js +0 -64
  54. data/lib/jekyll-admin/public/bundle.js.map +0 -1
  55. data/lib/jekyll-admin/public/styles.css +0 -106
  56. data/lib/jekyll-admin/public/styles.css.map +0 -1
@@ -1,106 +1,106 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class DataFile
5
- METHODS_FOR_LIQUID = %w(name path relative_path slug ext title).freeze
6
- EXTENSIONS = %w(yaml yml json csv).freeze
7
-
8
- include APIable
9
- include URLable
10
- include PathHelper
11
- extend PathHelper
12
-
13
- attr_reader :id, :ext
14
-
15
- # Initialize a new DataFile object
16
- #
17
- # id - the file ID as passed from the API. This may or may not have an extension
18
- def initialize(id)
19
- extname = File.extname(id)
20
- if extname.empty?
21
- @id = "#{id}.yml"
22
- @ext = ".yml"
23
- else
24
- @id = id
25
- @ext = extname
26
- end
27
- end
28
- alias_method :relative_path, :id
29
-
30
- # Returns the file's extension with preceeding `.`
31
- alias_method :extension, :ext
32
-
33
- def exists?
34
- @exists ||= File.exist?(absolute_path)
35
- end
36
-
37
- # Returns unparsed content as it exists on disk
38
- def raw_content
39
- @raw_content ||= File.open(absolute_path, "r:UTF-8", &:read)
40
- end
41
-
42
- # Returnes (re)parsed content using Jekyll's native parsing mechanism
43
- def content
44
- @content ||= data_reader.read_data_file(absolute_path)
45
- end
46
-
47
- # Returns the file's sanitized slug (as used in `site.data[slug]`)
48
- def slug
49
- @slug ||= data_reader.sanitize_filename(basename)
50
- end
51
-
52
- # Returns the human-readable title of the data file
53
- def title
54
- @title ||= Jekyll::Utils.titleize_slug(slug.tr("_", "-"))
55
- end
56
-
57
- # Returns path relative to site source
58
- def path
59
- @path ||= File.join(DataFile.data_dir, relative_path)
60
- end
61
-
62
- def absolute_path
63
- sanitized_path(path)
64
- end
65
- alias_method :file_path, :absolute_path
66
-
67
- # Mimics Jekyll's native to_liquid functionality by returning a hash
68
- # of data file metadata
69
- def to_liquid
70
- @to_liquid ||= METHODS_FOR_LIQUID.map { |key| [key, public_send(key)] }.to_h
71
- end
72
-
73
- def self.all
74
- data_dir = Jekyll.sanitized_path(JekyllAdmin.site.source, DataFile.data_dir)
75
- data_dir = Pathname.new(data_dir)
76
- Dir["#{data_dir}/**/*.{#{EXTENSIONS.join(",")}}"].map do |path|
77
- new(Pathname.new(path).relative_path_from(data_dir).to_s)
78
- end
79
- end
80
-
81
- # Relative path to data directory within site source
82
- def self.data_dir
83
- JekyllAdmin.site.config["data_dir"]
84
- end
85
-
86
- private
87
-
88
- def data_reader
89
- @data_reader = Jekyll::DataReader.new(JekyllAdmin.site)
90
- end
91
-
92
- def basename
93
- @basename ||= File.basename(id, ".*")
94
- end
95
-
96
- def basename_with_extension
97
- "#{basename}#{extension}"
98
- end
99
- alias_method :name, :basename_with_extension
100
- public :name
101
-
102
- def namespace
103
- "data"
104
- end
105
- end
106
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class DataFile
5
+ METHODS_FOR_LIQUID = %w(name path relative_path slug ext title).freeze
6
+ EXTENSIONS = %w(yaml yml json csv).freeze
7
+
8
+ include APIable
9
+ include URLable
10
+ include PathHelper
11
+ extend PathHelper
12
+
13
+ attr_reader :id, :ext
14
+
15
+ # Initialize a new DataFile object
16
+ #
17
+ # id - the file ID as passed from the API. This may or may not have an extension
18
+ def initialize(id)
19
+ extname = File.extname(id)
20
+ if extname.empty?
21
+ @id = "#{id}.yml"
22
+ @ext = ".yml"
23
+ else
24
+ @id = id
25
+ @ext = extname
26
+ end
27
+ end
28
+ alias_method :relative_path, :id
29
+
30
+ # Returns the file's extension with preceeding `.`
31
+ alias_method :extension, :ext
32
+
33
+ def exists?
34
+ @exists ||= File.exist?(absolute_path)
35
+ end
36
+
37
+ # Returns unparsed content as it exists on disk
38
+ def raw_content
39
+ @raw_content ||= File.open(absolute_path, "r:UTF-8", &:read)
40
+ end
41
+
42
+ # Returnes (re)parsed content using Jekyll's native parsing mechanism
43
+ def content
44
+ @content ||= data_reader.read_data_file(absolute_path)
45
+ end
46
+
47
+ # Returns the file's sanitized slug (as used in `site.data[slug]`)
48
+ def slug
49
+ @slug ||= data_reader.sanitize_filename(basename)
50
+ end
51
+
52
+ # Returns the human-readable title of the data file
53
+ def title
54
+ @title ||= Jekyll::Utils.titleize_slug(slug.tr("_", "-"))
55
+ end
56
+
57
+ # Returns path relative to site source
58
+ def path
59
+ @path ||= File.join(DataFile.data_dir, relative_path)
60
+ end
61
+
62
+ def absolute_path
63
+ sanitized_path(path)
64
+ end
65
+ alias_method :file_path, :absolute_path
66
+
67
+ # Mimics Jekyll's native to_liquid functionality by returning a hash
68
+ # of data file metadata
69
+ def to_liquid
70
+ @to_liquid ||= METHODS_FOR_LIQUID.map { |key| [key, public_send(key)] }.to_h
71
+ end
72
+
73
+ def self.all
74
+ data_dir = Jekyll.sanitized_path(JekyllAdmin.site.source, DataFile.data_dir)
75
+ data_dir = Pathname.new(data_dir)
76
+ Dir["#{data_dir}/**/*.{#{EXTENSIONS.join(",")}}"].map do |path|
77
+ new(Pathname.new(path).relative_path_from(data_dir).to_s)
78
+ end
79
+ end
80
+
81
+ # Relative path to data directory within site source
82
+ def self.data_dir
83
+ JekyllAdmin.site.config["data_dir"]
84
+ end
85
+
86
+ private
87
+
88
+ def data_reader
89
+ @data_reader = Jekyll::DataReader.new(JekyllAdmin.site)
90
+ end
91
+
92
+ def basename
93
+ @basename ||= File.basename(id, ".*")
94
+ end
95
+
96
+ def basename_with_extension
97
+ "#{basename}#{extension}"
98
+ end
99
+ alias_method :name, :basename_with_extension
100
+ public :name
101
+
102
+ def namespace
103
+ "data"
104
+ end
105
+ end
106
+ end
@@ -1,72 +1,72 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Directory
5
- extend Forwardable
6
- def_delegator :@path, :basename, :name
7
- def_delegator :@path, :mtime, :modified_time
8
- attr_reader :path, :splat, :content_type, :base
9
-
10
- include Enumerable
11
- include JekyllAdmin::URLable
12
- include JekyllAdmin::APIable
13
-
14
- RESOURCE_TYPES = %w(pages data drafts static_files).freeze
15
- DOT_DIRECTORIES = [".", ".."].freeze
16
-
17
- private_constant :RESOURCE_TYPES, :DOT_DIRECTORIES
18
-
19
- # Parameters:
20
- # path - The full path of the directory at which its entries will be listed.
21
- #
22
- # Named parameters:
23
- # base: - The full path to the directory from source.
24
- # splat: - The requested directory path relative to content namespace.
25
- # content_type: - The type of the requested directory entries. Corresponds to
26
- # the resources' API namespace.
27
- def initialize(path, base:, splat:, content_type:)
28
- @path = Pathname.new path
29
- @base = Pathname.new base
30
- @splat = Pathname.new splat
31
- @content_type = content_type
32
- end
33
-
34
- def to_liquid
35
- {
36
- "name" => name,
37
- "modified_time" => modified_time,
38
- "path" => relative_path,
39
- "type" => "directory",
40
- }
41
- end
42
-
43
- def relative_path
44
- @relative_path ||= path.relative_path_from(base).to_s
45
- end
46
-
47
- def resource_path
48
- if RESOURCE_TYPES.include?(content_type)
49
- "/#{content_type}/#{splat}/#{name}"
50
- else
51
- "/collections/#{content_type}/entries/#{splat}/#{name}"
52
- end
53
- end
54
- alias_method :url, :resource_path
55
-
56
- def http_url
57
- nil
58
- end
59
-
60
- def directories
61
- path.entries.map do |entry|
62
- next if DOT_DIRECTORIES.include? entry.to_s
63
- next unless path.join(entry).directory?
64
-
65
- self.class.new(
66
- path.join(entry),
67
- :base => base, :content_type => content_type, :splat => splat
68
- )
69
- end.compact!
70
- end
71
- end
72
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Directory
5
+ extend Forwardable
6
+ def_delegator :@path, :basename, :name
7
+ def_delegator :@path, :mtime, :modified_time
8
+ attr_reader :path, :splat, :content_type, :base
9
+
10
+ include Enumerable
11
+ include JekyllAdmin::URLable
12
+ include JekyllAdmin::APIable
13
+
14
+ RESOURCE_TYPES = %w(pages data drafts static_files).freeze
15
+ DOT_DIRECTORIES = [".", ".."].freeze
16
+
17
+ private_constant :RESOURCE_TYPES, :DOT_DIRECTORIES
18
+
19
+ # Parameters:
20
+ # path - The full path of the directory at which its entries will be listed.
21
+ #
22
+ # Named parameters:
23
+ # base: - The full path to the directory from source.
24
+ # splat: - The requested directory path relative to content namespace.
25
+ # content_type: - The type of the requested directory entries. Corresponds to
26
+ # the resources' API namespace.
27
+ def initialize(path, base:, splat:, content_type:)
28
+ @path = Pathname.new path
29
+ @base = Pathname.new base
30
+ @splat = Pathname.new splat
31
+ @content_type = content_type
32
+ end
33
+
34
+ def to_liquid
35
+ {
36
+ "name" => name,
37
+ "modified_time" => modified_time,
38
+ "path" => relative_path,
39
+ "type" => "directory",
40
+ }
41
+ end
42
+
43
+ def relative_path
44
+ @relative_path ||= path.relative_path_from(base).to_s
45
+ end
46
+
47
+ def resource_path
48
+ if RESOURCE_TYPES.include?(content_type)
49
+ "/#{content_type}/#{splat}/#{name}"
50
+ else
51
+ "/collections/#{content_type}/entries/#{splat}/#{name}"
52
+ end
53
+ end
54
+ alias_method :url, :resource_path
55
+
56
+ def http_url
57
+ nil
58
+ end
59
+
60
+ def directories
61
+ path.entries.map do |entry|
62
+ next if DOT_DIRECTORIES.include? entry.to_s
63
+ next unless path.join(entry).directory?
64
+
65
+ self.class.new(
66
+ path.join(entry),
67
+ :base => base, :content_type => content_type, :splat => splat
68
+ )
69
+ end.compact!
70
+ end
71
+ end
72
+ end
@@ -1,91 +1,91 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- module FileHelper
5
- # The file the user requested in the URL
6
- def requested_file
7
- find_by_path(path)
8
- end
9
-
10
- # The file ultimately written to disk
11
- # This may be the requested file, or in the case of a rename will be read
12
- # from the new path that was actually written to disk
13
- def written_file
14
- find_by_path(write_path)
15
- end
16
-
17
- # Write a file to disk with the given content
18
- def write_file(path, content)
19
- Jekyll.logger.debug "WRITING:", path
20
- path = sanitized_path(path)
21
- FileUtils.mkdir_p File.dirname(path)
22
- File.open(path, "wb") do |file|
23
- file.write(content)
24
- end
25
- # we should fully process in dev mode for tests to pass
26
- if ENV["RACK_ENV"] == "production"
27
- site.read
28
- else
29
- site.process
30
- end
31
- end
32
-
33
- # Delete the file at the given path
34
- def delete_file(path)
35
- Jekyll.logger.debug "DELETING:", path
36
- FileUtils.rm_f sanitized_path(path)
37
- site.process
38
- end
39
-
40
- def delete_file_without_process(path)
41
- Jekyll.logger.debug "DELETING:", path
42
- FileUtils.rm_f sanitized_path(path)
43
- end
44
-
45
- private
46
-
47
- def ensure_requested_file
48
- ensure_file(requested_file)
49
- end
50
-
51
- def ensure_written_file
52
- ensure_file(written_file)
53
- end
54
-
55
- def ensure_not_overwriting_existing_file
56
- ensure_not_file(written_file)
57
- end
58
-
59
- def find_by_path(path)
60
- files = case namespace
61
- when "collections"
62
- collection.docs
63
- when "data"
64
- DataFile.all
65
- when "drafts"
66
- drafts
67
- when "pages", "static_files"
68
- site.public_send(namespace.to_sym)
69
- else
70
- []
71
- end
72
- files.find { |f| sanitized_path(f.path) == path }
73
- end
74
-
75
- def ensure_file(file)
76
- render_404 if file.nil?
77
- end
78
-
79
- def ensure_not_file(file)
80
- return if file.nil?
81
-
82
- Jekyll.logger.warn "Jekyll Admin:", "Could not create file."
83
- Jekyll.logger.warn "", "Path #{file.relative_path.inspect} already exists!"
84
- render_404
85
- end
86
-
87
- def ensure_directory
88
- render_404 unless Dir.exist?(directory_path)
89
- end
90
- end
91
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ module FileHelper
5
+ # The file the user requested in the URL
6
+ def requested_file
7
+ find_by_path(path)
8
+ end
9
+
10
+ # The file ultimately written to disk
11
+ # This may be the requested file, or in the case of a rename will be read
12
+ # from the new path that was actually written to disk
13
+ def written_file
14
+ find_by_path(write_path)
15
+ end
16
+
17
+ # Write a file to disk with the given content
18
+ def write_file(path, content)
19
+ Jekyll.logger.debug "WRITING:", path
20
+ path = sanitized_path(path)
21
+ FileUtils.mkdir_p File.dirname(path)
22
+ File.open(path, "wb") do |file|
23
+ file.write(content)
24
+ end
25
+ # we should fully process in dev mode for tests to pass
26
+ if ENV["RACK_ENV"] == "production"
27
+ site.read
28
+ else
29
+ site.process
30
+ end
31
+ end
32
+
33
+ # Delete the file at the given path
34
+ def delete_file(path)
35
+ Jekyll.logger.debug "DELETING:", path
36
+ FileUtils.rm_f sanitized_path(path)
37
+ site.process
38
+ end
39
+
40
+ def delete_file_without_process(path)
41
+ Jekyll.logger.debug "DELETING:", path
42
+ FileUtils.rm_f sanitized_path(path)
43
+ end
44
+
45
+ private
46
+
47
+ def ensure_requested_file
48
+ ensure_file(requested_file)
49
+ end
50
+
51
+ def ensure_written_file
52
+ ensure_file(written_file)
53
+ end
54
+
55
+ def ensure_not_overwriting_existing_file
56
+ ensure_not_file(written_file)
57
+ end
58
+
59
+ def find_by_path(path)
60
+ files = case namespace
61
+ when "collections"
62
+ collection.docs
63
+ when "data"
64
+ DataFile.all
65
+ when "drafts"
66
+ drafts
67
+ when "pages", "static_files"
68
+ site.public_send(namespace.to_sym)
69
+ else
70
+ []
71
+ end
72
+ files.find { |f| sanitized_path(f.path) == path }
73
+ end
74
+
75
+ def ensure_file(file)
76
+ render_404 if file.nil?
77
+ end
78
+
79
+ def ensure_not_file(file)
80
+ return if file.nil?
81
+
82
+ Jekyll.logger.warn "Jekyll Admin:", "Could not create file."
83
+ Jekyll.logger.warn "", "Path #{file.relative_path.inspect} already exists!"
84
+ render_404
85
+ end
86
+
87
+ def ensure_directory
88
+ render_404 unless Dir.exist?(directory_path)
89
+ end
90
+ end
91
+ end