jekyll-admin 0.8.0 → 0.10.2

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