-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfile_tree.cr
More file actions
62 lines (55 loc) · 2.21 KB
/
file_tree.cr
File metadata and controls
62 lines (55 loc) · 2.21 KB
1
2
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
module Teeplate
# Collects template files from a local directory.
abstract class FileTree
# Collects and embeds template files.
#
# It runs another macro process that collects template files and embeds the files as code.
macro directory(dir)
{{ run(__DIR__ + "/file_tree/macros/directory", dir.id) }}
end
@file_entries : Array(AsDataEntry)?
# Returns collected file entries.
def file_entries : Array(AsDataEntry)
@file_entries ||= begin
files = [] of AsDataEntry
____collect_files files
files
end
end
# Renders all collected file entries.
#
# For more information about the arguments, see `Renderer`.
def render(out_dir, force : Bool = false, interactive : Bool = false, interact : Bool = false, list : Bool = false, color : Bool = false, per_entry : Bool = false, quit : Bool = true)
renderer = Renderer.new(out_dir, force: force, interact: interactive || interact, list: list, color: color, per_entry: per_entry, quit: quit)
renderer << rendered_file_entries
renderer.render
renderer
end
# Destroy the rendered files.
def destroy(out_dir, force : Bool = false, interactive : Bool = false, interact : Bool = false, list : Bool = false, color : Bool = false, per_entry : Bool = false, quit : Bool = true)
renderer = Renderer.new(out_dir, force: force, interact: interactive || interact, list: list, color: color, per_entry: per_entry, quit: quit)
renderer << destroy_file_entries
renderer.destroy
renderer
end
# Returns file entries to be rendered.
#
# This method just returns the `#file_entries` method's result. To filter entries, override this method.
def rendered_file_entries
file_entries
end
# :nodoc:
def destroy_file_entries
file_entries
end
# :nodoc:
def ____collect_files(files)
end
# Collects file entries from the *dir* directory.
def collect_from(dir, unique = false, relative_dir = nil)
FileEntryCollector.new(File.expand_path(dir, Dir.current), relative_dir: relative_dir).entries.each do |entry|
file_entries << entry unless file_entries.find{|i| i.path == entry.path}
end
end
end
end