calyx 0.10.3 → 0.10.4

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: 1318f87b80baddcf2bc2782a3c93b710912c78af
4
- data.tar.gz: 30461744ff65201a6ecb2bacbdb5492bf60e0685
3
+ metadata.gz: 78e2075bb19864a35f97504f1d2afc2e09b186ab
4
+ data.tar.gz: 1e474a6d3bac3d62d5a8b25c5ad75ec724a95a44
5
5
  SHA512:
6
- metadata.gz: 133902fc4013dd5d271a8dc01456e96f7776133cfdecb8deb21c805c7763b25c42bc9d403faa67aaf145e0981d10faa793aefae1f744381cba2cd6e753d6fff5
7
- data.tar.gz: f480d4901162ce5eb2a9809b87dfcc87e7b5282e4c179332ec48f318ae9f90fd5abb82b72d45e85a0136084f761da0f3217fda3db72e8668cbb9178a18e6e6cc
6
+ metadata.gz: 8d4facec94b4ffd5c29bfb53d4f8cd6b0de4939d9937ed0853a15420246deeee0fb543ae210e6462b4b707f1c82bd9c462b54b427a8637bf35b7536bb3a4b842
7
+ data.tar.gz: fd89979f568bd4ec3bd3655dfcacddf405841766ed7bef6a32a8d2d7a0ce501aa3bbc4fa85e67a0455106701f50787c071afbd6f4a6eb02d091f46c9a67a2be7
data/README.md CHANGED
@@ -299,7 +299,7 @@ Rough plan for stabilising the API and features for a `1.0` release.
299
299
  | `0.7` | ~~support for template context map passed to generate~~ |
300
300
  | `0.8` | ~~method missing metaclass API~~ |
301
301
  | `0.9` | ~~return grammar tree from `#evaluate`, with flattened string from `#generate` being separate~~ |
302
- | `0.10` | inject custom string functions for parameterised rules, transforms and mappings |
302
+ | `0.10` | ~~inject custom string functions for parameterised rules, transforms and mappings~~ |
303
303
  | `0.11` | support YAML format (and JSON?) |
304
304
  | `1.0` | API documentation |
305
305
 
data/lib/calyx.rb CHANGED
@@ -3,6 +3,7 @@ require 'calyx/grammar'
3
3
  require 'calyx/errors'
4
4
  require 'calyx/file_converter'
5
5
  require 'calyx/registry'
6
+ require 'calyx/modifier'
6
7
  require 'calyx/production/memo'
7
8
  require 'calyx/production/choices'
8
9
  require 'calyx/production/concat'
data/lib/calyx/grammar.rb CHANGED
@@ -5,6 +5,10 @@ module Calyx
5
5
  @registry ||= Registry.new
6
6
  end
7
7
 
8
+ def modifier(name)
9
+ registry.modifier(name)
10
+ end
11
+
8
12
  def mapping(name, pairs)
9
13
  registry.mapping(name, pairs)
10
14
  end
@@ -0,0 +1,17 @@
1
+ module Calyx
2
+ class Modifier
3
+ def extend_with(name)
4
+ extend name
5
+ end
6
+
7
+ def transform(name, value)
8
+ if respond_to?(name)
9
+ send(name, value)
10
+ elsif value.respond_to?(name)
11
+ value.send(name)
12
+ else
13
+ value
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,25 +1,30 @@
1
1
  module Calyx
2
2
  class Registry
3
- attr_reader :rules, :mappings
3
+ attr_reader :rules, :transforms
4
4
 
5
5
  def initialize
6
6
  @rules = {}
7
- @mappings = {}
7
+ @transforms = {}
8
+ @modifier = Modifier.new
8
9
  end
9
10
 
10
11
  def method_missing(name, *arguments)
11
12
  rule(name, *arguments)
12
13
  end
13
14
 
15
+ def modifier(name)
16
+ @modifier.extend_with(name)
17
+ end
18
+
14
19
  def mapping(name, pairs)
15
- mappings[name.to_sym] = construct_mapping(pairs)
20
+ transforms[name.to_sym] = construct_mapping(pairs)
16
21
  end
17
22
 
18
23
  def filter(name, callable=nil, &block)
19
24
  if block_given?
20
- mappings[name.to_sym] = block
25
+ transforms[name.to_sym] = block
21
26
  else
22
- mappings[name.to_sym] = callable
27
+ transforms[name.to_sym] = callable
23
28
  end
24
29
  end
25
30
 
@@ -32,12 +37,10 @@ module Calyx
32
37
  end
33
38
 
34
39
  def transform(name, value)
35
- if value.respond_to?(name)
36
- value.send(name)
37
- elsif mappings.key?(name)
38
- mappings[name].call(value)
40
+ if transforms.key?(name)
41
+ transforms[name].call(value)
39
42
  else
40
- value
43
+ @modifier.transform(name, value)
41
44
  end
42
45
  end
43
46
 
data/lib/calyx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.10.3'.freeze
2
+ VERSION = '0.10.4'.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.10.3
4
+ version: 0.10.4
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-05-30 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - lib/calyx/errors.rb
72
72
  - lib/calyx/file_converter.rb
73
73
  - lib/calyx/grammar.rb
74
+ - lib/calyx/modifier.rb
74
75
  - lib/calyx/production/choices.rb
75
76
  - lib/calyx/production/concat.rb
76
77
  - lib/calyx/production/expression.rb