jekyll-admin 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +50 -50
- data/lib/jekyll-admin.rb +46 -46
- data/lib/jekyll-admin/apiable.rb +163 -162
- data/lib/jekyll-admin/data_file.rb +103 -103
- data/lib/jekyll-admin/directory.rb +74 -73
- data/lib/jekyll-admin/file_helper.rb +77 -78
- data/lib/jekyll-admin/page_without_a_file.rb +7 -7
- data/lib/jekyll-admin/path_helper.rb +80 -78
- data/lib/jekyll-admin/public/{d7c639084f684d66a1bc66855d193ed8.svg → 24c601e721ebd8279d38e2cfa0d01bc6.svg} +684 -684
- data/lib/jekyll-admin/public/bundle.js +14 -77
- data/lib/jekyll-admin/public/bundle.js.map +1 -1
- data/lib/jekyll-admin/public/index.html +13 -12
- data/lib/jekyll-admin/public/styles.css +4 -4
- data/lib/jekyll-admin/public/styles.css.map +1 -1
- data/lib/jekyll-admin/server.rb +99 -101
- data/lib/jekyll-admin/server/collection.rb +82 -82
- data/lib/jekyll-admin/server/configuration.rb +57 -57
- data/lib/jekyll-admin/server/data.rb +82 -82
- data/lib/jekyll-admin/server/draft.rb +109 -110
- data/lib/jekyll-admin/server/page.rb +91 -90
- data/lib/jekyll-admin/server/static_file.rb +61 -61
- data/lib/jekyll-admin/static_server.rb +24 -24
- data/lib/jekyll-admin/urlable.rb +71 -67
- data/lib/jekyll-admin/version.rb +3 -3
- data/lib/jekyll/commands/serve.rb +28 -28
- metadata +24 -33
@@ -1,103 +1,103 @@
|
|
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
|
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
|
+
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,73 +1,74 @@
|
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
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
|
+
|
67
|
+
self.class.new(
|
68
|
+
path.join(entry),
|
69
|
+
:base => base, :content_type => content_type, :splat => splat
|
70
|
+
)
|
71
|
+
end.compact!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,78 +1,77 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
module FileHelper
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
end
|
1
|
+
module JekyllAdmin
|
2
|
+
module FileHelper
|
3
|
+
# The file the user requested in the URL
|
4
|
+
def requested_file
|
5
|
+
find_by_path(path)
|
6
|
+
end
|
7
|
+
|
8
|
+
# The file ultimately written to disk
|
9
|
+
# This may be the requested file, or in the case of a rename will be read
|
10
|
+
# from the new path that was actually written to disk
|
11
|
+
def written_file
|
12
|
+
find_by_path(write_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Write a file to disk with the given content
|
16
|
+
def write_file(path, content)
|
17
|
+
Jekyll.logger.debug "WRITING:", path
|
18
|
+
path = sanitized_path(path)
|
19
|
+
FileUtils.mkdir_p File.dirname(path)
|
20
|
+
File.open(path, "wb") do |file|
|
21
|
+
file.write(content)
|
22
|
+
end
|
23
|
+
# we should fully process in dev mode for tests to pass
|
24
|
+
if ENV["RACK_ENV"] == "production"
|
25
|
+
site.read
|
26
|
+
else
|
27
|
+
site.process
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delete the file at the given path
|
32
|
+
def delete_file(path)
|
33
|
+
Jekyll.logger.debug "DELETING:", path
|
34
|
+
FileUtils.rm_f sanitized_path(path)
|
35
|
+
site.process
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_file_without_process(path)
|
39
|
+
Jekyll.logger.debug "DELETING:", path
|
40
|
+
FileUtils.rm_f sanitized_path(path)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def ensure_requested_file
|
46
|
+
ensure_file(requested_file)
|
47
|
+
end
|
48
|
+
|
49
|
+
def ensure_written_file
|
50
|
+
ensure_file(written_file)
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_by_path(path)
|
54
|
+
files = case namespace
|
55
|
+
when "collections"
|
56
|
+
collection.docs
|
57
|
+
when "data"
|
58
|
+
DataFile.all
|
59
|
+
when "drafts"
|
60
|
+
drafts
|
61
|
+
when "pages", "static_files"
|
62
|
+
site.public_send(namespace.to_sym)
|
63
|
+
else
|
64
|
+
[]
|
65
|
+
end
|
66
|
+
files.find { |f| sanitized_path(f.path) == path }
|
67
|
+
end
|
68
|
+
|
69
|
+
def ensure_file(file)
|
70
|
+
render_404 if file.nil?
|
71
|
+
end
|
72
|
+
|
73
|
+
def ensure_directory
|
74
|
+
render_404 unless Dir.exist?(directory_path)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|