@@ -16,15 +16,15 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
16
16
let chapters = c. navigate ( rc. get_path ( ) , "chapters" ) ;
17
17
18
18
let current = c. navigate ( rc. get_path ( ) , "path" )
19
- . to_string ( )
20
- . replace ( "\" " , "" ) ;
19
+ . to_string ( )
20
+ . replace ( "\" " , "" ) ;
21
21
22
22
23
23
debug ! ( "[*]: Decode chapters from JSON" ) ;
24
24
// Decode json format
25
25
let decoded: Vec < BTreeMap < String , String > > = match json:: decode ( & chapters. to_string ( ) ) {
26
26
Ok ( data) => data,
27
- Err ( _) => return Err ( RenderError { desc : "Could not decode the JSON data" . to_owned ( ) } ) ,
27
+ Err ( _) => return Err ( RenderError :: new ( "Could not decode the JSON data" ) ) ,
28
28
} ;
29
29
let mut previous: Option < BTreeMap < String , String > > = None ;
30
30
@@ -52,7 +52,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
52
52
} ,
53
53
None => {
54
54
debug ! ( "[*]: No title found for chapter" ) ;
55
- return Err ( RenderError { desc : "No title found for chapter in JSON data" . to_owned ( ) } ) ;
55
+ return Err ( RenderError :: new ( "No title found for chapter in JSON data" ) ) ;
56
56
} ,
57
57
} ;
58
58
@@ -68,16 +68,10 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
68
68
Some ( p) => {
69
69
previous_chapter. insert ( "link" . to_owned ( ) , p. replace ( "\\ " , "/" ) . to_json ( ) ) ;
70
70
} ,
71
- None => {
72
- return Err ( RenderError {
73
- desc : "Link could not be converted to str" . to_owned ( ) ,
74
- } )
75
- } ,
71
+ None => return Err ( RenderError :: new ( "Link could not be converted to str" ) ) ,
76
72
}
77
73
} ,
78
- None => {
79
- return Err ( RenderError { desc : "No path found for chapter in JSON data" . to_owned ( ) } )
80
- } ,
74
+ None => return Err ( RenderError :: new ( "No path found for chapter in JSON data" ) ) ,
81
75
}
82
76
83
77
debug ! ( "[*]: Inject in context" ) ;
@@ -90,7 +84,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
90
84
Some ( t) => {
91
85
try!( t. render ( & updated_context, r, rc) ) ;
92
86
} ,
93
- None => return Err ( RenderError { desc : "Error with the handlebars template" . to_owned ( ) } ) ,
87
+ None => return Err ( RenderError :: new ( "Error with the handlebars template" ) ) ,
94
88
}
95
89
96
90
}
@@ -122,14 +116,14 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
122
116
let chapters = c. navigate ( rc. get_path ( ) , "chapters" ) ;
123
117
124
118
let current = c. navigate ( rc. get_path ( ) , "path" )
125
- . to_string ( )
126
- . replace ( "\" " , "" ) ;
119
+ . to_string ( )
120
+ . replace ( "\" " , "" ) ;
127
121
128
122
debug ! ( "[*]: Decode chapters from JSON" ) ;
129
123
// Decode json format
130
124
let decoded: Vec < BTreeMap < String , String > > = match json:: decode ( & chapters. to_string ( ) ) {
131
125
Ok ( data) => data,
132
- Err ( _) => return Err ( RenderError { desc : "Could not decode the JSON data" . to_owned ( ) } ) ,
126
+ Err ( _) => return Err ( RenderError :: new ( "Could not decode the JSON data" ) ) ,
133
127
} ;
134
128
let mut previous: Option < BTreeMap < String , String > > = None ;
135
129
@@ -145,7 +139,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
145
139
146
140
let previous_path = match previous. get ( "path" ) {
147
141
Some ( p) => p,
148
- None => return Err ( RenderError { desc : "No path found for chapter in JSON data" . to_owned ( ) } ) ,
142
+ None => return Err ( RenderError :: new ( "No path found for chapter in JSON data" ) ) ,
149
143
} ;
150
144
151
145
if previous_path == & current {
@@ -160,9 +154,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
160
154
debug ! ( "[*]: Inserting title: {}" , n) ;
161
155
next_chapter. insert ( "title" . to_owned ( ) , n. to_json ( ) ) ;
162
156
} ,
163
- None => {
164
- return Err ( RenderError { desc : "No title found for chapter in JSON data" . to_owned ( ) } )
165
- } ,
157
+ None => return Err ( RenderError :: new ( "No title found for chapter in JSON data" ) ) ,
166
158
}
167
159
168
160
@@ -174,7 +166,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
174
166
// Hack for windows who tends to use `\` as separator instead of `/`
175
167
next_chapter. insert ( "link" . to_owned ( ) , l. replace ( "\\ " , "/" ) . to_json ( ) ) ;
176
168
} ,
177
- None => return Err ( RenderError { desc : "Link could not converted to str" . to_owned ( ) } ) ,
169
+ None => return Err ( RenderError :: new ( "Link could not converted to str" ) ) ,
178
170
}
179
171
180
172
debug ! ( "[*]: Inject in context" ) ;
@@ -188,7 +180,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
188
180
Some ( t) => {
189
181
try!( t. render ( & updated_context, r, rc) ) ;
190
182
} ,
191
- None => return Err ( RenderError { desc : "Error with the handlebars template" . to_owned ( ) } ) ,
183
+ None => return Err ( RenderError :: new ( "Error with the handlebars template" ) ) ,
192
184
}
193
185
194
186
break ;
0 commit comments