papercraft 0.28 → 0.29
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 +40 -0
- data/lib/papercraft/version.rb +1 -1
- data/lib/tilt/papercraft.rb +25 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ca707074311c909d6e2b4aa86748f1ffbd5b614d73fb78e85985d174b69e263
|
4
|
+
data.tar.gz: f53dc4fa5088472ccc805f50938f25539950446fe14e97facb2cc346722d13fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d216f2c8db4beed8c7fe184d3b8e0a13ba8af4684d4e46f5506f0b1eb6c3bfaa0ad76b7a5b1b6e28a8ba37a730545ca00139fd0bf35b74628d117c504fc1e9c
|
7
|
+
data.tar.gz: 27ac04cf8b75b5d6abda511513618fb6ef20417365ac7b45855d909323db3c536204f85d719a44e2374b095d955f4eb0c25901290990dab861c908fa4d73142e
|
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)
|
@@ -126,6 +127,45 @@ Rendering a template is done using `#render`:
|
|
126
127
|
html.render #=> "<div id="greeter"><p>Hello!</p></div>"
|
127
128
|
```
|
128
129
|
|
130
|
+
## Using with Tilt
|
131
|
+
|
132
|
+
Papercraft templates can also be rendered using Tilt:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
require 'tilt/papercraft'
|
136
|
+
|
137
|
+
# loading from a file (with a .papercraft extension)
|
138
|
+
template = Tilt.new('mytemplate.papercraft')
|
139
|
+
template.render
|
140
|
+
|
141
|
+
# defining a template inline:
|
142
|
+
template = Tilt['papercraft'].new { <<~RUBY
|
143
|
+
h1 'Hello'
|
144
|
+
RUBY
|
145
|
+
}
|
146
|
+
template.render
|
147
|
+
```
|
148
|
+
|
149
|
+
When rendering using Tilt, the following local variables are available to the
|
150
|
+
template: `scope`, `locals` and `block`:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
template = Tilt['papercraft'].new { <<~RUBY
|
154
|
+
title scope.title
|
155
|
+
|
156
|
+
h1 locals[:message]
|
157
|
+
|
158
|
+
emit block if block
|
159
|
+
RUBY
|
160
|
+
}
|
161
|
+
|
162
|
+
def title
|
163
|
+
'foo'
|
164
|
+
end
|
165
|
+
|
166
|
+
template.render(self, message: 'bar') { p 'this is a paragraph' }
|
167
|
+
```
|
168
|
+
|
129
169
|
## Adding Tags
|
130
170
|
|
131
171
|
Tags are added using unqualified method calls, and can be nested using blocks:
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papercraft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.29'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -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:
|