Skip to content

Commit 170fcf5

Browse files
committed
moon_json: application
1 parent 5c27c32 commit 170fcf5

File tree

1 file changed

+66
-15
lines changed

1 file changed

+66
-15
lines changed

src/moon_json/application.cr

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,73 @@
1818
# -----------------------------------------------------------------------
1919

2020
module MoonScript
21-
class MoonScript
22-
class Parser
23-
def parse_application: Application
24-
meta = {} of String => String
25-
orientation = ""
26-
theme_color = ""
27-
css_prefix = ""
28-
display = ""
29-
name = ""
30-
icon = ""
21+
class MoonJson
22+
class Parser
23+
def parse_application : Application
24+
meta = {} of String => String
25+
orientation = ""
26+
theme_color = ""
27+
css_prefix = ""
28+
display = ""
29+
title = ""
30+
name = ""
31+
icon = ""
32+
head = ""
3133

32-
@parser.read_object do |key|
33-
case key
34-
end
35-
end
34+
@parser.read_object do |key|
35+
case key
36+
when "orientation"
37+
orientation = parse_application_orientation
38+
when "theme-color"
39+
theme_color = parse_application_theme_color
40+
when "css-prefix"
41+
css_prefix = parse_application_css_prefix
42+
when "display"
43+
display = parse_application_display
44+
when "title"
45+
title = parse_application_title
46+
when "head"
47+
head = parse_application_head
48+
when "icon"
49+
icon = parse_application_icon
50+
when "meta"
51+
meta = parse_application_meta
52+
when "name"
53+
name = parse_application_name
54+
else
55+
error! :application_invalid_key do
56+
block do
57+
text "The"
58+
bold "application object has an invalid key: "
59+
end
60+
61+
snippet key
62+
snippet "It is here:", snippet_data
3663
end
64+
end
65+
end
66+
67+
Application.new(
68+
theme_color: theme_color,
69+
orientation: orientation,
70+
css_prefix: css_prefix,
71+
display: display,
72+
title: title,
73+
meta: meta,
74+
icon: icon,
75+
head: head,
76+
name: name)
77+
rescue JSON::ParseException
78+
error! :application_invalid do
79+
block do
80+
text "The"
81+
bold "application field"
82+
text "should be an object"
83+
end
84+
85+
snippet snippet_data
3786
end
87+
end
3888
end
39-
end
89+
end
90+
end

0 commit comments

Comments
 (0)