super-slim 3.6.3 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/lib/super_slim/compiler.rb +92 -35
- data/lib/super_slim/parser.rb +17 -9
- data/lib/super_slim/runtime.rb +28 -23
- data/lib/super_slim/shortcuts.rb +3 -4
- data/lib/super_slim/version.rb +1 -1
- metadata +66 -66
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52391ec6b8e744b8b883f3f2c7673b0d16c64156869d2d529d4bf37f0d0502cc
|
|
4
|
+
data.tar.gz: bb76a49c673a063e5d8cae8d7a2829776885894673623ba8ee08689533e0be4b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b2fe8cf05a6937e42c9bb4e376f34981d9dd0cf522e9b131e0f471d14e612bcc47bb917f789200357824536644a8325f5edf8cc208c73e191a84afb6df97109
|
|
7
|
+
data.tar.gz: a7eba7d8442da3a42c4b97b6d264c69d0d873ed1df12f91c56928361b4af8ae0c2dc1651a65556f83223e4d2592529633702d18101ae23871de09f49312c7377
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [3.7.0] — 2026-11-24
|
|
6
|
+
|
|
7
|
+
Faster rendering of splats and data hashes, faster compiling, and one fix.
|
|
8
|
+
|
|
9
|
+
**Faster**
|
|
10
|
+
- Tags with a splat (`*attrs`) or a `data=`/`aria=` hash allocate a third fewer objects per render: a form of twelve
|
|
11
|
+
fields went from 258 to 138 allocations per render, 4% faster without JIT and 9% with YJIT. Rails compiles
|
|
12
|
+
templates without `frozen_string_literal`, so each attribute name passed to the runtime allocated a string.
|
|
13
|
+
- Compiling allocates 30% fewer objects and takes 5% less time on 6,097 public templates, with and without YJIT.
|
|
14
|
+
The compiled Ruby is unchanged.
|
|
15
|
+
|
|
16
|
+
**Fixed**
|
|
17
|
+
- `SuperSlim.compile(source, html_safe: nil)` no longer compiles a dynamic class or a splat into code that raises
|
|
18
|
+
`ArgumentError` when it renders: `nil` works like `false`.
|
|
19
|
+
|
|
5
20
|
## [3.6.3] — 2026-11-21
|
|
6
21
|
|
|
7
22
|
One fix: a line break inside an interpolation of a quoted attribute no longer shifts the lines that follow.
|
|
@@ -330,7 +345,8 @@ renders what Slim 5 renders with `format: :html, sort_attrs: false`, byte for by
|
|
|
330
345
|
- Ruby 3.3 or later, every Ruby still maintained, Rails 8.0 or 8.1 for the railtie, and strscan 3.1.1 or later,
|
|
331
346
|
newer than the one Ruby 3.3 ships.
|
|
332
347
|
|
|
333
|
-
[Unreleased]: https://github.com/levups/super-slim/compare/v3.
|
|
348
|
+
[Unreleased]: https://github.com/levups/super-slim/compare/v3.7.0...HEAD
|
|
349
|
+
[3.7.0]: https://github.com/levups/super-slim/compare/v3.6.3...v3.7.0
|
|
334
350
|
[3.6.3]: https://github.com/levups/super-slim/compare/v3.6.2...v3.6.3
|
|
335
351
|
[3.6.2]: https://github.com/levups/super-slim/compare/v3.6.1...v3.6.2
|
|
336
352
|
[3.6.1]: https://github.com/levups/super-slim/compare/v3.6.0...v3.6.1
|
data/lib/super_slim/compiler.rb
CHANGED
|
@@ -8,6 +8,7 @@ module SuperSlim
|
|
|
8
8
|
|
|
9
9
|
VOID_ELEMENTS = %w[area base br col embed hr img input keygen link menuitem meta param source track wbr].to_h { [_1, true] }.freeze
|
|
10
10
|
HYPHENATED_ATTRIBUTES = %w[data aria].freeze
|
|
11
|
+
MAX_SCANNED_ATTRIBUTES = 8
|
|
11
12
|
DOCTYPES = {
|
|
12
13
|
html: {
|
|
13
14
|
"5" => "<!DOCTYPE html>",
|
|
@@ -48,7 +49,7 @@ module SuperSlim
|
|
|
48
49
|
@xml = format == :xml
|
|
49
50
|
@doctypes = DOCTYPES.fetch(format)
|
|
50
51
|
@rails = rails
|
|
51
|
-
@html_safe = html_safe
|
|
52
|
+
@html_safe = html_safe ? true : false
|
|
52
53
|
@escape_function = html_safe ? "::SuperSlim::Runtime.escape_html_safe" : "::ERB::Escape.html_escape"
|
|
53
54
|
@preamble = preamble
|
|
54
55
|
@postamble = postamble
|
|
@@ -226,29 +227,49 @@ module SuperSlim
|
|
|
226
227
|
return if attributes.empty?
|
|
227
228
|
return emit_output(compile_runtime_attributes(attributes), false) if attributes.any? { runtime_attribute?(_1) }
|
|
228
229
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
230
|
+
# A tag has a handful of attributes: scanning them again costs less than a hash of their names, which only a
|
|
231
|
+
# long list needs, as the scans grow with its square.
|
|
232
|
+
seen_names = {} if attributes.size > MAX_SCANNED_ATTRIBUTES
|
|
233
|
+
attributes.each_with_index do |attribute, index|
|
|
234
|
+
name = attribute.name
|
|
235
|
+
next if name == "class"
|
|
236
|
+
|
|
237
|
+
if seen_names
|
|
238
|
+
next seen_names[name] = true unless seen_names.key?(name)
|
|
239
|
+
elsif attributes.index { _1.name == name } == index
|
|
240
|
+
next
|
|
240
241
|
end
|
|
242
|
+
|
|
243
|
+
# Reported on the last line of the attributes, like the tag's compiled code, which follows their code.
|
|
244
|
+
lines_ahead = attributes.sum { |other| code_newlines(other) }
|
|
245
|
+
compile_error!("Multiple #{name} attributes specified", lines_ahead:)
|
|
241
246
|
end
|
|
242
247
|
|
|
243
248
|
# Every class value renders at the place of the first class attribute.
|
|
244
|
-
|
|
249
|
+
classes_compiled = false
|
|
245
250
|
attributes.each do |attribute|
|
|
246
251
|
next compile_attribute(attribute) unless attribute.name == "class"
|
|
247
|
-
next if
|
|
252
|
+
next if classes_compiled
|
|
253
|
+
|
|
254
|
+
classes_compiled = true
|
|
255
|
+
if attributes.all? { _1.name != "class" || _1.is_a?(StaticAttribute) }
|
|
256
|
+
compile_static_classes(attributes)
|
|
257
|
+
else
|
|
258
|
+
compile_class_attribute(attributes.filter_map { attribute_parts(_1) if _1.name == "class" })
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Shortcuts, the most common classes: their values join at compile time.
|
|
264
|
+
def compile_static_classes(attributes)
|
|
265
|
+
opened = false
|
|
266
|
+
attributes.each do |attribute|
|
|
267
|
+
next if attribute.name != "class" || attribute.value.empty?
|
|
248
268
|
|
|
249
|
-
|
|
250
|
-
|
|
269
|
+
@static << (opened ? " " : ' class="') << attribute.value
|
|
270
|
+
opened = true
|
|
251
271
|
end
|
|
272
|
+
@static << '"' if opened
|
|
252
273
|
end
|
|
253
274
|
|
|
254
275
|
def runtime_attribute?(attribute)
|
|
@@ -259,6 +280,7 @@ module SuperSlim
|
|
|
259
280
|
case attribute
|
|
260
281
|
when BooleanAttribute then emit_boolean_attribute(attribute.name)
|
|
261
282
|
when CodeAttribute then compile_code_attribute(attribute)
|
|
283
|
+
when StaticAttribute then @static << " " << attribute.name << '="' << attribute.value << '"'
|
|
262
284
|
else emit_attribute(attribute.name, attribute_parts(attribute))
|
|
263
285
|
end
|
|
264
286
|
end
|
|
@@ -321,15 +343,15 @@ module SuperSlim
|
|
|
321
343
|
|
|
322
344
|
def compile_runtime_attributes(attributes)
|
|
323
345
|
builder = new_variable
|
|
324
|
-
emit_code("#{builder} = ::SuperSlim::Runtime
|
|
346
|
+
emit_code("#{builder} = ::SuperSlim::Runtime::#{@html_safe ? "HtmlSafeAttributes" : "Attributes"}.new")
|
|
325
347
|
attributes.each do |attribute|
|
|
326
348
|
case attribute
|
|
327
349
|
when Splat
|
|
328
350
|
emit_code("#{builder}.splat_attrs((#{attribute.code}))")
|
|
329
351
|
when CodeAttribute
|
|
330
|
-
emit_code("#{builder}.code_attr(#{attribute.name
|
|
352
|
+
emit_code("#{builder}.code_attr(#{frozen_literal(attribute.name)}, #{attribute.escape}, (#{attribute.code})#{unchecked_name(attribute.name)})")
|
|
331
353
|
else
|
|
332
|
-
emit_code("#{builder}.attr(#{attribute.name
|
|
354
|
+
emit_code("#{builder}.attr(#{frozen_literal(attribute.name)}, #{string_expression(attribute_parts(attribute))}#{unchecked_name(attribute.name)})")
|
|
333
355
|
end
|
|
334
356
|
end
|
|
335
357
|
builder
|
|
@@ -351,13 +373,14 @@ module SuperSlim
|
|
|
351
373
|
end
|
|
352
374
|
|
|
353
375
|
def emit_attribute(name, parts)
|
|
354
|
-
|
|
376
|
+
@static << " " << name << '="'
|
|
355
377
|
emit_parts(parts)
|
|
356
|
-
|
|
378
|
+
@static << '"'
|
|
357
379
|
end
|
|
358
380
|
|
|
359
381
|
def emit_boolean_attribute(name)
|
|
360
|
-
|
|
382
|
+
@static << " " << name
|
|
383
|
+
@static << '=""' if @xml
|
|
361
384
|
end
|
|
362
385
|
|
|
363
386
|
def emit_parts(parts)
|
|
@@ -376,6 +399,7 @@ module SuperSlim
|
|
|
376
399
|
return "#{@escape_function}((#{value}))" if kind == :dynamic && escape
|
|
377
400
|
return value if kind == :raw
|
|
378
401
|
end
|
|
402
|
+
return frozen_literal(parts.map { _1[1] }.join) if parts.all? { _1[0] == :static }
|
|
379
403
|
|
|
380
404
|
literal = parts.map do |kind, value, escape|
|
|
381
405
|
case kind
|
|
@@ -387,8 +411,19 @@ module SuperSlim
|
|
|
387
411
|
%("#{literal.join}")
|
|
388
412
|
end
|
|
389
413
|
|
|
414
|
+
# A name found valid now needs no check at render time; the parser lets through some the runtime refuses, such
|
|
415
|
+
# as control characters, which still raise when they render.
|
|
416
|
+
def unchecked_name(name)
|
|
417
|
+
", false" unless name.match?(Runtime::Attributes::INVALID_NAME)
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
# Rails compiles templates without `frozen_string_literal`: a bare literal would allocate on every render.
|
|
421
|
+
def frozen_literal(text)
|
|
422
|
+
"#{text.inspect}.freeze"
|
|
423
|
+
end
|
|
424
|
+
|
|
390
425
|
def emit_interpolated(text)
|
|
391
|
-
emit_parts(Compiler.interpolation_parts(text))
|
|
426
|
+
text.include?('#{') ? emit_parts(Compiler.interpolation_parts(text)) : emit_static(text)
|
|
392
427
|
end
|
|
393
428
|
|
|
394
429
|
def compile_embedded(embedded)
|
|
@@ -488,25 +523,29 @@ module SuperSlim
|
|
|
488
523
|
@static << text
|
|
489
524
|
end
|
|
490
525
|
|
|
526
|
+
# The buffers write their statements straight into the compiled code: no string for each one.
|
|
491
527
|
def emit_output(code, escape)
|
|
492
|
-
|
|
528
|
+
flush_static
|
|
529
|
+
separate_statement
|
|
530
|
+
escape ? @buffer.escaped(@code, code) : @buffer.raw(@code, code)
|
|
493
531
|
end
|
|
494
532
|
|
|
495
533
|
def emit_code(code)
|
|
496
534
|
flush_static
|
|
497
|
-
|
|
535
|
+
separate_statement
|
|
536
|
+
@code << code
|
|
498
537
|
end
|
|
499
538
|
|
|
500
539
|
def flush_static
|
|
501
540
|
return if @static.empty?
|
|
502
541
|
|
|
503
|
-
|
|
504
|
-
@static
|
|
542
|
+
separate_statement
|
|
543
|
+
@buffer.static(@code, @static)
|
|
544
|
+
@static.clear
|
|
505
545
|
end
|
|
506
546
|
|
|
507
|
-
def
|
|
547
|
+
def separate_statement
|
|
508
548
|
@code << "; " unless @code.empty? || @code.end_with?("\n")
|
|
509
|
-
@code << code
|
|
510
549
|
end
|
|
511
550
|
|
|
512
551
|
def new_variable
|
|
@@ -521,17 +560,35 @@ module SuperSlim
|
|
|
521
560
|
|
|
522
561
|
def open = "#{@name} = +\"\""
|
|
523
562
|
def close = @name
|
|
524
|
-
|
|
525
|
-
def
|
|
526
|
-
|
|
563
|
+
|
|
564
|
+
def static(code, text)
|
|
565
|
+
code << @name << " << " << text.inspect << ".freeze"
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
def escaped(code, ruby)
|
|
569
|
+
code << @name << " << " << @escape_function << "((" << ruby << "))"
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
def raw(code, ruby)
|
|
573
|
+
code << @name << " << (" << ruby << ").to_s"
|
|
574
|
+
end
|
|
527
575
|
end
|
|
528
576
|
|
|
529
577
|
class OutputBuffer
|
|
530
578
|
def open = "@output_buffer = output_buffer || ActionView::OutputBuffer.new"
|
|
531
579
|
def close = "@output_buffer"
|
|
532
|
-
|
|
533
|
-
def
|
|
534
|
-
|
|
580
|
+
|
|
581
|
+
def static(code, text)
|
|
582
|
+
code << "@output_buffer.safe_concat(" << text.inspect << ".freeze)"
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
def escaped(code, ruby)
|
|
586
|
+
code << "@output_buffer << (" << ruby << ")"
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
def raw(code, ruby)
|
|
590
|
+
code << "@output_buffer.safe_concat((" << ruby << ").to_s)"
|
|
591
|
+
end
|
|
535
592
|
end
|
|
536
593
|
end
|
|
537
594
|
end
|
data/lib/super_slim/parser.rb
CHANGED
|
@@ -47,6 +47,7 @@ module SuperSlim
|
|
|
47
47
|
QUOTED_CHUNK_BY_QUOTE = %w[" '].to_h { |quote| [quote, /(?:[^{}\\#{quote}]|\\(?!\z))+/] }.freeze
|
|
48
48
|
SLASH, PIPE, APOSTROPHE, LESS_THAN, GREATER_THAN, DASH, EQUALS = "/|'<>-=".bytes
|
|
49
49
|
OPENING_BRACE, CLOSING_BRACE = "{}".bytes
|
|
50
|
+
HASH, DOT, STAR = "#.*".bytes
|
|
50
51
|
WHITESPACE_MARKER_BYTES = "<>'".bytes.freeze
|
|
51
52
|
BOOLEAN_ATTRIBUTE_BY_CLOSING = DELIMITERS.values.to_h { |closing| [closing, /#{ATTRIBUTE_NAME}(?=(\s|#{Regexp.escape(closing)}|\z))/] }.freeze
|
|
52
53
|
ATTRIBUTE_LIST_END_BY_CLOSING = DELIMITERS.values.to_h { |closing| [closing, /\s*#{Regexp.escape(closing)}/] }.freeze
|
|
@@ -364,11 +365,18 @@ module SuperSlim
|
|
|
364
365
|
end
|
|
365
366
|
end
|
|
366
367
|
|
|
367
|
-
# A tag name is consumed with its match; a shortcut is left for parse_tag to read as an attribute
|
|
368
|
+
# A tag name is consumed with its match; a shortcut is left for parse_tag to read as an attribute of a div, and
|
|
369
|
+
# a splat as the attributes of a dynamic tag.
|
|
368
370
|
def scan_tag
|
|
369
|
-
|
|
370
|
-
@scanner.
|
|
371
|
-
|
|
371
|
+
length = @scanner.match?(Shortcuts::TAG_PATTERN) or return
|
|
372
|
+
case @scanner.peek_byte
|
|
373
|
+
when HASH, DOT then Shortcuts::DEFAULT_TAG
|
|
374
|
+
when STAR then "*"
|
|
375
|
+
else
|
|
376
|
+
tag = @scanner.peek(length)
|
|
377
|
+
@scanner.pos += length
|
|
378
|
+
tag
|
|
379
|
+
end
|
|
372
380
|
end
|
|
373
381
|
|
|
374
382
|
def parse_embedded(engine, attributes_source, text)
|
|
@@ -473,18 +481,18 @@ module SuperSlim
|
|
|
473
481
|
|
|
474
482
|
def parse_tag(tag)
|
|
475
483
|
tag_lineno = @lineno
|
|
476
|
-
tag = Shortcuts::DEFAULT_TAG if Shortcuts::ATTRIBUTE_BY_SHORTCUT.key?(tag)
|
|
477
484
|
|
|
478
485
|
attributes = []
|
|
479
486
|
# Read before it is consumed, so that an illegal shortcut is reported where it starts.
|
|
480
487
|
while (shortcut_length = @scanner.match?(@attribute_shortcut))
|
|
481
|
-
shortcut
|
|
482
|
-
|
|
483
|
-
syntax_error!("Illegal shortcut")
|
|
488
|
+
# A shortcut is a single `#` or `.`: read by bytes, without a string for it.
|
|
489
|
+
next_byte = @scanner.string.getbyte(@scanner.pos + 1)
|
|
490
|
+
syntax_error!("Illegal shortcut") if next_byte == HASH || next_byte == DOT
|
|
484
491
|
|
|
492
|
+
value = @scanner[1]
|
|
485
493
|
# Tailwind arbitrary values may hold quotes and ampersands, which Slim names never do.
|
|
486
494
|
value = ERB::Escape.html_escape(value) if value.match?(SHORTCUT_VALUE_TO_ESCAPE)
|
|
487
|
-
attributes << StaticAttribute.new(
|
|
495
|
+
attributes << StaticAttribute.new((@scanner.peek_byte == HASH) ? "id" : "class", value)
|
|
488
496
|
@scanner.pos += shortcut_length
|
|
489
497
|
end
|
|
490
498
|
|
data/lib/super_slim/runtime.rb
CHANGED
|
@@ -17,10 +17,10 @@ module SuperSlim
|
|
|
17
17
|
|
|
18
18
|
def class_value(value, escape, html_safe)
|
|
19
19
|
if value.is_a?(Array)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
# `flatten` returns a new array: changing it in place spares one more.
|
|
21
|
+
classes = value.flatten.map!(&:to_s)
|
|
22
|
+
classes.reject!(&:empty?)
|
|
23
|
+
value = classes.join(" ")
|
|
24
24
|
end
|
|
25
25
|
return value.to_s unless escape
|
|
26
26
|
|
|
@@ -28,11 +28,13 @@ module SuperSlim
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def join_classes(*values)
|
|
31
|
-
values.reject(&:empty?)
|
|
31
|
+
values.reject!(&:empty?)
|
|
32
|
+
values.join(" ")
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
# Attributes only known at render time: splats (`*hash`), `data=`/`aria=` hashes and dynamic tags (`*{tag: "a"}`).
|
|
35
|
-
|
|
36
|
+
# A hash of each attribute's rendered value by name, in the order they render: one object per tag.
|
|
37
|
+
class Attributes < Hash
|
|
36
38
|
# Slim lets tabs and line breaks through: they end a name, so `data: {"x\tonclick" => code}` set onclick.
|
|
37
39
|
INVALID_NAME = /[[:cntrl:] "'>\/=]/
|
|
38
40
|
# Read after escaping, which turns markup into entities: `&` is refused with the rest.
|
|
@@ -41,19 +43,15 @@ module SuperSlim
|
|
|
41
43
|
# Far deeper than any page needs, and short of the stack a hash referring to itself would exhaust.
|
|
42
44
|
MAX_HYPHENATED_DEPTH = 100
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@value_by_name = {}
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def code_attr(name, escape, value)
|
|
46
|
+
# Names are checked unless the compiler already found them valid: those from render-time data always are.
|
|
47
|
+
def code_attr(name, escape, value, check = true)
|
|
50
48
|
if name == "class"
|
|
51
49
|
value = value.is_a?(Array) ? value.join(" ") : value.to_s
|
|
52
|
-
attr(name, escape(escape, value)) unless value.empty?
|
|
50
|
+
attr(name, escape(escape, value), false) unless value.empty?
|
|
53
51
|
elsif HYPHENATED.include?(name) && value.is_a?(Hash)
|
|
54
52
|
hyphenated_attr(name, escape, value)
|
|
55
53
|
elsif value != false && !value.nil?
|
|
56
|
-
attr(name, escape(escape, value))
|
|
54
|
+
attr(name, escape(escape, value), check)
|
|
57
55
|
end
|
|
58
56
|
end
|
|
59
57
|
|
|
@@ -61,20 +59,20 @@ module SuperSlim
|
|
|
61
59
|
splat.each { |name, value| code_attr(name.is_a?(Symbol) ? name.name : name.to_s, true, value) }
|
|
62
60
|
end
|
|
63
61
|
|
|
64
|
-
def attr(name, value)
|
|
65
|
-
raise InvalidAttributeNameError, "Invalid attribute name '#{name}' was rendered" if name.empty? || name.match?(INVALID_NAME)
|
|
62
|
+
def attr(name, value, check = true)
|
|
63
|
+
raise InvalidAttributeNameError, "Invalid attribute name '#{name}' was rendered" if check && (name.empty? || name.match?(INVALID_NAME))
|
|
66
64
|
|
|
67
|
-
if
|
|
68
|
-
|
|
65
|
+
if !key?(name)
|
|
66
|
+
self[name] = value
|
|
69
67
|
elsif name == "class"
|
|
70
|
-
|
|
68
|
+
self[name] = "#{self[name]} #{value}"
|
|
71
69
|
else
|
|
72
70
|
raise "Multiple #{name} attributes specified"
|
|
73
71
|
end
|
|
74
72
|
end
|
|
75
73
|
|
|
76
74
|
def build_tag(content = nil)
|
|
77
|
-
tag =
|
|
75
|
+
tag = delete("tag").to_s
|
|
78
76
|
tag = "div" if tag.empty?
|
|
79
77
|
raise InvalidTagNameError, "Invalid tag name '#{tag}' was rendered" unless tag.match?(VALID_TAG)
|
|
80
78
|
content ? "<#{tag}#{self}>#{content}</#{tag}>" : "<#{tag}#{self} />"
|
|
@@ -82,7 +80,7 @@ module SuperSlim
|
|
|
82
80
|
|
|
83
81
|
def to_s
|
|
84
82
|
html = +""
|
|
85
|
-
|
|
83
|
+
each do |name, value|
|
|
86
84
|
html << " " << name
|
|
87
85
|
html << %(=") << value.to_s << %(") unless value == true
|
|
88
86
|
end
|
|
@@ -102,9 +100,16 @@ module SuperSlim
|
|
|
102
100
|
end
|
|
103
101
|
|
|
104
102
|
def escape(escape, value)
|
|
105
|
-
|
|
103
|
+
(!escape || value == true) ? value : Runtime.escape_html(value)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Values that are `html_safe?` render as they are.
|
|
108
|
+
class HtmlSafeAttributes < Attributes
|
|
109
|
+
private
|
|
106
110
|
|
|
107
|
-
|
|
111
|
+
def escape(escape, value)
|
|
112
|
+
(!escape || value == true) ? value : Runtime.escape_html_safe(value)
|
|
108
113
|
end
|
|
109
114
|
end
|
|
110
115
|
end
|
data/lib/super_slim/shortcuts.rb
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
module SuperSlim
|
|
4
4
|
# `#name` sets the id and `.name` a class, on a div unless a tag name comes first.
|
|
5
5
|
module Shortcuts
|
|
6
|
-
ATTRIBUTE_BY_SHORTCUT = {"#" => "id", "." => "class"}.freeze
|
|
7
6
|
DEFAULT_TAG = "div"
|
|
8
7
|
|
|
9
8
|
SLIM_NAME_PART = /\p{Word}|-|\/\d+|:(?:\w|-)+/
|
|
@@ -21,8 +20,8 @@ module SuperSlim
|
|
|
21
20
|
| (?<=-)\( (?:[^()\s] | \([^()\s]*\))+ \)
|
|
22
21
|
}x
|
|
23
22
|
|
|
24
|
-
ATTRIBUTE_PATTERN = /\A
|
|
25
|
-
TAILWIND_ATTRIBUTE_PATTERN = /\A
|
|
26
|
-
TAG_PATTERN = /\A(?:[#.]|\*(?=[^\s]+)|(
|
|
23
|
+
ATTRIBUTE_PATTERN = /\A[#.]+((?:#{SLIM_NAME_PART})*)/
|
|
24
|
+
TAILWIND_ATTRIBUTE_PATTERN = /\A[#.]+((?:#{TAILWIND_NAME_PART})*)/
|
|
25
|
+
TAG_PATTERN = /\A(?:[#.]|\*(?=[^\s]+)|(?:\p{Word}(?:\p{Word}|:|-)*\p{Word}|\p{Word}+))/
|
|
27
26
|
end
|
|
28
27
|
end
|
data/lib/super_slim/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: super-slim
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Level UP Solutions
|
|
7
|
+
- Level UP Solutions
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
rules, and a RuboCop plugin for the Ruby inside templates.
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: strscan
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
-
|
|
17
|
+
- ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 3.1.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
-
|
|
25
|
+
- ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: 3.1.1
|
|
28
|
+
description: "A Slim template engine written from scratch, without Temple. It renders the same HTML as Slim 5, compiles and renders faster with fewer allocations, and comes with a formatter that cannot change a page, a linter with HTML and accessibility rules, and a RuboCop plugin for the Ruby inside templates."
|
|
30
29
|
executables:
|
|
31
|
-
- super-slim
|
|
30
|
+
- super-slim
|
|
32
31
|
extensions: []
|
|
33
32
|
extra_rdoc_files: []
|
|
34
33
|
files:
|
|
35
|
-
- CHANGELOG.md
|
|
36
|
-
- LICENSE
|
|
37
|
-
- LICENSE-slim
|
|
38
|
-
- README.md
|
|
39
|
-
- config/rubocop.yml
|
|
40
|
-
- exe/super-slim
|
|
41
|
-
- lib/super-slim.rb
|
|
42
|
-
- lib/super_slim.rb
|
|
43
|
-
- lib/super_slim/ast.rb
|
|
44
|
-
- lib/super_slim/cli.rb
|
|
45
|
-
- lib/super_slim/compiler.rb
|
|
46
|
-
- lib/super_slim/formatter.rb
|
|
47
|
-
- lib/super_slim/formatter/attribute_arranger.rb
|
|
48
|
-
- lib/super_slim/formatter/code_wrapper.rb
|
|
49
|
-
- lib/super_slim/formatter/line_wrapper.rb
|
|
50
|
-
- lib/super_slim/linter.rb
|
|
51
|
-
- lib/super_slim/linter/presets.rb
|
|
52
|
-
- lib/super_slim/linter/rules.rb
|
|
53
|
-
- lib/super_slim/parallel.rb
|
|
54
|
-
- lib/super_slim/parser.rb
|
|
55
|
-
- lib/super_slim/parser/ruby_brackets.rb
|
|
56
|
-
- lib/super_slim/rails_handler.rb
|
|
57
|
-
- lib/super_slim/railtie.rb
|
|
58
|
-
- lib/super_slim/rubocop.rb
|
|
59
|
-
- lib/super_slim/runtime.rb
|
|
60
|
-
- lib/super_slim/shortcuts.rb
|
|
61
|
-
- lib/super_slim/version.rb
|
|
62
|
-
homepage: https://github.com/levups/super-slim
|
|
34
|
+
- CHANGELOG.md
|
|
35
|
+
- LICENSE
|
|
36
|
+
- LICENSE-slim
|
|
37
|
+
- README.md
|
|
38
|
+
- config/rubocop.yml
|
|
39
|
+
- exe/super-slim
|
|
40
|
+
- lib/super-slim.rb
|
|
41
|
+
- lib/super_slim.rb
|
|
42
|
+
- lib/super_slim/ast.rb
|
|
43
|
+
- lib/super_slim/cli.rb
|
|
44
|
+
- lib/super_slim/compiler.rb
|
|
45
|
+
- lib/super_slim/formatter.rb
|
|
46
|
+
- lib/super_slim/formatter/attribute_arranger.rb
|
|
47
|
+
- lib/super_slim/formatter/code_wrapper.rb
|
|
48
|
+
- lib/super_slim/formatter/line_wrapper.rb
|
|
49
|
+
- lib/super_slim/linter.rb
|
|
50
|
+
- lib/super_slim/linter/presets.rb
|
|
51
|
+
- lib/super_slim/linter/rules.rb
|
|
52
|
+
- lib/super_slim/parallel.rb
|
|
53
|
+
- lib/super_slim/parser.rb
|
|
54
|
+
- lib/super_slim/parser/ruby_brackets.rb
|
|
55
|
+
- lib/super_slim/rails_handler.rb
|
|
56
|
+
- lib/super_slim/railtie.rb
|
|
57
|
+
- lib/super_slim/rubocop.rb
|
|
58
|
+
- lib/super_slim/runtime.rb
|
|
59
|
+
- lib/super_slim/shortcuts.rb
|
|
60
|
+
- lib/super_slim/version.rb
|
|
61
|
+
homepage: "https://github.com/levups/super-slim"
|
|
63
62
|
licenses:
|
|
64
|
-
- MIT
|
|
63
|
+
- MIT
|
|
65
64
|
metadata:
|
|
66
|
-
source_code_uri: https://github.com/levups/super-slim
|
|
67
|
-
changelog_uri: https://github.com/levups/super-slim/blob/main/CHANGELOG.md
|
|
68
|
-
documentation_uri: https://levups.github.io/super-slim/
|
|
69
|
-
bug_tracker_uri: https://github.com/levups/super-slim/issues
|
|
70
|
-
rubygems_mfa_required:
|
|
71
|
-
default_lint_roller_plugin: SuperSlim::RuboCop::Plugin
|
|
65
|
+
source_code_uri: "https://github.com/levups/super-slim"
|
|
66
|
+
changelog_uri: "https://github.com/levups/super-slim/blob/main/CHANGELOG.md"
|
|
67
|
+
documentation_uri: "https://levups.github.io/super-slim/"
|
|
68
|
+
bug_tracker_uri: "https://github.com/levups/super-slim/issues"
|
|
69
|
+
rubygems_mfa_required: "true"
|
|
70
|
+
default_lint_roller_plugin: "SuperSlim::RuboCop::Plugin"
|
|
72
71
|
rdoc_options: []
|
|
73
72
|
require_paths:
|
|
74
|
-
- lib
|
|
73
|
+
- lib
|
|
75
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
75
|
requirements:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
-
|
|
77
|
+
- ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: "3.3"
|
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
requirements:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
-
|
|
83
|
+
- ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: "0"
|
|
85
86
|
requirements: []
|
|
86
|
-
rubygems_version: 4.0
|
|
87
|
+
rubygems_version: 4.1.0
|
|
87
88
|
specification_version: 4
|
|
88
|
-
summary: A Slim template engine that compiles and renders faster, with a formatter
|
|
89
|
-
and a linter
|
|
89
|
+
summary: "A Slim template engine that compiles and renders faster, with a formatter and a linter"
|
|
90
90
|
test_files: []
|