papercraft 0.29 → 1.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 +4 -0
- data/README.md +42 -3
- data/lib/papercraft/tags.rb +4 -0
- 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: d769e6ec71d8c6d60ebb0aa727037b691562a31ec1fc1a05ccb0f25f29858b7a
|
4
|
+
data.tar.gz: 97b15299e8b4ca3d801aec881bd0ea4cee245650225f9c6e41972333ab9f8011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff74adc23fc616b579f9729cecc595e2eebe92d2b96b6edcceff4eae043c7ca8048e3baea14f275533667809183cd7961e14c74a6afb71b04fe7902806c8678c
|
7
|
+
data.tar.gz: 8fcecbac3baa12296ae3386ecb31eb0db0d7e001f4f38dd1c055ab497a3113471338d26cca8812582091e10c17ab5413c1e37cdf172d07ca1eac011206935d90
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -84,6 +84,7 @@ hello.render('world')
|
|
84
84
|
- [Emitting Markdown](#emitting-markdown)
|
85
85
|
- [Working with MIME Types](#working-with-mime-types)
|
86
86
|
- [Deferred Evaluation](#deferred-evaluation)
|
87
|
+
- [HTML Templates](#html-templates)
|
87
88
|
- [XML Templates](#xml-templates)
|
88
89
|
- [JSON Templates](#json-templates)
|
89
90
|
- [Papercraft Extensions](#papercraft-extensions)
|
@@ -198,14 +199,28 @@ Papercraft.html { hr() }.render #=> "<hr/>"
|
|
198
199
|
Tag methods also accept tag attributes, given as a hash:
|
199
200
|
|
200
201
|
```ruby
|
201
|
-
Papercraft.html { img src: '/my.gif' }.render #=> "<img src
|
202
|
+
Papercraft.html { img src: '/my.gif' }.render #=> "<img src=\"/my.gif\"/>"
|
202
203
|
|
203
204
|
Papercraft.html { p "foobar", class: 'important' }.render #=> "<p class=\"important\">foobar</p>"
|
204
205
|
```
|
205
206
|
|
207
|
+
A `true` attribute value will emit a valueless attribute. A `nil` or `false`
|
208
|
+
attribute value will emit nothing:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
Papercraft.html { button disabled: nil }.render #=> "<button></button>"
|
212
|
+
Papercraft.html { button disabled: true }.render #=> "<button disabled></button>"
|
213
|
+
```
|
214
|
+
|
215
|
+
An attribute value given as an array will be joined by space characters:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
Papercraft.html { div class: [:foo, :bar] }.render #=> "<div class=\"foo bar\"></div>"
|
219
|
+
```
|
220
|
+
|
206
221
|
## Tag and Attribute Formatting
|
207
222
|
|
208
|
-
Papercraft does not make any
|
223
|
+
Papercraft does not make any assumption about what tags and attributes you can
|
209
224
|
use. You can mix upper and lower case letters, and you can include arbitrary
|
210
225
|
characters in tag and attribute names. However, in order to best adhere to the
|
211
226
|
HTML and XML specs and common practices, tag names and attributes will be
|
@@ -276,7 +291,7 @@ greeting.render(name: 'world') #=> "<h1>Hello, world!</h1>"
|
|
276
291
|
|
277
292
|
## Template Logic
|
278
293
|
|
279
|
-
Since Papercraft templates are just a bunch of Ruby, you can easily
|
294
|
+
Since Papercraft templates are just a bunch of Ruby, you can easily embed your
|
280
295
|
view logic right in the template:
|
281
296
|
|
282
297
|
```ruby
|
@@ -585,6 +600,24 @@ page = default_layout.apply {
|
|
585
600
|
}
|
586
601
|
```
|
587
602
|
|
603
|
+
## HTML Templates
|
604
|
+
|
605
|
+
HTML templates include a few HTML-specific methods to facilitate writing modern
|
606
|
+
HTML:
|
607
|
+
|
608
|
+
- `html5 { ... }` - emits an HTML 5 DOCTYPE (`<!DOCTYPE html>`)
|
609
|
+
- `import_map(root_path, root_url)` - emits an import map including all files
|
610
|
+
matching `<root_path>/*.js`, based on the given `root_url`
|
611
|
+
- `js_module(js)` - emits a `<script type="module">` element
|
612
|
+
- `link_stylesheet(href, **attributes)` - emits a `<link rel="stylesheet" ...>`
|
613
|
+
element
|
614
|
+
- `script(js, **attributes)` - emits an inline `<script>` element
|
615
|
+
- `style(css, **attributes)` - emits an inline `<style>` element
|
616
|
+
- `versioned_file_href(href, root_path, root_url)` - calculates a versioned href
|
617
|
+
for the given file
|
618
|
+
|
619
|
+
[HTML docs](https://www.rubydoc.info/gems/papercraft/Papercraft/HTML)
|
620
|
+
|
588
621
|
## XML Templates
|
589
622
|
|
590
623
|
XML templates behave largely the same as HTML templates, with a few minor
|
@@ -620,6 +653,8 @@ rss = Papercraft.xml(mime_type: 'text/xml; charset=utf-8') { |resource:, **props
|
|
620
653
|
}
|
621
654
|
```
|
622
655
|
|
656
|
+
[XML docs](https://www.rubydoc.info/gems/papercraft/Papercraft/XML)
|
657
|
+
|
623
658
|
## JSON Templates
|
624
659
|
|
625
660
|
JSON templates behave largely the same as HTML and XML templates. The only major
|
@@ -651,6 +686,8 @@ Papercraft.json {
|
|
651
686
|
Papercraft uses the [JSON gem](https://rubyapi.org/3.1/o/json) under the hood in
|
652
687
|
order to generate actual JSON.
|
653
688
|
|
689
|
+
[JSON docs](https://www.rubydoc.info/gems/papercraft/Papercraft/JSON)
|
690
|
+
|
654
691
|
## Papercraft Extensions
|
655
692
|
|
656
693
|
Papercraft extensions are modules that contain one or more methods that can be
|
@@ -857,6 +894,8 @@ xml = Papercraft.xml {
|
|
857
894
|
}
|
858
895
|
```
|
859
896
|
|
897
|
+
[SOAP docs](https://www.rubydoc.info/gems/papercraft/Papercraft/Extensions/Soap)
|
898
|
+
|
860
899
|
## API Reference
|
861
900
|
|
862
901
|
The API reference for this library can be found
|
data/lib/papercraft/tags.rb
CHANGED
@@ -387,6 +387,10 @@ module Papercraft
|
|
387
387
|
@buffer << S_SPACE << att_repr(k)
|
388
388
|
when false, nil
|
389
389
|
# emit nothing
|
390
|
+
when Array
|
391
|
+
v = v.join(' ')
|
392
|
+
@buffer << S_SPACE << att_repr(k) <<
|
393
|
+
S_EQUAL_QUOTE << escape_text(v) << S_QUOTE
|
390
394
|
else
|
391
395
|
@buffer << S_SPACE << att_repr(k) <<
|
392
396
|
S_EQUAL_QUOTE << escape_text(v) << S_QUOTE
|
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: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|