calyx 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/docs/_data/breadcrumbs.yml +9 -0
  3. data/docs/_data/docs.yml +35 -0
  4. data/docs/_data/examples.yml +9 -0
  5. data/docs/_includes/breadcrumbs.html +36 -0
  6. data/docs/_includes/contents.html +12 -0
  7. data/docs/_includes/icon-github.html +4 -0
  8. data/docs/_includes/icon-rubygems.html +9 -0
  9. data/docs/_includes/navbar.html +24 -0
  10. data/docs/_includes/pagebar.html +12 -0
  11. data/docs/_layouts/default.html +3 -23
  12. data/docs/_layouts/docs.html +14 -0
  13. data/docs/_layouts/home.html +13 -0
  14. data/docs/_layouts/page.html +20 -0
  15. data/docs/_posts/2017-09-14-welcome-to-jekyll.markdown +1 -1
  16. data/docs/_posts/2017-09-21-0.17.0-released.md +10 -0
  17. data/docs/_styles/card.scss +7 -0
  18. data/docs/_styles/colors.scss +18 -0
  19. data/docs/_styles/content.scss +57 -0
  20. data/docs/_styles/cta.scss +25 -0
  21. data/docs/_styles/grid.scss +22 -0
  22. data/docs/_styles/media.scss +50 -0
  23. data/docs/_styles/menu.scss +54 -0
  24. data/docs/_styles/modifiers.scss +3 -0
  25. data/docs/_styles/navbar.scss +161 -0
  26. data/docs/_styles/pagebar.scss +32 -0
  27. data/docs/_styles/reset.scss +92 -0
  28. data/docs/_styles/scale.scss +23 -0
  29. data/docs/_styles/spread.scss +55 -0
  30. data/docs/_styles/styleguide.scss +52 -0
  31. data/docs/_styles/syntax.scss +84 -0
  32. data/docs/_styles/typography.scss +49 -0
  33. data/docs/_styles/yard.scss +36 -0
  34. data/docs/api.html +9662 -0
  35. data/docs/assets/calyx-docs.css +253 -162
  36. data/docs/assets/calyx-flower-outline.svg +202 -0
  37. data/docs/assets/calyx-flower-reverse.svg +202 -0
  38. data/docs/assets/calyx-flower.svg +202 -0
  39. data/docs/assets/logo-small.png +0 -0
  40. data/docs/assets/logos/calyx-flower-1.svg +22 -0
  41. data/docs/assets/logos/calyx-flower-2.svg +21 -0
  42. data/docs/content/documentation.html +20 -0
  43. data/docs/content/examples.html +12 -0
  44. data/docs/content/examples/any-gradient.md +32 -0
  45. data/docs/content/examples/faker.md +16 -0
  46. data/docs/content/examples/tiny-woodland-bot.md +24 -0
  47. data/docs/{guide → content/guides}/context.md +2 -2
  48. data/docs/{guide → content/guides}/expressions.md +2 -2
  49. data/docs/content/guides/features.md +50 -0
  50. data/docs/{guide → content/guides}/formats.md +1 -1
  51. data/docs/content/guides/installation.md +51 -0
  52. data/docs/{guide → content/guides}/random.md +1 -1
  53. data/docs/{guide → content/guides}/results.md +1 -1
  54. data/docs/content/index.html +44 -0
  55. data/docs/content/introduction.md +23 -0
  56. data/docs/content/introduction/concepts.md +82 -0
  57. data/docs/content/introduction/contributing.md +43 -0
  58. data/docs/content/introduction/tutorial.md +129 -0
  59. data/docs/content/styleguide.html +71 -0
  60. data/docs/docs.scss +94 -0
  61. data/docs/index.html +1 -23
  62. data/docs/package.json +1 -1
  63. data/lib/calyx/production/choices.rb +7 -0
  64. data/lib/calyx/production/unique.rb +0 -2
  65. data/lib/calyx/registry.rb +5 -0
  66. data/lib/calyx/rule.rb +4 -0
  67. data/lib/calyx/version.rb +1 -1
  68. metadata +59 -13
  69. data/docs/about.md +0 -18
  70. data/docs/calyx-docs.scss +0 -66
  71. data/docs/guide/examples.md +0 -59
  72. data/docs/guide/getting-started.md +0 -129
  73. data/docs/guide/installation.md +0 -19
@@ -0,0 +1,43 @@
1
+ ---
2
+ title: Contributing to Calyx
3
+ layout: docs
4
+ permalink: /introduction/contributing/
5
+ ---
6
+
7
+ # Contributing to Calyx
8
+
9
+ Calyx is an open source project and contributions are welcome.
10
+
11
+ ## General Contributions
12
+
13
+ The best way to contribute is to use the Gem. Install it on a local project and try things out. Does it work? Does it do what you expect? Is there anything missing?
14
+
15
+ It’s really helpful to contribute to discussion on open issues, reporting bugs or suggest new features. Any feedback and criticism is received with gratitude.
16
+
17
+ ## Code Contributions
18
+
19
+ Changes that fix bugs and improve test coverage will generally be merged on-the-spot. Larger changes that introduce new features should harmonise with the vision, goals and style of the project. If in doubt, just ask in advance.
20
+
21
+ ### Submitting Changes
22
+
23
+ Changes to the source code and documentation should be submitted as a pull request on GitHub, corresponding to the following process:
24
+
25
+ - Fork the repo and make a new branch for your changes
26
+ - Submit your branch as a pull request against the master branch
27
+
28
+ If any aspects of your changes need further explanation, use the pull request description to provide further detail and context (including code samples as necessary).
29
+
30
+ Please don’t bump the version as part of your pull request (this happens separately).
31
+
32
+ ### Pull Request Checklist
33
+
34
+ - Extraneous and trivial small commits should be squashed into larger descriptive commits
35
+ - Commits should include concise and clear messages using standard formatting conventions
36
+ - The test suite must be passing
37
+ - Newly introduced code branches should be covered by tests
38
+ -- Introduce new tests if existing tests don’t support your changes
39
+ - Changes to method signatures and class organisation should be annotated by doc comments
40
+
41
+ ## Code of Conduct
42
+
43
+ Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
@@ -0,0 +1,129 @@
1
+ ---
2
+ title: Tutorial
3
+ layout: docs
4
+ permalink: /introduction/tutorial
5
+ ---
6
+
7
+ ## Objective
8
+
9
+ This tutorial introduces Calyx with a basic ‘hello world’ example. Following these steps will help you get Calyx up and running and provide you with a code skeleton to start adding more interesting and creative things.
10
+
11
+ ## Initial setup
12
+
13
+ Before getting started, you’ll need to install Calyx from RubyGems and have it available in your local dev environment:
14
+
15
+ ```
16
+ gem install calyx
17
+ ```
18
+
19
+ If you’re not sure how to do this yet, there’s more information about setting up your Ruby environment in the [resources for beginners](/introduction/beginners/). The [installation guide](/docs/guide/installation/) contains further details about prerequisites and how to download and install the Gem.
20
+
21
+ ## Getting started
22
+
23
+ Create a file named `hello.rb` and add the following contents:
24
+
25
+ ```ruby
26
+ require "calyx"
27
+
28
+ hello = Calyx::Grammar.new do
29
+ start "Hello world!"
30
+ end
31
+ ```
32
+
33
+ The first line imports the Calyx library and the lines following use the `Calyx::Grammar` class to define the rules for the generated text, in this case just ‘Hello world!’.
34
+
35
+ To generate the text result, call the `#generate` method on the grammar object. Add this to the bottom of the `hello.rb` file:
36
+
37
+ ```ruby
38
+ puts hello.generate
39
+ ```
40
+
41
+ Run it on the command line by typing `ruby hello.rb`. You should see the following result:
42
+
43
+ ```
44
+ Hello world!
45
+ ```
46
+
47
+ ## Adding random choices
48
+
49
+ Obviously, this hardcoded sentence isn’t very interesting by itself. To add variety to the text, rules can be defined with multiple choices to pick from:
50
+
51
+ ```ruby
52
+ hello = Calyx::Grammar.new do
53
+ start 'Hello world!', 'Hi world!', 'Hey world!'
54
+ end
55
+ ```
56
+
57
+ Each time `#generate` runs, Calyx evaluates the grammar and randomly selects a single choice from the list of possible choices. So if we run the grammar three times, we might see three different results:
58
+
59
+ ```ruby
60
+ hello.generate
61
+ # => Hi world!
62
+
63
+ hello.generate
64
+ # => Hello world!
65
+
66
+ hello.generate
67
+ # => Yo world!
68
+ ```
69
+
70
+ ## Nesting rules inside rules
71
+
72
+ When you embed the name of a rule in curly brackets inside a text fragment, Calyx will expand the embedded rule and replace it with generated output each time the grammar runs.
73
+
74
+ The following example nests the `greeting` rule within the `start` rule:
75
+
76
+ ```ruby
77
+ hello = Calyx::Grammar.new do
78
+ start '{greeting} world!'
79
+ greeting 'Hello', 'Hi', 'Hey', 'Yo'
80
+ end
81
+ ```
82
+
83
+ This generates the exact same text as before, but listing the greeting words on their own is more flexible and eliminates the need to write each variation of the phrase out in full.
84
+
85
+ This process of starting with a larger fragment of text and breaking it up into smaller phrases and single words is something you’ll do a lot when writing larger and more detailed grammars.
86
+
87
+ ## Using nesting to shape the text
88
+
89
+ Rules can be arbitrarily nested and connected to generate larger and more complex texts. The way the rules branch out is going to define the shape and ‘flavor’ of the text.
90
+
91
+ For example, to create more exaggerated variations of the phrase, we can branch out to pick from a list of happy adjectives or a list of sad adjectives:
92
+
93
+ ```ruby
94
+ hello = Calyx::Grammar.new do
95
+ start '{greeting} {world_phrase}.'
96
+ greeting 'Hello', 'Hi', 'Hey', 'Yo'
97
+ world_phrase '{happy_adj} world', '{sad_adj} world', 'world'
98
+ happy_adj 'wonderful', 'amazing', 'bright', 'beautiful'
99
+ sad_adj 'cruel', 'miserable'
100
+ end
101
+ ```
102
+
103
+ Nesting and branching can be manipulated to balance consistency with novelty. The exact same text fragments can be combined in a variety of ways to produce strikingly different resulting texts.
104
+
105
+ The following grammar branches out at the top level, with `happy_phrase` and `sad_phrase` being generated from completely separate trees that don’t overlap:
106
+
107
+ ```ruby
108
+ hello = Calyx::Grammar.new do
109
+ start '{happy_phrase} world.', '{sad_phrase} world.'
110
+ happy_phrase '{happy_greeting} {happy_adj}'
111
+ happy_greeting 'Hello', 'Hi', 'Hey', 'Yo'
112
+ happy_adj 'wonderful', 'amazing', 'bright', 'beautiful'
113
+ sad_phrase '{sad_greeting} {sad_adj}'
114
+ sad_greeting 'Goodbye', 'So long', 'Farewell'
115
+ sad_adj 'cruel', 'miserable'
116
+ end
117
+ ```
118
+
119
+ Whereas this variation of the grammar uses the same content but generates everything from a single branch, resulting in a word salad with happy and sad fragments mashed together:
120
+
121
+ ```ruby
122
+ hello = Calyx::Grammar.new do
123
+ start '{greeting} {adj} world.'
124
+ greeting 'Hello', 'Hi', 'Hey', 'Yo', 'Goodbye', 'So long', 'Farewell'
125
+ adj 'wonderful', 'amazing', 'bright', 'beautiful', 'cruel', 'miserable'
126
+ end
127
+ ```
128
+
129
+ That’s really all you need to know to get started.
@@ -0,0 +1,71 @@
1
+ ---
2
+ layout: default
3
+ title: Styleguide
4
+ permalink: /styleguide/
5
+ ---
6
+
7
+ <h2>Logo</h2>
8
+
9
+ <div class="card">
10
+ <img src="/assets/calyx-flower.svg" width="200" height="200">
11
+ </div>
12
+
13
+ <h2>Colors</h2>
14
+
15
+ <div class="columns">
16
+
17
+ <div class="column">
18
+ <div class="card">
19
+ <div class="card-header">
20
+ <div class="color-chip color-aquamarine"></div>
21
+ </div>
22
+ <div class="card-body">
23
+ <p>Aquamarine</p>
24
+ </div>
25
+ </div>
26
+ </div>
27
+
28
+ <div class="column">
29
+ <div class="card">
30
+ <div class="card-header">
31
+ <div class="color-chip color-meadow"></div>
32
+ </div>
33
+ <div class="card-body">
34
+ <p>Meadow</p>
35
+ </div>
36
+ </div>
37
+ </div>
38
+
39
+ <div class="column">
40
+ <div class="card">
41
+ <div class="card-header">
42
+ <div class="color-chip color-eucalyptus"></div>
43
+ </div>
44
+ <div class="card-body">
45
+ <p>Eucalyptus</p>
46
+ </div>
47
+ </div>
48
+ </div>
49
+
50
+ <div class="column">
51
+ <div class="card">
52
+ <div class="card-header">
53
+ <div class="color-chip color-stromboli"></div>
54
+ </div>
55
+ <div class="card-body">
56
+ <p>Stromboli</p>
57
+ </div>
58
+ </div>
59
+ </div>
60
+
61
+ </div>
62
+
63
+ <h2>Scale</h2>
64
+
65
+ <div class="content">
66
+ <p class="p0">Wavering Plywood Handgloves</p>
67
+ <p class="p1">Wavering Plywood Handgloves</p>
68
+ <p class="p2">Wavering Plywood Handgloves</p>
69
+ <p class="p3">Wavering Plywood Handgloves</p>
70
+ <p class="p4">Wavering Plywood Handgloves</p>
71
+ </div>
@@ -0,0 +1,94 @@
1
+ @import "_styles/reset";
2
+ @import "_styles/media";
3
+ @import "_styles/colors";
4
+ @import "_styles/typography";
5
+ @import "_styles/modifiers";
6
+ @import "_styles/grid";
7
+ @import "_styles/menu";
8
+ @import "_styles/styleguide";
9
+ @import "_styles/navbar";
10
+ @import "_styles/pagebar";
11
+ @import "_styles/syntax";
12
+ @import "_styles/spread";
13
+ @import "_styles/cta";
14
+ @import "_styles/yard";
15
+ @import "_styles/card";
16
+ @import "_styles/content";
17
+
18
+ .container {
19
+ width: 60%;
20
+ margin: $scale-p2 auto;
21
+ color: $color-dark;
22
+ line-height: 1.5;
23
+
24
+ h1 {
25
+ color: $color-eucalyptus;
26
+ }
27
+
28
+ a {
29
+ color: $color-dark;
30
+ border-bottom: 1px solid $color-meadow;
31
+ padding-left: $scale-m2;
32
+
33
+ &:before {
34
+ padding-right: $scale-m2;
35
+ content: "→";
36
+ }
37
+ }
38
+ }
39
+
40
+ .page {
41
+ background-color: $color-page-background;
42
+ min-height: calc(100vh - #{$navbar-height} - #{$pagebar-height} - #{$scale-p1});
43
+ }
44
+
45
+ .docs-sidebar {
46
+ background-color: $color-sidebar-background;
47
+
48
+ @include at-least-tablet {
49
+ .menu-label,
50
+ .menu-list li {
51
+ font-size: $scale-m1;
52
+ }
53
+ }
54
+
55
+ @include until-tablet {
56
+ .menu-label,
57
+ .menu-list li {
58
+ a {
59
+ padding-left: $scale-p3;
60
+ }
61
+ }
62
+ }
63
+
64
+ @include tablet {
65
+ width: $scale-p0 * 10;
66
+ }
67
+
68
+ @include desktop {
69
+ width: $scale-p0 * 10;
70
+ }
71
+ }
72
+
73
+ .docs-content {
74
+ order: 2;
75
+ min-width: 83.3333333%;
76
+ }
77
+
78
+
79
+
80
+ .content-footer {
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: space-between;
84
+
85
+ .content-footer-col {
86
+ border: 1px solid red;
87
+ //padding: $scale-p3;
88
+ }
89
+ }
90
+
91
+ .navbar.is-fixed + .spread,
92
+ .navbar.is-fixed + .page {
93
+ margin-top: ($scale-p0 + $scale-m3) * 3;
94
+ }
@@ -2,31 +2,9 @@
2
2
  layout: home
3
3
  ---
4
4
 
5
- {% include navbar.html %}
6
-
7
- <div class="spread spread-hero">
8
- <figure class="identity">
9
- <img src="/assets/logos/calyx-flower-2.svg" width="80%" height="80%">
10
- </figure>
11
- <div class="lede">
12
- <h2>Create writing machines with generative grammars</h2>
13
-
14
- <ul class="cta-list">
15
- <li><a class="cta-button" href="#">Download</a></li>
16
- <li><a class="cta-button" href="#">Learn more</a></li>
17
- </ul>
18
- </div>
19
- </div>
20
-
21
- <div class="spread spread-intro">
22
- <p>Calyx is a simple and powerful generative grammar tool for creating writing machines using the Ruby programming language.</p>
23
- </div>
24
-
25
5
  <div class="content">
26
6
  <h1>Calyx</h1>
27
- <p>Calyx provides a simple and powerful generative grammar format for creating writing machines using the Ruby programming language.</p>
28
- <p>Although the primary use case is procedurally generating text, Calyx grammars can be used to make anything where the output format is a string.</p>
29
- <p>Calyx provides a simple Ruby API for creating writing machines of all shapes and sizes using generative grammars.</p>
7
+ <p>Calyx provides a simple Ruby API for generating text with template expansion grammars.</p>
30
8
  <ul>
31
9
  <li><a href="https://github.com/maetl/calyx">Source code on GitHub</a></li>
32
10
  <li><a href="https://rubygems.org/gems/calyx">Package on Rubygems</a></li>
@@ -3,7 +3,7 @@
3
3
  "version": "1.0.0",
4
4
  "main": "index.html",
5
5
  "scripts": {
6
- "build": "node-sass --include-path node_modules/bulma calyx-docs.scss assets/calyx-docs.css",
6
+ "build": "node-sass --include-path node_modules/bulma docs.scss assets/calyx-docs.css",
7
7
  "watch": "node-sass --watch --include-path node_modules/bulma docs.scss assets/calyx-docs.css",
8
8
  "help": "node-sass --help"
9
9
  },
@@ -34,6 +34,13 @@ module Calyx
34
34
  @collection = collection
35
35
  end
36
36
 
37
+ # The number of possible choices available for this rule.
38
+ #
39
+ # @return [Integer]
40
+ def size
41
+ @collection.size
42
+ end
43
+
37
44
  # Evaluate the choice by randomly picking one of its possible options.
38
45
  #
39
46
  # @param [Calyx::Options] options
@@ -4,8 +4,6 @@ module Calyx
4
4
  # returns values that have not previously been selected. The probability
5
5
  # that a given rule will be selected increases as more selections are made
6
6
  # and the list grows smaller.
7
- #
8
- # TODO: handle wraparound
9
7
  class Unique
10
8
  SIGIL = '$'.freeze
11
9
 
@@ -128,6 +128,11 @@ module Calyx
128
128
  uniques[symbol] = [] if uniques[symbol].nil?
129
129
 
130
130
  while pending
131
+ if uniques[symbol].size == @rules[symbol].size
132
+ uniques[symbol] = []
133
+ pending = false
134
+ end
135
+
131
136
  result = expand(symbol).evaluate(@options)
132
137
 
133
138
  unless uniques[symbol].include?(result)
@@ -10,6 +10,10 @@ module Calyx
10
10
  @trace = trace
11
11
  end
12
12
 
13
+ def size
14
+ productions.size
15
+ end
16
+
13
17
  def evaluate(options)
14
18
  productions.evaluate(options)
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.17.1'.freeze
2
+ VERSION = '0.18.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.17.1
4
+ version: 0.18.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: 2017-10-08 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,19 +72,65 @@ files:
72
72
  - docs/404.html
73
73
  - docs/CNAME
74
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
75
84
  - docs/_layouts/default.html
85
+ - docs/_layouts/docs.html
86
+ - docs/_layouts/home.html
87
+ - docs/_layouts/page.html
76
88
  - docs/_posts/2017-09-14-welcome-to-jekyll.markdown
77
- - docs/about.md
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
78
108
  - docs/assets/calyx-docs.css
79
- - docs/calyx-docs.scss
80
- - docs/guide/context.md
81
- - docs/guide/examples.md
82
- - docs/guide/expressions.md
83
- - docs/guide/formats.md
84
- - docs/guide/getting-started.md
85
- - docs/guide/installation.md
86
- - docs/guide/random.md
87
- - docs/guide/results.md
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
88
134
  - docs/index.html
89
135
  - docs/package-lock.json
90
136
  - docs/package.json
@@ -130,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
176
  version: '0'
131
177
  requirements: []
132
178
  rubyforge_project:
133
- rubygems_version: 2.6.13
179
+ rubygems_version: 2.7.6
134
180
  signing_key:
135
181
  specification_version: 4
136
182
  summary: Generate text with declarative recursive grammars