Skip to content

Commit 0828f6a

Browse files
committed
moon_json: applications[orientation]
1 parent df57679 commit 0828f6a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -----------------------------------------------------------------------
2+
# This file is part of MoonScript
3+
#
4+
# MoonSript is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# MoonSript is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with MoonSript. If not, see <https://www.gnu.org/licenses/>.
16+
#
17+
# Copyright (C) 2025 Krisna Pranav, MoonScript Developers
18+
# -----------------------------------------------------------------------
19+
20+
module MoonScript
21+
class MoonJson
22+
class Parser
23+
ORIENTATION_VALUES =
24+
%w[
25+
any natural landscape landscape-primary
26+
landscape-secondary portrait portrait-primary
27+
portrait-secondary
28+
]
29+
30+
def parse_application_orientation : String
31+
@parser.location.try do |location|
32+
@parser.read_string.tap do |value|
33+
error! :application_orientation_mismatch do
34+
block do
35+
text "The"
36+
bold "value"
37+
text "of the"
38+
bold "orientation should be off"
39+
end
40+
41+
snippet ORIENTATION_VALUES.join("\n")
42+
snippet "It is here:", snippet_data(location)
43+
end unless ORIENTATION_VALUES.includes?(value)
44+
end
45+
end
46+
rescue JSON::ParseException
47+
error! :application_orientation_invalid do
48+
block do
49+
text "The"
50+
bold "orientation field"
51+
text "of the"
52+
bold "application object should be string"
53+
end
54+
55+
snippet snippet_data
56+
end
57+
end
58+
end
59+
end
60+
end

0 commit comments

Comments
 (0)