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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +15 -20
- data/lib/papercraft/compiler.rb +23 -5
- data/lib/papercraft/template.rb +1 -1
- data/lib/papercraft/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 778a543052eef0a1901172f1655da8ca1bfadce65699e70cdb42abf0f690b5da
|
4
|
+
data.tar.gz: 2268982f7ff3476073eb40e3b76e4061cde3c521fb68864b47ca46fabda9833b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4360ecfe28aedacb33d6b4b77f1715289c3831a09629cdb398fb16b8319ce603bbd47f565720aca2120efafa9add694bcbd783d06682f72f199844f24a318934
|
7
|
+
data.tar.gz: 6fa327527d4221bf2527be387ffc9b9a2a1504d5f91e761793f572eb55f7ddaf3914ee1849f8ab434043bc52f3fc4efd690a130e49c742d413005c0432f88c44
|
data/CHANGELOG.md
CHANGED
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 {
|
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 {
|
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
|
-
- [
|
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
|
-
### `#
|
242
|
+
### `#render_children` - render the given block
|
243
243
|
|
244
|
-
`#
|
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 {
|
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
|
-
`
|
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
|
-
|
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 `
|
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 {
|
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 {
|
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 {
|
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
|
-
|
492
|
+
render_children(**params)
|
498
493
|
}
|
499
494
|
}
|
500
495
|
}
|
@@ -512,7 +507,7 @@ article_layout.render(
|
|
512
507
|
)
|
513
508
|
```
|
514
509
|
|
515
|
-
##
|
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 {
|
581
|
+
body { render_children **args }
|
587
582
|
}
|
588
583
|
|
589
584
|
button = proc { |text, onclick|
|
data/lib/papercraft/compiler.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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)
|
data/lib/papercraft/template.rb
CHANGED
data/lib/papercraft/version.rb
CHANGED