@@ -171,13 +171,14 @@ def self.token_path_to_hint hint, kinds
171
171
def setup options
172
172
super
173
173
174
+ check_options options
175
+
174
176
if options [ :wrap ] || options [ :line_numbers ]
175
177
@real_out = @out
176
178
@out = ''
177
179
end
178
180
179
181
options [ :break_lines ] = true if options [ :line_numbers ] == :inline
180
-
181
182
@break_lines = ( options [ :break_lines ] == true )
182
183
183
184
@HTML_ESCAPE = HTML_ESCAPE . dup
@@ -187,43 +188,7 @@ def setup options
187
188
@last_opened = nil
188
189
@css = CSS . new options [ :style ]
189
190
190
- hint = options [ :hint ]
191
- if hint && ![ :debug , :info , :info_long ] . include? ( hint )
192
- raise ArgumentError , "Unknown value %p for :hint; \
193
- expected :info, :info_long, :debug, false, or nil." % hint
194
- end
195
-
196
- css_classes = TokenKinds
197
- case options [ :css ]
198
- when :class
199
- @span_for_kind = Hash . new do |h , k |
200
- if k . is_a? ::Symbol
201
- kind = k_dup = k
202
- else
203
- kind = k . first
204
- k_dup = k . dup
205
- end
206
- if kind != :space && ( hint || css_class = css_classes [ kind ] )
207
- title = HTML . token_path_to_hint hint , k if hint
208
- css_class ||= css_classes [ kind ]
209
- h [ k_dup ] = "<span#{ title } #{ " class=\" #{ css_class } \" " if css_class } >"
210
- else
211
- h [ k_dup ] = nil
212
- end
213
- end
214
- when :style
215
- @span_for_kind = Hash . new do |h , k |
216
- kind = k . is_a? ( Symbol ) ? k : k . first
217
- h [ k . is_a? ( Symbol ) ? k : k . dup ] =
218
- if kind != :space && ( hint || css_classes [ kind ] )
219
- title = HTML . token_path_to_hint hint , k if hint
220
- style = @css . get_style Array ( k ) . map { |c | css_classes [ c ] }
221
- "<span#{ title } #{ " style=\" #{ style } \" " if style } >"
222
- end
223
- end
224
- else
225
- raise ArgumentError , "Unknown value %p for :css." % options [ :css ]
226
- end
191
+ @span_for_kind = make_span_for_kind ( options [ :css ] , options [ :hint ] , @css )
227
192
228
193
@set_last_opened = options [ :hint ] || options [ :css ] == :style
229
194
end
@@ -306,6 +271,35 @@ def end_line kind
306
271
307
272
protected
308
273
274
+ def check_options options
275
+ unless [ false , nil , :debug , :info , :info_long ] . include? options [ :hint ]
276
+ raise ArgumentError , "Unknown value %p for :hint; expected :info, :info_long, :debug, false, or nil." % [ options [ :hint ] ]
277
+ end
278
+
279
+ unless [ :class , :style ] . include? options [ :css ]
280
+ raise ArgumentError , 'Unknown value %p for :css.' % [ options [ :css ] ]
281
+ end
282
+ end
283
+
284
+ def make_span_for_kind method , hint , css
285
+ css_classes = TokenKinds
286
+
287
+ Hash . new do |h , k |
288
+ kind = k . is_a? ( Symbol ) ? k : k . first
289
+
290
+ h [ k . is_a? ( Symbol ) ? k : k . dup ] =
291
+ if kind != :space && ( ( css_class = css_classes [ kind ] ) || hint )
292
+ title = HTML . token_path_to_hint hint , k if hint
293
+ if method == :class
294
+ "<span#{ title } #{ " class=\" #{ css_class } \" " if css_class } >"
295
+ else
296
+ style = css . get_style k . is_a? ( Array ) ? k . map { |c | css_classes [ c ] } : [ css_class ]
297
+ "<span#{ title } #{ " style=\" #{ style } \" " if style } >"
298
+ end
299
+ end
300
+ end
301
+ end
302
+
309
303
def check_group_nesting name , kind
310
304
if @opened . empty? || @opened . last != kind
311
305
warn "Malformed token stream: Trying to close a #{ name } (%p) that is not open. Open are: %p." % [ kind , @opened [ 1 ..-1 ] ]
0 commit comments