mustachers 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 856f256560d1bde9d3a7c00bb9ff0aa79b3dc00d4a999f46c57193c7d70c82fd
4
+ data.tar.gz: 4dfd897b7d42617534044a649618897df0743e37b06fa3a3c75b9ffe9d1c576e
5
+ SHA512:
6
+ metadata.gz: 5c4391f93cf872b2aa394400b2b815b572d7a19bed4353cee82a537bc1d1be7df064256ff5a49a6c65b1a867a3cd616de7e257ba8a8548f2c120ba88c227aae8
7
+ data.tar.gz: 344d0c30e6286aeef9b3b775d0f7d5a0f716d04037d6cec6fc1e602db6872ed180e48602f80ade7661ade00ca10e6916f8ed9744e57f21f2a64cce2c491bd01e
data/Cargo.lock ADDED
@@ -0,0 +1,321 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.0.2"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.62.0"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "c6720a8b7b2d39dd533285ed438d458f65b31b5c257e6ac7bb3d7e82844dd722"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "lazy_static",
24
+ "lazycell",
25
+ "peeking_take_while",
26
+ "proc-macro2",
27
+ "quote",
28
+ "regex",
29
+ "rustc-hash",
30
+ "shlex",
31
+ "syn",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "bitflags"
36
+ version = "1.3.2"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
39
+
40
+ [[package]]
41
+ name = "cexpr"
42
+ version = "0.6.0"
43
+ source = "registry+https://github.com/rust-lang/crates.io-index"
44
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
45
+ dependencies = [
46
+ "nom",
47
+ ]
48
+
49
+ [[package]]
50
+ name = "cfg-if"
51
+ version = "1.0.0"
52
+ source = "registry+https://github.com/rust-lang/crates.io-index"
53
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
54
+
55
+ [[package]]
56
+ name = "clang-sys"
57
+ version = "1.6.1"
58
+ source = "registry+https://github.com/rust-lang/crates.io-index"
59
+ checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
60
+ dependencies = [
61
+ "glob",
62
+ "libc",
63
+ "libloading",
64
+ ]
65
+
66
+ [[package]]
67
+ name = "glob"
68
+ version = "0.3.1"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
71
+
72
+ [[package]]
73
+ name = "lazy_static"
74
+ version = "1.4.0"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
77
+
78
+ [[package]]
79
+ name = "lazycell"
80
+ version = "1.3.0"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
83
+
84
+ [[package]]
85
+ name = "libc"
86
+ version = "0.2.147"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
89
+
90
+ [[package]]
91
+ name = "libloading"
92
+ version = "0.7.4"
93
+ source = "registry+https://github.com/rust-lang/crates.io-index"
94
+ checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
95
+ dependencies = [
96
+ "cfg-if",
97
+ "winapi",
98
+ ]
99
+
100
+ [[package]]
101
+ name = "log"
102
+ version = "0.3.9"
103
+ source = "registry+https://github.com/rust-lang/crates.io-index"
104
+ checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
105
+ dependencies = [
106
+ "log 0.4.19",
107
+ ]
108
+
109
+ [[package]]
110
+ name = "log"
111
+ version = "0.4.19"
112
+ source = "registry+https://github.com/rust-lang/crates.io-index"
113
+ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
114
+
115
+ [[package]]
116
+ name = "magnus"
117
+ version = "0.4.4"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "fc87660cd7daa49fddbfd524c836de54d5c927d520cd163f43700c5087c57d6c"
120
+ dependencies = [
121
+ "magnus-macros",
122
+ "rb-sys",
123
+ "rb-sys-env",
124
+ ]
125
+
126
+ [[package]]
127
+ name = "magnus-macros"
128
+ version = "0.3.0"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "206cb23bfeea05180c97522ef6a3e52a4eb17b0ed2f30ee3ca9c4f994d2378ae"
131
+ dependencies = [
132
+ "proc-macro2",
133
+ "quote",
134
+ "syn",
135
+ ]
136
+
137
+ [[package]]
138
+ name = "memchr"
139
+ version = "2.5.0"
140
+ source = "registry+https://github.com/rust-lang/crates.io-index"
141
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
142
+
143
+ [[package]]
144
+ name = "minimal-lexical"
145
+ version = "0.2.1"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
148
+
149
+ [[package]]
150
+ name = "mustache"
151
+ version = "0.9.0"
152
+ source = "registry+https://github.com/rust-lang/crates.io-index"
153
+ checksum = "51956ef1c5d20a1384524d91e616fb44dfc7d8f249bf696d49c97dd3289ecab5"
154
+ dependencies = [
155
+ "log 0.3.9",
156
+ "serde",
157
+ ]
158
+
159
+ [[package]]
160
+ name = "mustachers"
161
+ version = "0.1.0"
162
+ dependencies = [
163
+ "magnus",
164
+ "mustache",
165
+ ]
166
+
167
+ [[package]]
168
+ name = "nom"
169
+ version = "7.1.3"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
172
+ dependencies = [
173
+ "memchr",
174
+ "minimal-lexical",
175
+ ]
176
+
177
+ [[package]]
178
+ name = "peeking_take_while"
179
+ version = "0.1.2"
180
+ source = "registry+https://github.com/rust-lang/crates.io-index"
181
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
182
+
183
+ [[package]]
184
+ name = "proc-macro2"
185
+ version = "1.0.66"
186
+ source = "registry+https://github.com/rust-lang/crates.io-index"
187
+ checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
188
+ dependencies = [
189
+ "unicode-ident",
190
+ ]
191
+
192
+ [[package]]
193
+ name = "quote"
194
+ version = "1.0.32"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
197
+ dependencies = [
198
+ "proc-macro2",
199
+ ]
200
+
201
+ [[package]]
202
+ name = "rb-sys"
203
+ version = "0.9.79"
204
+ source = "registry+https://github.com/rust-lang/crates.io-index"
205
+ checksum = "939fb78db3e4f26665c1d4c7b91ca66d3578335a19aba552d4a6445811d07072"
206
+ dependencies = [
207
+ "rb-sys-build",
208
+ ]
209
+
210
+ [[package]]
211
+ name = "rb-sys-build"
212
+ version = "0.9.79"
213
+ source = "registry+https://github.com/rust-lang/crates.io-index"
214
+ checksum = "335a95eb0420d52fa94ef12019df3c2c250c6b19cbb3c60bd05cb7e9c362072c"
215
+ dependencies = [
216
+ "bindgen",
217
+ "lazy_static",
218
+ "proc-macro2",
219
+ "quote",
220
+ "regex",
221
+ "shell-words",
222
+ "syn",
223
+ ]
224
+
225
+ [[package]]
226
+ name = "rb-sys-env"
227
+ version = "0.1.2"
228
+ source = "registry+https://github.com/rust-lang/crates.io-index"
229
+ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
230
+
231
+ [[package]]
232
+ name = "regex"
233
+ version = "1.9.1"
234
+ source = "registry+https://github.com/rust-lang/crates.io-index"
235
+ checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575"
236
+ dependencies = [
237
+ "aho-corasick",
238
+ "memchr",
239
+ "regex-automata",
240
+ "regex-syntax",
241
+ ]
242
+
243
+ [[package]]
244
+ name = "regex-automata"
245
+ version = "0.3.3"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310"
248
+ dependencies = [
249
+ "aho-corasick",
250
+ "memchr",
251
+ "regex-syntax",
252
+ ]
253
+
254
+ [[package]]
255
+ name = "regex-syntax"
256
+ version = "0.7.4"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
259
+
260
+ [[package]]
261
+ name = "rustc-hash"
262
+ version = "1.1.0"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
265
+
266
+ [[package]]
267
+ name = "serde"
268
+ version = "1.0.175"
269
+ source = "registry+https://github.com/rust-lang/crates.io-index"
270
+ checksum = "5d25439cd7397d044e2748a6fe2432b5e85db703d6d097bd014b3c0ad1ebff0b"
271
+
272
+ [[package]]
273
+ name = "shell-words"
274
+ version = "1.1.0"
275
+ source = "registry+https://github.com/rust-lang/crates.io-index"
276
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
277
+
278
+ [[package]]
279
+ name = "shlex"
280
+ version = "1.1.0"
281
+ source = "registry+https://github.com/rust-lang/crates.io-index"
282
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
283
+
284
+ [[package]]
285
+ name = "syn"
286
+ version = "1.0.109"
287
+ source = "registry+https://github.com/rust-lang/crates.io-index"
288
+ checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
289
+ dependencies = [
290
+ "proc-macro2",
291
+ "quote",
292
+ "unicode-ident",
293
+ ]
294
+
295
+ [[package]]
296
+ name = "unicode-ident"
297
+ version = "1.0.11"
298
+ source = "registry+https://github.com/rust-lang/crates.io-index"
299
+ checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
300
+
301
+ [[package]]
302
+ name = "winapi"
303
+ version = "0.3.9"
304
+ source = "registry+https://github.com/rust-lang/crates.io-index"
305
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
306
+ dependencies = [
307
+ "winapi-i686-pc-windows-gnu",
308
+ "winapi-x86_64-pc-windows-gnu",
309
+ ]
310
+
311
+ [[package]]
312
+ name = "winapi-i686-pc-windows-gnu"
313
+ version = "0.4.0"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
316
+
317
+ [[package]]
318
+ name = "winapi-x86_64-pc-windows-gnu"
319
+ version = "0.4.0"
320
+ source = "registry+https://github.com/rust-lang/crates.io-index"
321
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/mustachers"]
7
+ resolver = "2"
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Mustachers
2
+
3
+ Providing mustache rendering using Rust by wrapping the mustache crate.
4
+
5
+ At the moment only a simple render function taking a template file and parameters to interpolate. This does not look to replace or compete with the ruby offering, but provides an alternative seemingly offering a performance enhancement.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add mustachers
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install mustachers
16
+
17
+ ## Usage
18
+
19
+ Require the gem if needed. Some might be dynamically loaded.
20
+ ```rb
21
+ require 'mustachers'
22
+
23
+ ```
24
+
25
+ An example of using the gem.
26
+ ```rb
27
+ Mustachers::Renderer.render("<h1>{{text}}</h1>", {text: "abc123"})
28
+ ```
29
+
30
+ From the console.
31
+ ```sh
32
+ bundle exec ruby -r mustachers -e 'puts Mustachers::Renderer.render("<h1>{{text}}</h1>", {text: "abc123"})'
33
+ <h1>abc123</h1>
34
+ ```
35
+
36
+ ## Benchmark
37
+ The script for this can be found in the [benchmarks directory](./benchmarks/simple.rb).
38
+ ```sh
39
+ bundle exec ruby benchmarks/simple.rb
40
+ user system total real
41
+ 236.928979 1.059659 237.988638 (239.572824) # ruby
42
+ 13.929279 0.069823 13.999102 ( 14.088116) # rust
43
+ ```
44
+
45
+ ## Development
46
+
47
+ TODO:
48
+ - [ ] Check Ruby performance such as any memory leaks and garbage collection.
49
+ - [ ] Improve the error handling to raise an appropriate error.
50
+ - [ ] Unit tests in rust to provide faster feedback while developing.
51
+ - [ ] More options for the template rendering such as reading the file.
52
+ - [ ] Benchmarking with different sized inputs.
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/samfrench/mustachers.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rb_sys/extensiontask"
5
+
6
+ task build: :compile
7
+
8
+ RbSys::ExtensionTask.new("mustachers") do |ext|
9
+ ext.lib_dir = "lib/mustachers"
10
+ end
11
+
12
+ task default: :compile
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ require 'benchmark'
4
+ require 'mustache'
5
+ require 'mustachers'
6
+
7
+ template = '<html lang="{{{lang}}}"/>{{{ top }}}{{{ middle }}}{{{ bottom }}}'
8
+
9
+ params = {
10
+ top: '<h1>Page heading</h1>',
11
+ middle: '<p>Paragraph of text.</p>',
12
+ bottom: '<a href="#about">Page link</a>',
13
+ lang: 'en-GB',
14
+ foo: 'bar'
15
+ }
16
+
17
+ n = 1_000_000
18
+ Benchmark.bm do |x|
19
+ x.report { n.times do; Mustache.render(template, params); end }
20
+ x.report { n.times do; Mustachers::Renderer.render(template, params); end }
21
+ end
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "mustachers"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["Sam French <Sam.French@bbc.co.uk>"]
6
+ publish = false
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ magnus = { version = "0.4" }
13
+ mustache = "0.9.0"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("mustachers/mustachers")
@@ -0,0 +1,29 @@
1
+ extern crate mustache;
2
+
3
+ use std::collections::HashMap;
4
+ use magnus::{define_module, prelude::*, Error, function, RHash, Symbol, r_hash::ForEach};
5
+
6
+ fn render(template: String, params: RHash) -> Result<String, Error> {
7
+ let template = mustache::compile_str(&template).expect("Failed to compile");
8
+ let mut bytes = vec![];
9
+ let mut data: HashMap<String, String> = HashMap::new();
10
+
11
+ params.foreach(|key: Symbol, value: String| {
12
+ data.insert(key.to_string(), value);
13
+
14
+ return Ok(ForEach::Continue);
15
+ })?;
16
+
17
+ template.render(&mut bytes, &data).expect("Failed to render");
18
+
19
+ return Ok(String::from_utf8(bytes).expect("Failed to encode string"));
20
+ }
21
+
22
+ #[magnus::init]
23
+ fn init() -> Result<(), Error> {
24
+ let mustachers_module = define_module("Mustachers")?;
25
+ let renderer_module = mustachers_module.define_module("Renderer")?;
26
+ renderer_module.define_singleton_method("render", function!(render, 2))?;
27
+
28
+ Ok(())
29
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mustachers
4
+ VERSION = "0.1.1"
5
+ end
data/lib/mustachers.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mustachers/version"
4
+ require_relative "mustachers/mustachers"
5
+
6
+ module Mustachers
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,4 @@
1
+ module Mustachers
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mustachers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam French
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mustache
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ description: Mustache templating with Rust to test performance
42
+ email:
43
+ executables: []
44
+ extensions:
45
+ - ext/mustachers/Cargo.toml
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Cargo.lock
49
+ - Cargo.toml
50
+ - README.md
51
+ - Rakefile
52
+ - benchmarks/simple.rb
53
+ - ext/mustachers/Cargo.toml
54
+ - ext/mustachers/extconf.rb
55
+ - ext/mustachers/src/lib.rs
56
+ - lib/mustachers.rb
57
+ - lib/mustachers/version.rb
58
+ - sig/mustachers.rbs
59
+ homepage: https://github.com/samfrench/mustachers
60
+ licenses: []
61
+ metadata:
62
+ homepage_uri: https://github.com/samfrench/mustachers
63
+ source_code_uri: https://github.com/samfrench/mustachers
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.6.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 3.3.11
78
+ requirements: []
79
+ rubygems_version: 3.4.16
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Mustache templating with Rust
83
+ test_files: []