calyx 0.7.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4116e94128a27a95985b8fa9780de2eabfec427c
4
- data.tar.gz: 5b396249d4439e4a849b57ded682778e9b695be0
3
+ metadata.gz: 2bd547cabae5575236b9ef076d641c222365c207
4
+ data.tar.gz: 3a534687dc5371ade6bb88b06ff4059a20b25c7b
5
5
  SHA512:
6
- metadata.gz: 1a48eb785e80d97e999cae3dfe9b254ebb68982dffe959e7d823bbdc73204b4baab96803a1a6693f1fddb80d5f6fb21c6350d43ffcf99967ccabc7cd11df7908
7
- data.tar.gz: 8b83890ae677018d977e4cc3435ac414de947806af2fe912eeab12fee541ba0d3daf206989fc0f0a227c3987f5f3184f853e048cf36365384f9a9c27feda7887
6
+ metadata.gz: 86fdb69a40b9f57995da80c8318e38992b7588053c73824207ea058cf2262d3bc90fe87fea0e6f3e2967a0403239da2db70a14c799a2829ccddd2355e690f1af
7
+ data.tar.gz: 7252174f84e3edc72cf8e6e8dee901c4c2f8ba9b3aa746b3d62f577d48d620c8946efacdab01b6373c9afe18488c2b846abccc1f62c53e6258c3f6984acf266a
data/README.md CHANGED
@@ -219,6 +219,25 @@ end
219
219
  # => "A pear."
220
220
  ```
221
221
 
222
+ ### Dynamically Constructing Rules
223
+
224
+ Template expansions can be dynamically constructed at runtime by passing a context map of rules to the `#generate` method:
225
+
226
+ ```ruby
227
+ class AppGreeting < Calyx::Grammar
228
+ start 'Hi {username}!', 'Welcome back {username}...', 'Hola {username}'
229
+ end
230
+
231
+ context = {
232
+ username: UserModel.username
233
+ }
234
+
235
+ greeting = AppGreeting.new
236
+ greeting.generate(context)
237
+ ```
238
+
239
+ __Note: This feature is still experimental, and the API may morph and change a bit as we try to figure out the best patterns for merging and combining grammars.__
240
+
222
241
  ## Roadmap
223
242
 
224
243
  Rough plan for stabilising the API and features for a `1.0` release.
@@ -226,13 +245,18 @@ Rough plan for stabilising the API and features for a `1.0` release.
226
245
  | Version | Features planned |
227
246
  |---------|------------------|
228
247
  | `0.6` | ~~block constructor~~ |
229
- | `0.7` | support for template context map passed to generate |
248
+ | `0.7` | ~~support for template context map passed to generate~~ |
230
249
  | `0.8` | return grammar tree from evaluate/generate, with to_s being separate |
231
250
  | `0.9` | support mixin/composition of rule sets rather than inheritance |
232
251
  | `0.10` | support YAML format (and JSON?) |
233
252
  | `0.11` | method missing metaclass API |
234
253
  | `1.0` | API documentation |
235
254
 
255
+ ## Credits
256
+
257
+ - [Mark Rickerby](https://github.com/maetl) (author and maintainer)
258
+ - [Tariq Ali](https://github.com/tra38)
259
+
236
260
  ## License
237
261
 
238
262
  Calyx is open source and provided under the terms of the MIT license. Copyright (c) 2015 Mark Rickerby
@@ -24,19 +24,21 @@ module Calyx
24
24
  end
25
25
 
26
26
  def evaluate(context={})
27
+ duplicate_registry = Marshal.load(Marshal.dump(self))
28
+ duplicate_rules = duplicate_registry.rules
27
29
  context.each do |key, value|
28
- if @rules.key?(key.to_sym)
30
+ if duplicate_rules.key?(key.to_sym)
29
31
  raise "Rule already declared in grammar: #{key}"
30
32
  end
31
33
 
32
- @rules[key.to_sym] = if value.is_a?(Array)
33
- Production::Choices.parse(value, self)
34
+ duplicate_rules[key.to_sym] = if value.is_a?(Array)
35
+ Production::Choices.parse(value, duplicate_registry)
34
36
  else
35
- Production::Concat.parse(value.to_s, self)
37
+ Production::Concat.parse(value.to_s, duplicate_registry)
36
38
  end
37
39
  end
38
40
 
39
- @rules[:start].evaluate
41
+ duplicate_rules[:start].evaluate
40
42
  end
41
43
 
42
44
  private
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.7.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calyx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler