papercraft 2.13 → 2.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56eed644cb59fa526aaa4a540854d36456c812e3d697f3c26cf64b57b26ff124
4
- data.tar.gz: e5f93cffebceb83199cb08ae7dc7d442bb2cd40118839bfee194be0fbd55db5f
3
+ metadata.gz: 778a543052eef0a1901172f1655da8ca1bfadce65699e70cdb42abf0f690b5da
4
+ data.tar.gz: 2268982f7ff3476073eb40e3b76e4061cde3c521fb68864b47ca46fabda9833b
5
5
  SHA512:
6
- metadata.gz: f352689a65bba3879698cccd8ab7650ad74213403a9f4cf5a6dacbb1414a62c8f9052277fbbdca0d107e9fd748d43ea77432a822ef2ad55981ad39277e551d78
7
- data.tar.gz: 387558f9b1a32ca905621e8823e6f2b25160dc4270ba549ef9e3f1d889401314b2737fa82a9fa79417249a0e2621e76824eabe08d11da88534c1af08506d49a9
6
+ metadata.gz: 4360ecfe28aedacb33d6b4b77f1715289c3831a09629cdb398fb16b8319ce603bbd47f565720aca2120efafa9add694bcbd783d06682f72f199844f24a318934
7
+ data.tar.gz: 6fa327527d4221bf2527be387ffc9b9a2a1504d5f91e761793f572eb55f7ddaf3914ee1849f8ab434043bc52f3fc4efd690a130e49c742d413005c0432f88c44
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.14 2025-09-17
2
+
3
+ - Do not escape inner text of style and script tags
4
+
1
5
  # 2.13 2025-09-11
2
6
 
3
7
  - Pass level to HTML debug attribute injection proc
data/README.md CHANGED
@@ -30,7 +30,7 @@ require 'papercraft'
30
30
  page = ->(**props) {
31
31
  html {
32
32
  head { title 'My Title' }
33
- body { render_yield **props }
33
+ body { render_children **props }
34
34
  }
35
35
  }
36
36
  page.render {
@@ -58,7 +58,7 @@ require 'papercraft'
58
58
  page = ->(**props) {
59
59
  html {
60
60
  head { title 'My Title' }
61
- body { yield **props }
61
+ body { render_children **props }
62
62
  }
63
63
  }
64
64
  page.render {
@@ -99,7 +99,7 @@ Papercraft features:
99
99
  - [Parameter and Block Application](#parameter-and-block-application)
100
100
  - [Higher-Order Templates](#higher-order-templates)
101
101
  - [Layout Template Composition](#layout-template-composition)
102
- - [Emitting Markdown](#emitting-markdown)
102
+ - [Rendering Markdown](#rendering-markdown)
103
103
  - [Deferred Evaluation](#deferred-evaluation)
104
104
  - [Cached Rendering](#cached-rendering)
105
105
 
@@ -239,14 +239,14 @@ TITLE_HTML = '<h1>hi</h1>'
239
239
  }.render #=> <div><h1>hi</h1></div>
240
240
  ```
241
241
 
242
- ### `#render_yield` - emit given block
242
+ ### `#render_children` - render the given block
243
243
 
244
- `#render_yield` is used to emit a given block. If no block is given, a
244
+ `#render_children` is used to emit a given block. If no block is given, a
245
245
  `LocalJumpError` exception is raised:
246
246
 
247
247
  ```ruby
248
248
  Card = ->(**props) {
249
- card { render_yield(**props) }
249
+ card { render_children(**props) }
250
250
  }
251
251
 
252
252
  Card.render(foo: 'bar') { |foo|
@@ -254,14 +254,9 @@ Card.render(foo: 'bar') { |foo|
254
254
  } #=> <card><h1>bar</h1></card>
255
255
  ```
256
256
 
257
- `render_yield` can be called with or without arguments, which are passed to the
257
+ `render_children` can be called with or without arguments, which are passed to the
258
258
  given block.
259
259
 
260
- ### `#render_children` - emit given block
261
-
262
- `#render_children` is used to emit a given block, but does not raise an
263
- exception if no block is given.
264
-
265
260
  ### `#defer` - emit deferred HTML
266
261
 
267
262
  `#defer` is used to emit HTML in a deferred fashion - the deferred part will be
@@ -275,7 +270,7 @@ Layout = -> {
275
270
  }
276
271
  }
277
272
  body {
278
- render_yield
273
+ render_children
279
274
  }
280
275
  }
281
276
 
@@ -368,12 +363,12 @@ logic right in the template:
368
363
 
369
364
  ## Template Blocks
370
365
 
371
- Templates can also accept and render blocks by using `render_yield`:
366
+ Templates can also accept and render blocks by using `render_children`:
372
367
 
373
368
  ```ruby
374
369
  page = -> {
375
370
  html {
376
- body { render_yield }
371
+ body { render_children }
377
372
  }
378
373
  }
379
374
 
@@ -446,7 +441,7 @@ hello_world = hello.apply('world')
446
441
  hello_world.render #=> "<h1>Hello, world!</h1>"
447
442
 
448
443
  # block application
449
- div_wrap = -> { div { render_yield } }
444
+ div_wrap = -> { div { render_children } }
450
445
  wrapped_h1 = div_wrap.apply { h1 'hi' }
451
446
  wrapped_h1.render #=> "<div><h1>hi</h1></div>"
452
447
 
@@ -474,7 +469,7 @@ wrapped_greeter.render #=> "<div><h1>hi</h1></div>"
474
469
  The inner template can also be passed as a block, as shown above:
475
470
 
476
471
  ```ruby
477
- div_wrap = -> { div { render_yield } }
472
+ div_wrap = -> { div { render_children } }
478
473
  wrapped_greeter = div_wrap.apply { h1 'hi' }
479
474
  wrapped_greeter.render #=> "<div><h1>hi</h1></div>"
480
475
  ```
@@ -494,7 +489,7 @@ default_layout = -> { |**params|
494
489
  title: params[:title]
495
490
  }
496
491
  body {
497
- render_yield(**params)
492
+ render_children(**params)
498
493
  }
499
494
  }
500
495
  }
@@ -512,7 +507,7 @@ article_layout.render(
512
507
  )
513
508
  ```
514
509
 
515
- ## Emitting Markdown
510
+ ## Rendering Markdown
516
511
 
517
512
  Markdown is rendered using the
518
513
  [Kramdown](https://kramdown.gettalong.org/index.html) gem. To emit Markdown, use
@@ -583,7 +578,7 @@ default_layout = -> { |**args|
583
578
  head {
584
579
  defer { render deps.head_markup }
585
580
  }
586
- body { render_yield **args }
581
+ body { render_children **args }
587
582
  }
588
583
 
589
584
  button = proc { |text, onclick|
@@ -163,6 +163,8 @@ module Papercraft
163
163
 
164
164
  # adjust_whitespace(node.location)
165
165
  is_void = is_void_element?(tag)
166
+ is_raw_inner_text = is_raw_inner_text_element?(tag)
167
+
166
168
  emit_html(node.tag_location, format_html_tag_open(node.tag_location, tag, node.attributes))
167
169
  return if is_void
168
170
 
@@ -177,9 +179,17 @@ module Papercraft
177
179
 
178
180
  if node.inner_text
179
181
  if is_static_node?(node.inner_text)
180
- emit_html(node.location, ERB::Escape.html_escape(format_literal(node.inner_text)))
182
+ if is_raw_inner_text
183
+ emit_html(node.location, format_literal(node.inner_text))
184
+ else
185
+ emit_html(node.location, ERB::Escape.html_escape(format_literal(node.inner_text)))
186
+ end
181
187
  else
182
- emit_html(node.location, interpolated("ERB::Escape.html_escape((#{format_code(node.inner_text)}))"))
188
+ if is_raw_inner_text
189
+ emit_html(node.location, interpolated(format_code(node.inner_text)))
190
+ else
191
+ emit_html(node.location, interpolated("ERB::Escape.html_escape((#{format_code(node.inner_text)}))"))
192
+ end
183
193
  end
184
194
  end
185
195
  emit_html(node.location, format_html_tag_close(tag))
@@ -464,6 +474,14 @@ module Papercraft
464
474
  VOID_TAGS.include?(tag.to_s)
465
475
  end
466
476
 
477
+ RAW_INNER_TEXT_TAGS = %w(style script)
478
+
479
+ def is_raw_inner_text_element?(tag)
480
+ return false if @mode == :xml
481
+
482
+ RAW_INNER_TEXT_TAGS.include?(tag.to_s)
483
+ end
484
+
467
485
  # Formats an open tag with optional attributes.
468
486
  #
469
487
  # @param loc [Prism::Location] tag location
@@ -591,7 +609,7 @@ module Papercraft
591
609
  end
592
610
 
593
611
  # Returns true if the given node is a dynamic node.
594
- #
612
+ #
595
613
  # @param node [Prism::Node] attributes node
596
614
  # @return [bool] is node dynamic
597
615
  def is_dynamic_attribute?(node)
@@ -599,7 +617,7 @@ module Papercraft
599
617
  end
600
618
 
601
619
  # Computes injected attributes for the given tag location.
602
- #
620
+ #
603
621
  # @param loc [Prism::Location] tag location
604
622
  # @return [Hash] injected attributes hash
605
623
  def compute_injected_attributes(loc)
@@ -610,7 +628,7 @@ module Papercraft
610
628
  end
611
629
 
612
630
  # Computes injected attributes for the given tag location.
613
- #
631
+ #
614
632
  # @param loc [Prism::Location] tag location
615
633
  # @return [Array<String>] array of attribute strings
616
634
  def format_injected_attributes(loc)
@@ -20,7 +20,7 @@ module Papercraft
20
20
  def apply(*, **, &)
21
21
  Template.new(@proc.apply(*, **, &), mode: @mode)
22
22
  end
23
-
23
+
24
24
  def compiled_proc
25
25
  @proc.compiled_proc(mode: @mode)
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Papercraft
4
- VERSION = '2.13'
4
+ VERSION = '2.14'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papercraft
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.13'
4
+ version: '2.14'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner