papercraft 0.21 → 0.22

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: a23bf614d84747a18eecf84545604c9c2f58710dc3fa0e0c651a863a53c919b0
4
- data.tar.gz: 6b1ca8f4a90801beff11807dd357ce801b7526b5d114d5cca5f41f41aec69958
3
+ metadata.gz: 729c7b1cf7482cb761b005fba8da8ae4c1325559daee15fedd2d695de21ee08d
4
+ data.tar.gz: 0546c527a6a9ac0570c9bd6057101b31591eba1f1ee549c272d9bda13a9f7a04
5
5
  SHA512:
6
- metadata.gz: dcd7eada8280cb0fcd68528eaea0d2500ff99ac149c8495dd5a3955a93c3f181301a4decc9eeb4d7efdd8cfe2c4f6047c9f838e5084b413c1118a76d6abc4252
7
- data.tar.gz: 840ce0fc2a83de9b5a83bb10a5f4ed98986f7201737d6e31a4e89877aeb6bb22b2f2449c6efa08302473c073e26c830cfbe9e267456b450a56222b57a429fd15
6
+ metadata.gz: fdaa8d2f254744694ea3624f39871f4b411294a990f6e1bb4c57f56bf36049031b9403820cbadaa57ef6ac3e9021b6afa53da22588462450a6ca0863b6b88184
7
+ data.tar.gz: 4ea21235970af0cdef9ce09cd790742a94632e4f1f02d4a3d90a3e857741ec41952a53fe59b24016c00894dde7131dbbbc79d7616564f159f5646acf24f469f9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.22 2022-02-14
2
+
3
+ - Fix behaviour of call to `#p` in an extension (#10)
4
+
1
5
  ## 0.21 2022-02-13
2
6
 
3
7
  - Refactor and improve documentation
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
- h5 title, class: 'card-title'
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 '#', 'Card link'
547
- bootstrap.card_link '#', 'Another 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
@@ -160,7 +160,6 @@ module Papercraft
160
160
  # @param &block [Proc] block passed to method
161
161
  # @return [void]
162
162
  def method_missing(sym, *args, **opts, &block)
163
- # p method_missing: sym, self: self
164
163
  tag = sym.to_s
165
164
  repr = tag_repr(tag)
166
165
  code = S_TAG_METHOD % {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Papercraft
4
- VERSION = '0.21'
4
+ VERSION = '0.22'
5
5
  end
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.21'
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-13 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils