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.
- checksums.yaml +5 -5
- data/LICENSE +21 -21
- data/README.md +94 -54
- data/lib/jekyll-admin.rb +47 -46
- data/lib/jekyll-admin/apiable.rb +224 -162
- data/lib/jekyll-admin/data_file.rb +106 -103
- data/lib/jekyll-admin/directory.rb +72 -73
- data/lib/jekyll-admin/file_helper.rb +91 -78
- data/lib/jekyll-admin/path_helper.rb +87 -78
- data/lib/jekyll-admin/public/asset-manifest.json +27 -0
- data/lib/jekyll-admin/public/index.html +1 -12
- data/lib/jekyll-admin/public/precache-manifest.5e08ed7edb8d446719b76ae6ead9e3fe.js +78 -0
- data/lib/jekyll-admin/public/service-worker.js +39 -0
- data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css +2 -0
- data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css.map +1 -0
- data/lib/jekyll-admin/public/static/css/main.7e0a6705.chunk.css +5 -0
- data/lib/jekyll-admin/public/static/css/main.7e0a6705.chunk.css.map +1 -0
- data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js +3 -0
- data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js.LICENSE.txt +67 -0
- data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js.map +1 -0
- data/lib/jekyll-admin/public/static/js/main.f3346e4e.chunk.js +2 -0
- data/lib/jekyll-admin/public/static/js/main.f3346e4e.chunk.js.map +1 -0
- data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js +2 -0
- data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js.map +1 -0
- data/lib/jekyll-admin/public/{1dc35d25e61d819a9c357074014867ab.ttf → static/media/fontawesome-webfont.1dc35d25.ttf} +0 -0
- data/lib/jekyll-admin/public/{d7c639084f684d66a1bc66855d193ed8.svg → static/media/fontawesome-webfont.24c601e7.svg} +684 -684
- data/lib/jekyll-admin/public/{25a32416abee198dd821b0b17a198a8f.eot → static/media/fontawesome-webfont.25a32416.eot} +0 -0
- data/lib/jekyll-admin/public/{c8ddf1e5e5bf3682bc7bebf30f394148.woff → static/media/fontawesome-webfont.c8ddf1e5.woff} +0 -0
- data/lib/jekyll-admin/public/{e6cf7c6ec7c2d6f670ae9d762604cb0b.woff2 → static/media/fontawesome-webfont.e6cf7c6e.woff2} +0 -0
- data/lib/jekyll-admin/public/{55131026930a0cd4539d1e2fdb92722d.ttf → static/media/lato-bold.55131026.ttf} +0 -0
- data/lib/jekyll-admin/public/{059514c92565e4045da1a69525dd9ec0.ttf → static/media/lato-regular.059514c9.ttf} +0 -0
- data/lib/jekyll-admin/public/{a770b6797b68e3f8920e473eb824bac0.gif → static/media/loader-big.a770b679.gif} +0 -0
- data/lib/jekyll-admin/public/static/media/rw-widgets.12f0820c.woff +0 -0
- data/lib/jekyll-admin/public/{03945ac4fc7fdefc44bc110bf1ba2393.svg → static/media/rw-widgets.792dcd18.svg} +14 -8
- data/lib/jekyll-admin/public/{e44520ab9079ea7633bfa874bed5d21d.eot → static/media/rw-widgets.bc7c4a59.eot} +0 -0
- data/lib/jekyll-admin/public/{bfc14ac982326f7d0b1340e20d3e0c37.ttf → static/media/rw-widgets.eceddf47.ttf} +0 -0
- data/lib/jekyll-admin/server.rb +108 -101
- data/lib/jekyll-admin/server/{collection.rb → collections.rb} +89 -82
- data/lib/jekyll-admin/server/configuration.rb +60 -57
- data/lib/jekyll-admin/server/data.rb +84 -82
- data/lib/jekyll-admin/server/{draft.rb → drafts.rb} +114 -110
- data/lib/jekyll-admin/server/{page.rb → pages.rb} +109 -90
- data/lib/jekyll-admin/server/site_meta.rb +25 -0
- data/lib/jekyll-admin/server/static_files.rb +83 -0
- data/lib/jekyll-admin/static_server.rb +26 -24
- data/lib/jekyll-admin/urlable.rb +75 -67
- data/lib/jekyll-admin/version.rb +5 -3
- data/lib/jekyll/commands/serve.rb +30 -24
- metadata +57 -59
- data/lib/jekyll-admin/page_without_a_file.rb +0 -7
- data/lib/jekyll-admin/public/33a752211d05af6684e26ec63c2ed965.gif +0 -0
- data/lib/jekyll-admin/public/8b4968b70019a0551a72940c5a2020d3.png +0 -0
- data/lib/jekyll-admin/public/8ea28ca3bfdf27145068e81dd07a34c6.png +0 -0
- data/lib/jekyll-admin/public/99adb54b0f30c0758bb4cb9ed5b80aa8.woff +0 -0
- data/lib/jekyll-admin/public/bundle.js +0 -117
- data/lib/jekyll-admin/public/bundle.js.map +0 -1
- data/lib/jekyll-admin/public/styles.css +0 -5
- data/lib/jekyll-admin/public/styles.css.map +0 -1
- data/lib/jekyll-admin/server/static_file.rb +0 -61
@@ -1,103 +1,106 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
include
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
include
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@path
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
"/#{content_type}/#{splat}/#{name}"
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
File.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|