hmote 1.3.0 → 1.4.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/.gems +0 -2
- data/README.md +4 -81
- data/lib/hmote/version.rb +1 -1
- metadata +3 -5
- data/lib/hmote/render.rb +0 -45
- data/test/render.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 855833b547b4d187ff22113c18fe341b5c51d5cb
|
4
|
+
data.tar.gz: ede1156a3d50af5965e2bf39a5bd9dc550feb767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8f3e5add70ab91115ffd4c3ec06fccee2527e3a77351aa2d225f7dbf5ee43a4777c70f7c4e54ecbcd598f9b1b7c8f7f9efa48a68d95a48e0b876d16a5d21006
|
7
|
+
data.tar.gz: d38d472e9bc930879e9261f1ddfa6c4e4a00255c0dbc236a1274489af5c1f8c0524a40bca639ea2f0b65535db23d34e614e0c11655254c6c251f5cd398a4cd9a
|
data/.gems
CHANGED
data/README.md
CHANGED
@@ -127,87 +127,10 @@ For example:
|
|
127
127
|
hmote("foo.mote", a: 1, b: 2)
|
128
128
|
```
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
To use HMote in [Cuba][cuba], you need to load the `HMote::Render`
|
134
|
-
plugin as shown below:
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
require "hmote"
|
138
|
-
require "hmote/render"
|
139
|
-
|
140
|
-
Cuba.plugin(HMote::Render)
|
141
|
-
```
|
142
|
-
|
143
|
-
`HMote::Render` provides three helper methods for rendering templates:
|
144
|
-
`partial`, `view` and `render`.
|
130
|
+
Related projects:
|
131
|
+
-----------------
|
145
132
|
|
146
|
-
|
147
|
-
Cuba.define do
|
148
|
-
on "about" do
|
149
|
-
# `partial` renders a template without a layout.
|
150
|
-
res.write partial("about")
|
151
|
-
end
|
152
|
-
|
153
|
-
on "home" do
|
154
|
-
# `view` renders a template within a layout.
|
155
|
-
res.write view("about")
|
156
|
-
end
|
157
|
-
|
158
|
-
on "contact" do
|
159
|
-
# `render` is a shortcut to `res.write view(...)`
|
160
|
-
render("contact")
|
161
|
-
end
|
162
|
-
end
|
163
|
-
```
|
164
|
-
|
165
|
-
By default, `HMote::Render` assumes that all view templates are placed
|
166
|
-
in a folder named `views` and that they use the `.mote` extension. Also
|
167
|
-
for `view` and `render` methods, it assumes that the layout template is
|
168
|
-
called `layout.mote`.
|
169
|
-
|
170
|
-
The defaults can be changed through the `Cuba.settings` method:
|
171
|
-
|
172
|
-
```ruby
|
173
|
-
Cuba.settings[:hmote][:views] = "./views/admin/"
|
174
|
-
Cuba.settings[:hmote][:layout] = "admin"
|
175
|
-
```
|
176
|
-
|
177
|
-
### Layouts
|
178
|
-
|
179
|
-
To render inner content into a layout, use the `{{! content }}` tag.
|
180
|
-
|
181
|
-
```html
|
182
|
-
<html>
|
183
|
-
<head>
|
184
|
-
<title>Mote Layout</title>
|
185
|
-
</head>
|
186
|
-
<body>
|
187
|
-
<h1>Hello, world!</h1>
|
188
|
-
|
189
|
-
{{! content }}
|
190
|
-
</body>
|
191
|
-
</html>
|
192
|
-
```
|
193
|
-
|
194
|
-
### Helpers
|
195
|
-
|
196
|
-
You can use the `app` variable to access the application helpers.
|
197
|
-
|
198
|
-
```ruby
|
199
|
-
Cuba.define do
|
200
|
-
def h(unsafe)
|
201
|
-
...
|
202
|
-
end
|
203
|
-
end
|
204
|
-
```
|
205
|
-
|
206
|
-
```html
|
207
|
-
<h1>{{! app.h("unsafe") }}</h1>
|
208
|
-
|
209
|
-
{{ app.partial("list") }}
|
210
|
-
```
|
133
|
+
- [hmote-render][hmote-render]: HMote plugin for Cuba.
|
211
134
|
|
212
135
|
Installation
|
213
136
|
------------
|
@@ -216,7 +139,7 @@ Installation
|
|
216
139
|
$ gem install hmote
|
217
140
|
```
|
218
141
|
|
219
|
-
[cuba]: http://cuba.is
|
220
142
|
[mote]: https://github.com/soveran/mote
|
221
143
|
[hache]: https://github.com/harmoni/hache
|
144
|
+
[hmote-render]: https://github.com/harmoni/hmote-render
|
222
145
|
[xss]: http://en.wikipedia.org/wiki/Cross-Site_Scripting
|
data/lib/hmote/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hmote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hache
|
@@ -62,14 +62,12 @@ files:
|
|
62
62
|
- benchmarks/templates/mote
|
63
63
|
- hmote.gemspec
|
64
64
|
- lib/hmote.rb
|
65
|
-
- lib/hmote/render.rb
|
66
65
|
- lib/hmote/version.rb
|
67
66
|
- makefile
|
68
67
|
- test/foo.mote
|
69
68
|
- test/helper.rb
|
70
69
|
- test/helpers.rb
|
71
70
|
- test/parsing.rb
|
72
|
-
- test/render.rb
|
73
71
|
- test/views/context.mote
|
74
72
|
- test/views/home.mote
|
75
73
|
- test/views/layout.mote
|
@@ -93,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
91
|
version: '0'
|
94
92
|
requirements: []
|
95
93
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.4.
|
94
|
+
rubygems_version: 2.4.8
|
97
95
|
signing_key:
|
98
96
|
specification_version: 4
|
99
97
|
summary: A minimum operational template that escapes HTML tags by default.
|
data/lib/hmote/render.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require_relative "../hmote"
|
2
|
-
|
3
|
-
module HMote::Render
|
4
|
-
include HMote::Helpers
|
5
|
-
|
6
|
-
CONTENT_TYPE = "Content-Type".freeze
|
7
|
-
DEFAULT_CONTENT_TYPE = "text/html; charset=utf-8".freeze
|
8
|
-
|
9
|
-
def self.setup(app)
|
10
|
-
app.settings[:hmote] ||= {}
|
11
|
-
|
12
|
-
app.layout("layout")
|
13
|
-
app.view_path("views")
|
14
|
-
end
|
15
|
-
|
16
|
-
def render(template, params = {}, layout = settings[:hmote][:layout])
|
17
|
-
res.status ||= 200
|
18
|
-
res.headers[CONTENT_TYPE] ||= DEFAULT_CONTENT_TYPE
|
19
|
-
res.write(view(template, params, layout))
|
20
|
-
|
21
|
-
halt(res.finish)
|
22
|
-
end
|
23
|
-
|
24
|
-
def view(template, params = {}, layout = settings[:hmote][:layout])
|
25
|
-
return partial(layout, params.merge(content: partial(template, params)))
|
26
|
-
end
|
27
|
-
|
28
|
-
def partial(template, params = {})
|
29
|
-
return hmote(template_path(template), params.merge(app: self), TOPLEVEL_BINDING)
|
30
|
-
end
|
31
|
-
|
32
|
-
def template_path(template)
|
33
|
-
return File.join(settings[:hmote][:views], "#{template}.mote")
|
34
|
-
end
|
35
|
-
|
36
|
-
module ClassMethods
|
37
|
-
def layout(name)
|
38
|
-
settings[:hmote][:layout] = name
|
39
|
-
end
|
40
|
-
|
41
|
-
def view_path(path)
|
42
|
-
settings[:hmote][:views] = File.expand_path(path, Dir.pwd)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/test/render.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
require "cuba/test"
|
3
|
-
require_relative "../lib/hmote/render"
|
4
|
-
|
5
|
-
Cuba.plugin(HMote::Render)
|
6
|
-
Cuba.settings[:hmote][:views] = "./test/views"
|
7
|
-
|
8
|
-
Cuba.define do
|
9
|
-
def name
|
10
|
-
"App"
|
11
|
-
end
|
12
|
-
|
13
|
-
on "partial" do
|
14
|
-
res.write partial("home")
|
15
|
-
end
|
16
|
-
|
17
|
-
on "view" do
|
18
|
-
res.write view("home", title: "Hello")
|
19
|
-
end
|
20
|
-
|
21
|
-
on "render" do
|
22
|
-
render("home", title: "Hola")
|
23
|
-
end
|
24
|
-
|
25
|
-
on "context" do
|
26
|
-
res.write partial("context")
|
27
|
-
end
|
28
|
-
|
29
|
-
on "halt" do
|
30
|
-
render("home", title: "Halt before error")
|
31
|
-
raise "This is invalid"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
scope do
|
36
|
-
test "view renders view with layout" do
|
37
|
-
expected = "<title>Hello</title>\n<h1>Home</h1>"
|
38
|
-
|
39
|
-
get "/view"
|
40
|
-
|
41
|
-
assert last_response.body[expected]
|
42
|
-
end
|
43
|
-
|
44
|
-
test "partial renders view without layout" do
|
45
|
-
get "/partial"
|
46
|
-
|
47
|
-
assert last_response.body["<h1>Home</h1>"]
|
48
|
-
end
|
49
|
-
|
50
|
-
test "render renders view with layout" do
|
51
|
-
get "/render"
|
52
|
-
|
53
|
-
assert last_response.body["<title>Hola</title>\n<h1>Home</h1>"]
|
54
|
-
end
|
55
|
-
|
56
|
-
test "access to application context" do
|
57
|
-
get "/context"
|
58
|
-
|
59
|
-
assert last_response.body["App"]
|
60
|
-
end
|
61
|
-
|
62
|
-
test "render halts request" do
|
63
|
-
get "/halt"
|
64
|
-
|
65
|
-
assert true
|
66
|
-
end
|
67
|
-
end
|