papercraft 0.28 → 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 +8 -0
- data/README.md +82 -3
- data/lib/papercraft/tags.rb +4 -0
- data/lib/papercraft/version.rb +1 -1
- data/lib/tilt/papercraft.rb +25 -0
- metadata +5 -4
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
@@ -66,6 +66,7 @@ hello.render('world')
|
|
66
66
|
## Table of Content
|
67
67
|
|
68
68
|
- [Installing Papercraft](#installing-papercraft)
|
69
|
+
- [Using with Tilt](#using-with-tilt)
|
69
70
|
- [Basic Usage](#basic-usage)
|
70
71
|
- [Adding Tags](#adding-tags)
|
71
72
|
- [Tag and Attribute Formatting](#tag-and-attribute-formatting)
|
@@ -83,6 +84,7 @@ hello.render('world')
|
|
83
84
|
- [Emitting Markdown](#emitting-markdown)
|
84
85
|
- [Working with MIME Types](#working-with-mime-types)
|
85
86
|
- [Deferred Evaluation](#deferred-evaluation)
|
87
|
+
- [HTML Templates](#html-templates)
|
86
88
|
- [XML Templates](#xml-templates)
|
87
89
|
- [JSON Templates](#json-templates)
|
88
90
|
- [Papercraft Extensions](#papercraft-extensions)
|
@@ -126,6 +128,45 @@ Rendering a template is done using `#render`:
|
|
126
128
|
html.render #=> "<div id="greeter"><p>Hello!</p></div>"
|
127
129
|
```
|
128
130
|
|
131
|
+
## Using with Tilt
|
132
|
+
|
133
|
+
Papercraft templates can also be rendered using Tilt:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
require 'tilt/papercraft'
|
137
|
+
|
138
|
+
# loading from a file (with a .papercraft extension)
|
139
|
+
template = Tilt.new('mytemplate.papercraft')
|
140
|
+
template.render
|
141
|
+
|
142
|
+
# defining a template inline:
|
143
|
+
template = Tilt['papercraft'].new { <<~RUBY
|
144
|
+
h1 'Hello'
|
145
|
+
RUBY
|
146
|
+
}
|
147
|
+
template.render
|
148
|
+
```
|
149
|
+
|
150
|
+
When rendering using Tilt, the following local variables are available to the
|
151
|
+
template: `scope`, `locals` and `block`:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
template = Tilt['papercraft'].new { <<~RUBY
|
155
|
+
title scope.title
|
156
|
+
|
157
|
+
h1 locals[:message]
|
158
|
+
|
159
|
+
emit block if block
|
160
|
+
RUBY
|
161
|
+
}
|
162
|
+
|
163
|
+
def title
|
164
|
+
'foo'
|
165
|
+
end
|
166
|
+
|
167
|
+
template.render(self, message: 'bar') { p 'this is a paragraph' }
|
168
|
+
```
|
169
|
+
|
129
170
|
## Adding Tags
|
130
171
|
|
131
172
|
Tags are added using unqualified method calls, and can be nested using blocks:
|
@@ -158,14 +199,28 @@ Papercraft.html { hr() }.render #=> "<hr/>"
|
|
158
199
|
Tag methods also accept tag attributes, given as a hash:
|
159
200
|
|
160
201
|
```ruby
|
161
|
-
Papercraft.html { img src: '/my.gif' }.render #=> "<img src
|
202
|
+
Papercraft.html { img src: '/my.gif' }.render #=> "<img src=\"/my.gif\"/>"
|
162
203
|
|
163
204
|
Papercraft.html { p "foobar", class: 'important' }.render #=> "<p class=\"important\">foobar</p>"
|
164
205
|
```
|
165
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
|
+
|
166
221
|
## Tag and Attribute Formatting
|
167
222
|
|
168
|
-
Papercraft does not make any
|
223
|
+
Papercraft does not make any assumption about what tags and attributes you can
|
169
224
|
use. You can mix upper and lower case letters, and you can include arbitrary
|
170
225
|
characters in tag and attribute names. However, in order to best adhere to the
|
171
226
|
HTML and XML specs and common practices, tag names and attributes will be
|
@@ -236,7 +291,7 @@ greeting.render(name: 'world') #=> "<h1>Hello, world!</h1>"
|
|
236
291
|
|
237
292
|
## Template Logic
|
238
293
|
|
239
|
-
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
|
240
295
|
view logic right in the template:
|
241
296
|
|
242
297
|
```ruby
|
@@ -545,6 +600,24 @@ page = default_layout.apply {
|
|
545
600
|
}
|
546
601
|
```
|
547
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
|
+
|
548
621
|
## XML Templates
|
549
622
|
|
550
623
|
XML templates behave largely the same as HTML templates, with a few minor
|
@@ -580,6 +653,8 @@ rss = Papercraft.xml(mime_type: 'text/xml; charset=utf-8') { |resource:, **props
|
|
580
653
|
}
|
581
654
|
```
|
582
655
|
|
656
|
+
[XML docs](https://www.rubydoc.info/gems/papercraft/Papercraft/XML)
|
657
|
+
|
583
658
|
## JSON Templates
|
584
659
|
|
585
660
|
JSON templates behave largely the same as HTML and XML templates. The only major
|
@@ -611,6 +686,8 @@ Papercraft.json {
|
|
611
686
|
Papercraft uses the [JSON gem](https://rubyapi.org/3.1/o/json) under the hood in
|
612
687
|
order to generate actual JSON.
|
613
688
|
|
689
|
+
[JSON docs](https://www.rubydoc.info/gems/papercraft/Papercraft/JSON)
|
690
|
+
|
614
691
|
## Papercraft Extensions
|
615
692
|
|
616
693
|
Papercraft extensions are modules that contain one or more methods that can be
|
@@ -817,6 +894,8 @@ xml = Papercraft.xml {
|
|
817
894
|
}
|
818
895
|
```
|
819
896
|
|
897
|
+
[SOAP docs](https://www.rubydoc.info/gems/papercraft/Papercraft/Extensions/Soap)
|
898
|
+
|
820
899
|
## API Reference
|
821
900
|
|
822
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
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'papercraft'
|
4
|
+
require 'tilt'
|
5
|
+
|
6
|
+
# Tilt.
|
7
|
+
module Tilt
|
8
|
+
# Papercraft templating engine for Tilt
|
9
|
+
class PapercraftTemplate < Template
|
10
|
+
metadata[:mime_type] = 'text/html'
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def prepare
|
15
|
+
inner = eval("proc { |scope:, locals:, block:|\n#{data}\n}")
|
16
|
+
@template = Papercraft.html(&inner)
|
17
|
+
end
|
18
|
+
|
19
|
+
def evaluate(scope, locals, &block)
|
20
|
+
@template.render(scope: scope, locals: locals, block: block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
register(PapercraftTemplate, 'papercraft')
|
25
|
+
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
|
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
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.0
|
117
|
+
version: 2.1.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.0
|
124
|
+
version: 2.1.0
|
125
125
|
description:
|
126
126
|
email: sharon@noteflakes.com
|
127
127
|
executables: []
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/papercraft/template.rb
|
144
144
|
- lib/papercraft/version.rb
|
145
145
|
- lib/papercraft/xml.rb
|
146
|
+
- lib/tilt/papercraft.rb
|
146
147
|
- papercraft.png
|
147
148
|
homepage: http://github.com/digital-fabric/papercraft
|
148
149
|
licenses:
|