papercraft 0.21 → 0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +55 -13
- data/lib/papercraft/extension_proxy.rb +13 -2
- data/lib/papercraft/tags.rb +0 -1
- data/lib/papercraft/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 729c7b1cf7482cb761b005fba8da8ae4c1325559daee15fedd2d695de21ee08d
|
4
|
+
data.tar.gz: 0546c527a6a9ac0570c9bd6057101b31591eba1f1ee549c272d9bda13a9f7a04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdaa8d2f254744694ea3624f39871f4b411294a990f6e1bb4c57f56bf36049031b9403820cbadaa57ef6ac3e9021b6afa53da22588462450a6ca0863b6b88184
|
7
|
+
data.tar.gz: 4ea21235970af0cdef9ce09cd790742a94632e4f1f02d4a3d90a3e857741ec41952a53fe59b24016c00894dde7131dbbbc79d7616564f159f5646acf24f469f9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -64,6 +64,7 @@ hello.render('world')
|
|
64
64
|
- [Installing papercraft](#installing-papercraft)
|
65
65
|
- [Basic usage](#basic-usage)
|
66
66
|
- [Adding tags](#adding-tags)
|
67
|
+
- [Tag and attribute formatting](#tag-and-attribute-formatting)
|
67
68
|
- [Template parameters](#template-parameters)
|
68
69
|
- [Template logic](#template-logic)
|
69
70
|
- [Template blocks](#template-blocks)
|
@@ -154,6 +155,43 @@ Papercraft.html { img src: '/my.gif' }.render #=> "<img src="/my.gif"/>
|
|
154
155
|
Papercraft.html { p "foobar", class: 'important' }.render #=> "<p class=\"important\">foobar</p>"
|
155
156
|
```
|
156
157
|
|
158
|
+
## Tag and attribute formatting
|
159
|
+
|
160
|
+
Papercraft does not make any presumption about what tags and attributes you can
|
161
|
+
use. You can mix upper and lower case letters, and you can include arbitrary
|
162
|
+
characters in tag and attribute names. However, in order to best adhere to the
|
163
|
+
HTML and XML specs and common practices, tag names and attributes will be
|
164
|
+
formatted according to the following rules, depending on the template type:
|
165
|
+
|
166
|
+
- HTML: underscores are converted to dashes:
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
Papercraft.html {
|
170
|
+
foo_bar { p 'Hello', data_name: 'world' }
|
171
|
+
}.render #=> '<foo-bar><p data-name="world">Hello</p></foo-bar>'
|
172
|
+
```
|
173
|
+
|
174
|
+
- XML: underscores are converted to dashes, double underscores are converted to
|
175
|
+
colons:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
Papercraft.xml {
|
179
|
+
soap__Envelope(
|
180
|
+
xmlns__soap: 'http://schemas.xmlsoap.org/soap/envelope/',
|
181
|
+
) { }
|
182
|
+
}.render #=> '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Envelope>'
|
183
|
+
```
|
184
|
+
|
185
|
+
If you need more precise control over tag names, you can use the `#tag` method,
|
186
|
+
which takes the tag name as its first parameter, then the rest of the parameters
|
187
|
+
normally used for tags:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
Papercraft.html {
|
191
|
+
tag 'cra_zy__:!tag', 'foo'
|
192
|
+
}.render #=> '<cra_zy__:!tag>foo</cra_zy__:!tag>'
|
193
|
+
```
|
194
|
+
|
157
195
|
## Template parameters
|
158
196
|
|
159
197
|
In Papercraft, parameters are always passed explicitly. This means that template
|
@@ -513,21 +551,27 @@ and other associated methods:
|
|
513
551
|
|
514
552
|
```ruby
|
515
553
|
module BootstrapComponents
|
516
|
-
|
517
|
-
|
518
|
-
def card(**props)
|
554
|
+
def card(**props, &block)
|
519
555
|
div(class: 'card', **props) {
|
520
|
-
div(class: 'card-body')
|
521
|
-
emit_yield
|
522
|
-
}
|
556
|
+
div(class: 'card-body', &block)
|
523
557
|
}
|
524
558
|
end
|
525
|
-
|
559
|
+
|
526
560
|
def card_title(title)
|
527
|
-
|
561
|
+
h4(title, class: 'card-title')
|
562
|
+
end
|
563
|
+
|
564
|
+
def card_subtitle(subtitle)
|
565
|
+
h5(subtitle, class: 'card-subtitle')
|
528
566
|
end
|
529
567
|
|
530
|
-
|
568
|
+
def card_text(text)
|
569
|
+
p(text, class: 'card-text')
|
570
|
+
end
|
571
|
+
|
572
|
+
def card_link(text, **opts)
|
573
|
+
a(text, class: 'card-link', **opts)
|
574
|
+
end
|
531
575
|
end
|
532
576
|
|
533
577
|
Papercraft.extension(bootstrap: BootstrapComponents)
|
@@ -543,14 +587,12 @@ Papercraft.html {
|
|
543
587
|
bootstrap.card_title 'Card title'
|
544
588
|
bootstrap.card_subtitle 'Card subtitle'
|
545
589
|
bootstrap.card_text 'Some quick example text to build on the card title and make up the bulk of the card''s content.'
|
546
|
-
bootstrap.card_link '
|
547
|
-
bootstrap.card_link '
|
590
|
+
bootstrap.card_link 'Card link', href: '#foo'
|
591
|
+
bootstrap.card_link 'Another link', href: '#bar'
|
548
592
|
}
|
549
593
|
}
|
550
594
|
```
|
551
595
|
|
552
|
-
|
553
|
-
|
554
596
|
## XML templates
|
555
597
|
|
556
598
|
XML templates behave largely the same as HTML templates, with a few minor
|
@@ -23,10 +23,21 @@ module Papercraft
|
|
23
23
|
#
|
24
24
|
# @param sym [Symbol] method name
|
25
25
|
# @param *args [Array] arguments
|
26
|
+
# @param *props [Array] named arguments
|
26
27
|
# @param &block [Proc] block
|
27
28
|
# @return void
|
28
|
-
def method_missing(sym, *args, &block)
|
29
|
-
@renderer.send(sym, *args, &block)
|
29
|
+
def method_missing(sym, *args, **props, &block)
|
30
|
+
@renderer.send(sym, *args, **props, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Overrides the `Kernel#p` method to emit a p tag.
|
34
|
+
#
|
35
|
+
# @param *args [Array] arguments
|
36
|
+
# @param *props [Array] named arguments
|
37
|
+
# @param &block [Proc] block
|
38
|
+
# @return void
|
39
|
+
def p(text = nil, **props, &block)
|
40
|
+
@renderer.p(text, **props, &block)
|
30
41
|
end
|
31
42
|
end
|
32
43
|
end
|
data/lib/papercraft/tags.rb
CHANGED
data/lib/papercraft/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papercraft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.22'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|