calyx 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +33 -0
  3. data/.travis.yml +1 -1
  4. data/lib/calyx.rb +1 -0
  5. data/lib/calyx/grammar.rb +12 -0
  6. data/lib/calyx/mapping.rb +15 -0
  7. data/lib/calyx/modifiers.rb +10 -0
  8. data/lib/calyx/production/weighted_choices.rb +7 -0
  9. data/lib/calyx/registry.rb +2 -12
  10. data/lib/calyx/rule.rb +14 -4
  11. data/lib/calyx/version.rb +1 -1
  12. metadata +5 -69
  13. data/docs/404.html +0 -7
  14. data/docs/CNAME +0 -1
  15. data/docs/_config.yml +0 -27
  16. data/docs/_data/breadcrumbs.yml +0 -9
  17. data/docs/_data/docs.yml +0 -35
  18. data/docs/_data/examples.yml +0 -9
  19. data/docs/_includes/breadcrumbs.html +0 -36
  20. data/docs/_includes/contents.html +0 -12
  21. data/docs/_includes/icon-github.html +0 -4
  22. data/docs/_includes/icon-rubygems.html +0 -9
  23. data/docs/_includes/navbar.html +0 -24
  24. data/docs/_includes/pagebar.html +0 -12
  25. data/docs/_layouts/default.html +0 -13
  26. data/docs/_layouts/docs.html +0 -14
  27. data/docs/_layouts/home.html +0 -13
  28. data/docs/_layouts/page.html +0 -20
  29. data/docs/_posts/2017-09-14-welcome-to-jekyll.markdown +0 -25
  30. data/docs/_posts/2017-09-21-0.17.0-released.md +0 -10
  31. data/docs/_styles/card.scss +0 -7
  32. data/docs/_styles/colors.scss +0 -18
  33. data/docs/_styles/content.scss +0 -57
  34. data/docs/_styles/cta.scss +0 -25
  35. data/docs/_styles/grid.scss +0 -22
  36. data/docs/_styles/media.scss +0 -50
  37. data/docs/_styles/menu.scss +0 -54
  38. data/docs/_styles/modifiers.scss +0 -3
  39. data/docs/_styles/navbar.scss +0 -161
  40. data/docs/_styles/pagebar.scss +0 -32
  41. data/docs/_styles/reset.scss +0 -92
  42. data/docs/_styles/scale.scss +0 -23
  43. data/docs/_styles/spread.scss +0 -55
  44. data/docs/_styles/styleguide.scss +0 -52
  45. data/docs/_styles/syntax.scss +0 -84
  46. data/docs/_styles/typography.scss +0 -49
  47. data/docs/_styles/yard.scss +0 -36
  48. data/docs/api.html +0 -9662
  49. data/docs/assets/calyx-docs.css +0 -792
  50. data/docs/assets/calyx-flower-outline.svg +0 -202
  51. data/docs/assets/calyx-flower-reverse.svg +0 -202
  52. data/docs/assets/calyx-flower.svg +0 -202
  53. data/docs/assets/logo-small.png +0 -0
  54. data/docs/assets/logos/calyx-flower-1.svg +0 -22
  55. data/docs/assets/logos/calyx-flower-2.svg +0 -21
  56. data/docs/content/documentation.html +0 -20
  57. data/docs/content/examples.html +0 -12
  58. data/docs/content/examples/any-gradient.md +0 -32
  59. data/docs/content/examples/faker.md +0 -16
  60. data/docs/content/examples/tiny-woodland-bot.md +0 -24
  61. data/docs/content/guides/context.md +0 -45
  62. data/docs/content/guides/expressions.md +0 -175
  63. data/docs/content/guides/features.md +0 -50
  64. data/docs/content/guides/formats.md +0 -37
  65. data/docs/content/guides/installation.md +0 -51
  66. data/docs/content/guides/random.md +0 -100
  67. data/docs/content/guides/results.md +0 -62
  68. data/docs/content/index.html +0 -44
  69. data/docs/content/introduction.md +0 -23
  70. data/docs/content/introduction/concepts.md +0 -82
  71. data/docs/content/introduction/contributing.md +0 -43
  72. data/docs/content/introduction/tutorial.md +0 -129
  73. data/docs/content/styleguide.html +0 -71
  74. data/docs/docs.scss +0 -94
  75. data/docs/index.html +0 -12
  76. data/docs/package-lock.json +0 -1536
  77. data/docs/package.json +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbece8aa49b259e11dfd37c03f3ea13050349f30c003bf8f9874bb069e3b4866
4
- data.tar.gz: fe7e4b4df68c0daf35688b5c103b85302ae953d98d0e326f9e087d5d1d7fdf9c
3
+ metadata.gz: 88debcd6bac2845d1d5b6c932aff212a3d93a900cfb6758db486500f49987e7e
4
+ data.tar.gz: 7a22972ac485e7147f0855bac351badaa25876978655191e75327a54a404cd4d
5
5
  SHA512:
6
- metadata.gz: 7237633f9354a5e81b05b8840b514ab2060b45d936b496e2cb47abdefce019c6d14a7350f416f1137866e73d84f5a1e169cbda78c879aa49d0c83543c0cd3f06
7
- data.tar.gz: babf2c39c0550cbdccc8e5a2822ae8030f827e96f424a17e9ffdd22a13d22504610400b19425b3dde9dd4a9932285253d03f3d52a23c20751791e4139601bc7d
6
+ metadata.gz: 716f85a44ca0e852c96695ffdd6ddb91b298c5c6579a61d5082893be445ab78d6e8b7b37ac0f50eac2169f14ada86c0001cabf7c354ae4ba6ecd763c0335de8e
7
+ data.tar.gz: 63de5c1d2d1ccaa74232eb3c7535df24cdce5fc2065bedc2cf90a8a590080397d9e1881cbee15501aeb8ef61f206b561e5e2888f0c7dee22680eefbb83c1e615
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ # uses: ruby/setup-ruby@v1
27
+ uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
28
+ with:
29
+ ruby-version: 2.6
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run tests
33
+ run: bundle exec rspec
@@ -5,6 +5,6 @@ rvm:
5
5
  - 2.6
6
6
  - ruby-head
7
7
  - jruby-9.1.13.0
8
- - rbx-3
8
+ - rbx
9
9
  before_install: gem install bundler
10
10
  script: bundle exec rspec
@@ -8,6 +8,7 @@ require 'calyx/errors'
8
8
  require 'calyx/format'
9
9
  require 'calyx/registry'
10
10
  require 'calyx/modifiers'
11
+ require 'calyx/mapping'
11
12
  require 'calyx/production/memo'
12
13
  require 'calyx/production/unique'
13
14
  require 'calyx/production/choices'
@@ -33,6 +33,10 @@ module Calyx
33
33
  #
34
34
  # @param [Module] module_name
35
35
  def modifier(module_name)
36
+ warn [
37
+ "NOTE: Loading modifiers via grammar class methods is deprecated.",
38
+ "Alternative API TBD. For now this method still works."
39
+ ].join
36
40
  registry.modifier(module_name)
37
41
  end
38
42
 
@@ -41,6 +45,10 @@ module Calyx
41
45
  # @param [Symbol] name
42
46
  # @param [Hash<Regex,String>] pairs
43
47
  def mapping(name, pairs)
48
+ warn [
49
+ "NOTE: The fixed `mapping` class method is deprecated.",
50
+ "This still works but will be replaced with a new mapping format."
51
+ ].join
44
52
  registry.mapping(name, pairs)
45
53
  end
46
54
 
@@ -50,6 +58,10 @@ module Calyx
50
58
  # @yieldparam [String] the input string to be processed by the filter
51
59
  # @yieldreturn [String] the processed output string
52
60
  def filter(name, &block)
61
+ warn [
62
+ "NOTE: The fixed `filter` class method is deprecated.",
63
+ "This will be removed in 0.22. Use the API for modifers instead."
64
+ ].join
53
65
  registry.filter(name, &block)
54
66
  end
55
67
 
@@ -0,0 +1,15 @@
1
+ module Calyx
2
+ class Mapping
3
+ def initialize
4
+ @key = "key"
5
+ @value = "value"
6
+ end
7
+
8
+ def call(input)
9
+ if @key == input then @value
10
+ else
11
+ ""
12
+ end
13
+ end
14
+ end
15
+ end
@@ -20,5 +20,15 @@ module Calyx
20
20
  value
21
21
  end
22
22
  end
23
+
24
+ def upper(value)
25
+ value.upcase
26
+ end
27
+
28
+ def lower(value)
29
+ value.downcase
30
+ end
31
+
32
+
23
33
  end
24
34
  end
@@ -63,6 +63,13 @@ module Calyx
63
63
  @collection = collection
64
64
  end
65
65
 
66
+ # The number of possible choices available for this rule.
67
+ #
68
+ # @return [Integer]
69
+ def size
70
+ @collection.size
71
+ end
72
+
66
73
  # Evaluate the choice by randomly picking one of its possible options,
67
74
  # balanced according to the given weights.
68
75
  #
@@ -67,7 +67,7 @@ module Calyx
67
67
  # @param [Symbol] name
68
68
  # @param [Array] productions
69
69
  def define_rule(name, trace, productions)
70
- rules[name.to_sym] = Rule.new(name.to_sym, construct_rule(productions), trace)
70
+ rules[name.to_sym] = Rule.new(name.to_sym, Rule.build_ast(productions, self), trace)
71
71
  end
72
72
 
73
73
  # Defines a rule in the temporary evaluation context.
@@ -76,7 +76,7 @@ module Calyx
76
76
  # @param [Array] productions
77
77
  def define_context_rule(name, trace, productions)
78
78
  productions = [productions] unless productions.is_a?(Enumerable)
79
- context[name.to_sym] = Rule.new(name.to_sym, construct_rule(productions), trace)
79
+ context[name.to_sym] = Rule.new(name.to_sym, Rule.build_ast(productions, self), trace)
80
80
  end
81
81
 
82
82
  # Expands the given symbol to its rule.
@@ -197,15 +197,5 @@ module Calyx
197
197
  end
198
198
  }
199
199
  end
200
-
201
- def construct_rule(productions)
202
- if productions.first.is_a?(Hash)
203
- Production::WeightedChoices.parse(productions.first.to_a, self)
204
- elsif productions.first.is_a?(Enumerable)
205
- Production::WeightedChoices.parse(productions, self)
206
- else
207
- Production::Choices.parse(productions, self)
208
- end
209
- end
210
200
  end
211
201
  end
@@ -2,20 +2,30 @@ module Calyx
2
2
  # Represents a named rule connected to a tree of productions that can be
3
3
  # evaluated and a trace which represents where the rule was declared.
4
4
  class Rule
5
- attr_reader :name, :productions, :trace
5
+ def self.build_ast(productions, registry)
6
+ if productions.first.is_a?(Hash)
7
+ Production::WeightedChoices.parse(productions.first.to_a, registry)
8
+ elsif productions.first.is_a?(Enumerable)
9
+ Production::WeightedChoices.parse(productions, registry)
10
+ else
11
+ Production::Choices.parse(productions, registry)
12
+ end
13
+ end
14
+
15
+ attr_reader :name, :tree, :trace
6
16
 
7
17
  def initialize(name, productions, trace)
8
18
  @name = name.to_sym
9
- @productions = productions
19
+ @tree = productions
10
20
  @trace = trace
11
21
  end
12
22
 
13
23
  def size
14
- productions.size
24
+ tree.size
15
25
  end
16
26
 
17
27
  def evaluate(options)
18
- productions.evaluate(options)
28
+ tree.evaluate(options)
19
29
  end
20
30
  end
21
31
  end
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.20.0'.freeze
2
+ VERSION = '0.21.0'.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.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-07 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".github/workflows/ruby.yml"
63
64
  - ".gitignore"
64
65
  - ".travis.yml"
65
66
  - CODE_OF_CONDUCT.md
@@ -69,71 +70,6 @@ files:
69
70
  - README.md
70
71
  - SYNTAX.md
71
72
  - calyx.gemspec
72
- - docs/404.html
73
- - docs/CNAME
74
- - docs/_config.yml
75
- - docs/_data/breadcrumbs.yml
76
- - docs/_data/docs.yml
77
- - docs/_data/examples.yml
78
- - docs/_includes/breadcrumbs.html
79
- - docs/_includes/contents.html
80
- - docs/_includes/icon-github.html
81
- - docs/_includes/icon-rubygems.html
82
- - docs/_includes/navbar.html
83
- - docs/_includes/pagebar.html
84
- - docs/_layouts/default.html
85
- - docs/_layouts/docs.html
86
- - docs/_layouts/home.html
87
- - docs/_layouts/page.html
88
- - docs/_posts/2017-09-14-welcome-to-jekyll.markdown
89
- - docs/_posts/2017-09-21-0.17.0-released.md
90
- - docs/_styles/card.scss
91
- - docs/_styles/colors.scss
92
- - docs/_styles/content.scss
93
- - docs/_styles/cta.scss
94
- - docs/_styles/grid.scss
95
- - docs/_styles/media.scss
96
- - docs/_styles/menu.scss
97
- - docs/_styles/modifiers.scss
98
- - docs/_styles/navbar.scss
99
- - docs/_styles/pagebar.scss
100
- - docs/_styles/reset.scss
101
- - docs/_styles/scale.scss
102
- - docs/_styles/spread.scss
103
- - docs/_styles/styleguide.scss
104
- - docs/_styles/syntax.scss
105
- - docs/_styles/typography.scss
106
- - docs/_styles/yard.scss
107
- - docs/api.html
108
- - docs/assets/calyx-docs.css
109
- - docs/assets/calyx-flower-outline.svg
110
- - docs/assets/calyx-flower-reverse.svg
111
- - docs/assets/calyx-flower.svg
112
- - docs/assets/logo-small.png
113
- - docs/assets/logos/calyx-flower-1.svg
114
- - docs/assets/logos/calyx-flower-2.svg
115
- - docs/content/documentation.html
116
- - docs/content/examples.html
117
- - docs/content/examples/any-gradient.md
118
- - docs/content/examples/faker.md
119
- - docs/content/examples/tiny-woodland-bot.md
120
- - docs/content/guides/context.md
121
- - docs/content/guides/expressions.md
122
- - docs/content/guides/features.md
123
- - docs/content/guides/formats.md
124
- - docs/content/guides/installation.md
125
- - docs/content/guides/random.md
126
- - docs/content/guides/results.md
127
- - docs/content/index.html
128
- - docs/content/introduction.md
129
- - docs/content/introduction/concepts.md
130
- - docs/content/introduction/contributing.md
131
- - docs/content/introduction/tutorial.md
132
- - docs/content/styleguide.html
133
- - docs/docs.scss
134
- - docs/index.html
135
- - docs/package-lock.json
136
- - docs/package.json
137
73
  - examples/any_gradient.rb
138
74
  - examples/faker.json
139
75
  - examples/faker.rb
@@ -142,6 +78,7 @@ files:
142
78
  - lib/calyx/errors.rb
143
79
  - lib/calyx/format.rb
144
80
  - lib/calyx/grammar.rb
81
+ - lib/calyx/mapping.rb
145
82
  - lib/calyx/modifiers.rb
146
83
  - lib/calyx/options.rb
147
84
  - lib/calyx/production/choices.rb
@@ -175,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
112
  - !ruby/object:Gem::Version
176
113
  version: '0'
177
114
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.7.6
115
+ rubygems_version: 3.1.2
180
116
  signing_key:
181
117
  specification_version: 4
182
118
  summary: Generate text with declarative recursive grammars
@@ -1,7 +0,0 @@
1
- ---
2
- layout: default
3
- ---
4
- <div class="content">
5
- <h1>Not found</h1>
6
- <p>Whatever you were looking for is not here.</p>
7
- </div>
data/docs/CNAME DELETED
@@ -1 +0,0 @@
1
- calyx-rb.org
@@ -1,27 +0,0 @@
1
- title: Calyx
2
- email: me@maetl.net
3
- description: >
4
- A Ruby library for generating text with template expansion grammars.
5
- baseurl: "" # the subpath of your site, e.g. /blog
6
- url: "" # the base hostname & protocol for your site, e.g. http://example.com
7
- twitter_username: maetl
8
- github_username: maetl
9
-
10
- # Build settings
11
- markdown: kramdown
12
- plugins:
13
- - jekyll-feed
14
-
15
- highlighter: rouge
16
-
17
- # Exclude from processing.
18
- # The following items will not be processed, by default. Create a custom list
19
- # to override the default setting.
20
- # exclude:
21
- # - Gemfile
22
- # - Gemfile.lock
23
- # - node_modules
24
- # - vendor/bundle/
25
- # - vendor/cache/
26
- # - vendor/gems/
27
- # - vendor/ruby/
@@ -1,9 +0,0 @@
1
- documentation:
2
- title: Documentation
3
- permalink: /documentation/
4
- introduction:
5
- title: Introduction
6
- permalink: /introduction/
7
- guides:
8
- title: Guides
9
- permalink: /guides/
@@ -1,35 +0,0 @@
1
- - title: Introduction
2
- permalink: /introduction/
3
- pages:
4
- - title: Tutorial
5
- permalink: /introduction/tutorial
6
- - title: Key Concepts
7
- permalink: /introduction/concepts
8
- - title: For Beginners
9
- permalink: /introduction/beginners
10
- - title: Contributing
11
- permalink: /introduction/contributing
12
- - title: Guides
13
- permalink: /guides/
14
- pages:
15
- - title: Installation
16
- permalink: /guides/installation
17
- - title: Generating Results
18
- permalink: /guides/results
19
- - title: Dynamic Rules
20
- permalink: /guides/dynamic-rules
21
- - title: Template Expressions
22
- permalink: /guides/template-expressions
23
- - title: Weighted Choices
24
- permalink: /guides/weighted-choices
25
- - title: Extending Grammars
26
- permalink: /guides/extending
27
- - title: Random Seeds
28
- permalink: /guides/random-seeds
29
- - title: Reference
30
- permalink: /reference/
31
- pages:
32
- - title: Configuration Options
33
- permalink: /reference/config
34
- - title: API Listing
35
- permalink: /reference/api
@@ -1,9 +0,0 @@
1
- - title: Tiny Woodland Bot
2
- description: Minimalist Twitter emoji scenes.
3
- permalink: /examples/tiny-woodland-bot
4
- - title: Any Gradient
5
- description: A web service making linear gradients.
6
- permalink: /examples/any-gradient
7
- - title: Faker
8
- description: Generates fake names and email addresses.
9
- permalink: /examples/faker
@@ -1,36 +0,0 @@
1
- <ol itemscope itemtype="http://schema.org/BreadcrumbList">
2
-
3
- {% assign counter=0 %}
4
-
5
- {% for category in site.categories %}
6
-
7
- {% capture category_url %}{{ site.category_dir }}/{{ category | first | slugize | downcase | replace:' ','-' }}{% endcapture %}
8
- {% capture category_name %}{{ category | first}}{% endcapture %}
9
-
10
- {% for catpagename in page.categories %}
11
- {% if category_name == catpagename %}
12
-
13
- {% assign counter=counter | plus:1 %}
14
-
15
- <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
16
- <a itemprop="item" href="{{ site.url }}{{ append:'/' | append:category_url | append:'/' }}">
17
- <span itemprop="name">{{ catpagename }}</span>
18
- </a>
19
- <meta itemprop="position" content="{{counter}}" />
20
- </li>
21
-
22
- {% endif %}
23
- {% endfor %}
24
-
25
- {% endfor %}
26
-
27
- {% assign counter=counter | plus:1 %}
28
-
29
- <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
30
- <a itemprop="item" href="{{ site.url }}{{ page.url }}">
31
- <span itemprop="name">{{ page.title }}</span>
32
- </a>
33
- <meta itemprop="position" content="{{counter}}" />
34
- </li>
35
-
36
- </ol>