Skip to content

Commit 4c1e2db

Browse files
committed
moon_json: source directories
1 parent 889201d commit 4c1e2db

File tree

1 file changed

+59
-11
lines changed

1 file changed

+59
-11
lines changed

src/moon_json/source_directories.cr

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,76 @@ module MoonScript
2828
directories << parse_source_directory
2929
end
3030

31-
error! :source_directory_empty do
31+
error! :source_directories_empty do
32+
block do
33+
text "The"
34+
bold "source-directories"
35+
text "field lists all directories reative to moon.json"
36+
text "which contain the source files"
37+
end
38+
39+
block do
40+
text "The"
41+
bold "source-directories"
42+
text "array should not be empty: "
43+
end
44+
45+
snippet snippet_data(location)
46+
end if directories.empty?
47+
48+
directories
49+
end
50+
rescue JSON::ParseException
51+
error! :source_directories_invalid do
52+
block do
53+
text "The"
54+
bold "source-directories"
55+
text "field lists all directories relative to moon.json"
56+
text "which contain the source files"
3257
end
3358

3459
block do
60+
text "The"
61+
bold "source-directories"
62+
text "field should be an array: "
3563
end
3664

37-
snippet snippet_data(location)
65+
snippet snippet_data
3866
end
3967
end
4068

41-
def parse_source_directory: String
42-
location = @parser.location
43-
directory = @parser.read_string
44-
path = Path[root, directory]
69+
def parse_source_directory : String
70+
location =
71+
@parser.location
72+
73+
directory =
74+
@parser.read_string
75+
76+
path =
77+
Path[root, directory]
4578

4679
error! :source_directory_not_exists do
47-
end
80+
block do
81+
text "The source directory"
82+
bold directory
83+
text "does not exists:"
84+
end
4885

49-
snippet snippet_data(location)
50-
end unless Dir.exists?(path)
51-
end
52-
directory
86+
snippet snippet_data(location)
87+
end unless Dir.exists?(path)
5388

89+
directory
90+
rescue JSON::ParseException
91+
error! :source_directory_invalid do
92+
block do
93+
text "All entries in the"
94+
bold "source-directories"
95+
text "array should be string"
96+
end
97+
98+
snippet snippet_data
99+
end
100+
end
101+
end
54102
end
55103
end

0 commit comments

Comments
 (0)