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
Binary file
@@ -1,22 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <svg width="400px"
3
- height="400px"
4
- version="1.1"
5
- xmlns="http://www.w3.org/2000/svg"
6
- xmlns:xlink="http://www.w3.org/1999/xlink">
7
- <defs>
8
- <symbol id="petals">
9
- <ellipse cx="200" cy="120" rx="37" ry="80" /><ellipse cx="200" cy="280" rx="37" ry="80" /><ellipse cx="280" cy="200" rx="80" ry="37" /><ellipse cx="120" cy="200" rx="80" ry="37" />
10
- </symbol>
11
- <symbol id="corolla">
12
- <use xlink:href="#petals" />
13
- <use xlink:href="#petals" transform="rotate(22.5 200 200)" />
14
- <use xlink:href="#petals" transform="rotate(45 200 200)" />
15
- <use xlink:href="#petals" transform="rotate(-22.5 200 200)" />
16
- </symbol>
17
- </defs>
18
- <use xlink:href="#corolla" fill="#1BDE81" stroke="#2F5E52" stroke-width="16"/>
19
- <use xlink:href="#corolla" fill="#76FABB" stroke="#2F5E52" stroke-width="18" transform="scale(0.80 0.80) translate(50 50)" />
20
- <use xlink:href="#corolla" fill="#218764" stroke="#2F5E52" stroke-width="5" transform="scale(0.40 0.40) translate(300 300)" />
21
- </svg>
22
-
@@ -1,21 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <svg width="400px"
3
- height="400px"
4
- version="1.1"
5
- xmlns="http://www.w3.org/2000/svg"
6
- xmlns:xlink="http://www.w3.org/1999/xlink">
7
- <defs>
8
- <symbol id="petals">
9
- <ellipse cx="200" cy="120" rx="25" ry="80" /><ellipse cx="200" cy="280" rx="25" ry="80" /><ellipse cx="280" cy="200" rx="80" ry="25" /><ellipse cx="120" cy="200" rx="80" ry="25" />
10
- </symbol>
11
- <symbol id="corolla">
12
- <use xlink:href="#petals" />
13
- <use xlink:href="#petals" transform="rotate(22.5 200 200)" />
14
- <use xlink:href="#petals" transform="rotate(45 200 200)" />
15
- <use xlink:href="#petals" transform="rotate(-22.5 200 200)" />
16
- </symbol>
17
- </defs>
18
- <use xlink:href="#corolla" fill="#1BDE81" stroke="#218764" stroke-width="10"/>
19
- <use xlink:href="#corolla" fill="#76FABB" stroke="#1BDE81" stroke-width="18" transform="scale(0.80 0.80) translate(50 50)" />
20
- <use xlink:href="#corolla" fill="#218764" stroke="#76FABB" stroke-width="15" transform="scale(0.40 0.40) translate(300 300)" />
21
- </svg>
@@ -1,20 +0,0 @@
1
- ---
2
- title: Documentation
3
- layout: page
4
- permalink: /docs/
5
- ---
6
-
7
- <div class="row">
8
- {% for section in site.data.docs %}
9
- <div class="col">
10
- <div class="menu">
11
- <h2 class="menu-label"><a href="{{ section.permalink }}">{{ section.title }}</a></h2>
12
- <ul class="menu-list">
13
- {% for doc_page in section.pages %}
14
- <li><a href="{{ doc_page.permalink }}">{{ doc_page.title }}</a></li>
15
- {% endfor %}
16
- </ul>
17
- </div>
18
- </div>
19
- {% endfor %}
20
- </div>
@@ -1,12 +0,0 @@
1
- ---
2
- title: Examples
3
- layout: page
4
- permalink: /examples/
5
- ---
6
-
7
- {% for example in site.data.examples %}
8
- <div class="card">
9
- <h2><a href="{{ example.permalink }}">{{ example.title }}</a></h2>
10
- <p>{{ example.description }}</p>
11
- </div>
12
- {% endfor %}
@@ -1,32 +0,0 @@
1
- ---
2
- layout: default
3
- title: Examples
4
- layout: page
5
- permalink: /examples/any-gradient
6
- ---
7
-
8
- # Examples
9
-
10
- The best way to get started quickly is to install the gem and run the examples locally.
11
-
12
- ## Any Gradient
13
-
14
- Requires Roda and Rack to be available.
15
-
16
- ```
17
- gem install roda
18
- ```
19
-
20
- Demonstrates how to use Calyx to construct SVG graphics. **Any Gradient** generates a rectangle with a linear gradient of random colours.
21
-
22
- Run as a web server and preview the output in a browser (`http://localhost:9292`):
23
-
24
- ```
25
- ruby examples/any_gradient.rb
26
- ```
27
-
28
- Or generate SVG files via a command line pipe:
29
-
30
- ```
31
- ruby examples/any_gradient > gradient1.xml
32
- ```
@@ -1,16 +0,0 @@
1
- ---
2
- layout: default
3
- title: Examples
4
- layout: page
5
- permalink: /examples/faker
6
- ---
7
-
8
- ## Faker
9
-
10
- [Faker](https://github.com/stympy/faker) is a popular library for generating fake names and associated sample data like internet addresses, company names and locations.
11
-
12
- This example demonstrates how to use Calyx to reproduce the same functionality using custom lists defined in a YAML configuration file.
13
-
14
- ```
15
- ruby examples/faker.rb
16
- ```
@@ -1,24 +0,0 @@
1
- ---
2
- layout: default
3
- title: Examples
4
- layout: page
5
- permalink: /examples/tiny-woodland-bot
6
- ---
7
-
8
- ## Tiny Woodland Bot
9
-
10
- Requires the Twitter client gem and API access configured for a specific Twitter handle.
11
-
12
- ```
13
- gem install twitter
14
- ```
15
-
16
- Demonstrates how to use Calyx to make a minimal Twitter bot that periodically posts unique tweets. See [@tiny_woodland on Twitter](https://twitter.com/tiny_woodland) and the [writeup here](http://maetl.net/notes/storyboard/tiny-woodlands).
17
-
18
- ```
19
- TWITTER_CONSUMER_KEY=XXX-XXX
20
- TWITTER_CONSUMER_SECRET=XXX-XXX
21
- TWITTER_ACCESS_TOKEN=XXX-XXX
22
- TWITTER_CONSUMER_SECRET=XXX-XXX
23
- ruby examples/tiny_woodland_bot.rb
24
- ```
@@ -1,45 +0,0 @@
1
- ---
2
- layout: page
3
- title: Context
4
- permalink: /guides/context
5
- ---
6
-
7
- j,jnnnnnnjjj
8
-
9
- ## Constructing rules
10
-
11
- To achieve particular effects, structured repetition of grammar rules can be extremely useful, but these sets of rules can be boring and error-prone to write by hand.
12
-
13
- ```ruby
14
- row "{point}{point}{point}{point}{point}{point}{point}{point}{point}{point}{point}{point}"
15
- ```
16
-
17
- An easier
18
-
19
- ```ruby
20
- row (0..12).map { "{point}" }.join
21
- ```
22
-
23
- ## Injecting rules
24
-
25
- Sometimes it’s useful to calculate template expansions outside of Calyx and inject them where they’re needed, rather than rely on the hard-coded rules defined in grammar classes and object instances.
26
-
27
- The `#generate` method accepts an optional context map parameter which can be used to dynamically combine rules with an existing grammar during the generation process. This feature is generally used like a traditional template engine to substitute individual values that aren’t known ahead of time.
28
-
29
- The context map is a hash, with the keys being symbols defining the rules and the values being template expansion strings.
30
-
31
- The following example demonstrates how a field returned from a database query could be injected into a grammar to produce a randomized welcome message for users of an app.
32
-
33
- ```ruby
34
- greeting = Calyx::Grammar.new do
35
- start 'Hi {username}', 'Welcome back {username}', 'Hola {username}'
36
- end
37
-
38
- user = User.find(id: user_id)
39
-
40
- context = {
41
- username: user.name
42
- }
43
-
44
- greeting.generate(context)
45
- ```
@@ -1,175 +0,0 @@
1
- ---
2
- layout: page
3
- title: Template Expressions
4
- permalink: /guides/expressions
5
- ---
6
-
7
- # Template Expressions
8
-
9
- Dot-notation is supported in template expressions, allowing you to call any available method on the `String` object returned from a rule. Formatting methods can be chained arbitrarily and will execute in the same way as they would in native Ruby code.
10
-
11
- ```ruby
12
- greeting = Calyx::Grammar.new do
13
- start '{hello.capitalize} there.', 'Why, {hello} there.'
14
- hello 'hello', 'hi'
15
- end
16
-
17
- 4.times { greeting.generate }
18
- # => "Hello there."
19
- # => "Hi there."
20
- # => "Why, hello there."
21
- # => "Why, hi there."
22
- ```
23
-
24
- You can also extend the grammar with custom modifiers that provide useful formatting functions.
25
-
26
- ### Filters
27
-
28
- Filters accept an input string and return the transformed output:
29
-
30
- ```ruby
31
- greeting = Calyx::Grammar.new do
32
- filter :shoutycaps do |input|
33
- input.upcase
34
- end
35
-
36
- start '{hello.shoutycaps} there.', 'Why, {hello.shoutycaps} there.'
37
- hello 'hello', 'hi'
38
- end
39
-
40
- 4.times { greeting.generate }
41
- # => "HELLO there."
42
- # => "HI there."
43
- # => "Why, HELLO there."
44
- # => "Why, HI there."
45
- ```
46
-
47
- ### Mappings
48
-
49
- The mapping shortcut allows you to specify a map of regex patterns pointing to their resulting substitution strings:
50
-
51
- ```ruby
52
- green_bottle = Calyx::Grammar.new do
53
- mapping :pluralize, /(.+)/ => '\\1s'
54
- start 'One green {bottle}.', 'Two green {bottle.pluralize}.'
55
- bottle 'bottle'
56
- end
57
-
58
- 2.times { green_bottle.generate }
59
- # => "One green bottle."
60
- # => "Two green bottles."
61
- ```
62
-
63
- ### Modifier Mixins
64
-
65
- In order to use more intricate rewriting and formatting methods in a modifier chain, you can add methods to a module and embed it in a grammar using the `modifier` classmethod.
66
-
67
- Modifier methods accept a single argument representing the input string from the previous step in the expression chain and must return a string, representing the modified output.
68
-
69
- ```ruby
70
- module FullStop
71
- def full_stop(input)
72
- input << '.'
73
- end
74
- end
75
-
76
- hello = Calyx::Grammar.new do
77
- modifier FullStop
78
- start '{hello.capitalize.full_stop}'
79
- hello 'hello'
80
- end
81
-
82
- hello.generate
83
- # => "Hello."
84
- ```
85
-
86
- To share custom modifiers across multiple grammars, you can include the module in `Calyx::Modifiers`. This will make the methods available to all subsequent instances:
87
-
88
- ```ruby
89
- module FullStop
90
- def full_stop(input)
91
- input << '.'
92
- end
93
- end
94
-
95
- class Calyx::Modifiers
96
- include FullStop
97
- end
98
- ```
99
-
100
- ### Monkeypatching String
101
-
102
- Alternatively, you can combine methods from existing Gems that monkeypatch `String`:
103
-
104
- ```ruby
105
- require 'indefinite_article'
106
-
107
- module FullStop
108
- def full_stop
109
- self << '.'
110
- end
111
- end
112
-
113
- class String
114
- include FullStop
115
- end
116
-
117
- noun_articles = Calyx::Grammar.new do
118
- start '{fruit.with_indefinite_article.capitalize.full_stop}'
119
- fruit 'apple', 'orange', 'banana', 'pear'
120
- end
121
-
122
- 4.times { noun_articles.generate }
123
- # => "An apple."
124
- # => "An orange."
125
- # => "A banana."
126
- # => "A pear."
127
- ```
128
-
129
- ### Memoized Rules
130
-
131
- Rule expansions can be ‘memoized’ so that multiple references to the same rule return the same value. This is useful for picking a noun from a list and reusing it in multiple places within a text.
132
-
133
- The `@` sigil is used to mark memoized rules. This evaluates the rule and stores it in memory the first time it’s referenced. All subsequent references to the memoized rule use the same stored value.
134
-
135
- ```ruby
136
- # Without memoization
137
- grammar = Calyx::Grammar.new do
138
- start '{name} <{name.downcase}>'
139
- name 'Daenerys', 'Tyrion', 'Jon'
140
- end
141
-
142
- 3.times { grammar.generate }
143
- # => Daenerys <jon>
144
- # => Tyrion <daenerys>
145
- # => Jon <tyrion>
146
-
147
- # With memoization
148
- grammar = Calyx::Grammar.new do
149
- start '{@name} <{@name.downcase}>'
150
- name 'Daenerys', 'Tyrion', 'Jon'
151
- end
152
-
153
- 3.times { grammar.generate }
154
- # => Tyrion <tyrion>
155
- # => Daenerys <daenerys>
156
- # => Jon <jon>
157
- ```
158
-
159
- Note that the memoization symbol can only be used on the right hand side of a production rule.
160
-
161
- ### Unique Rules
162
-
163
- Rule expansions can be marked as ‘unique’, meaning that multiple references to the same rule always return a different value. This is useful for situations where the same result appearing twice would appear awkward and messy.
164
-
165
- Unique rules are marked by the `$` sigil.
166
-
167
- ```ruby
168
- grammar = Calyx::Grammar.new do
169
- start "{$medal}, {$medal}, {$medal}"
170
- medal 'Gold', 'Silver', 'Bronze'
171
- end
172
-
173
- grammar.generate
174
- # => Silver, Bronze, Gold
175
- ```
@@ -1,50 +0,0 @@
1
- ---
2
- layout: docs
3
- title: Features documented in README
4
- ---
5
-
6
- ## Template Expressions
7
-
8
- Basic rule substitution uses single curly brackets as delimiters for template expressions:
9
-
10
- ```ruby
11
- fruit = Calyx::Grammar.new do
12
- start '{colour} {fruit}'
13
- colour 'red', 'green', 'yellow'
14
- fruit 'apple', 'pear', 'tomato'
15
- end
16
-
17
- 6.times { fruit.generate }
18
- # => "yellow pear"
19
- # => "red apple"
20
- # => "green tomato"
21
- # => "red pear"
22
- # => "yellow tomato"
23
- # => "green apple"
24
- ```
25
-
26
- ## The start symbol
27
-
28
- By convention, the `start` rule specifies the default starting point for generating the final text. You can start from any other named rule by passing it explicitly to the generate method.
29
-
30
- ```ruby
31
- class HelloWorld < Calyx::Grammar
32
- hello 'Hello world!'
33
- end
34
-
35
- hello = HelloWorld.new
36
- hello.generate(:hello)
37
- ```
38
-
39
- ## Block Constructors
40
-
41
- As an alternative to subclassing, you can also construct rules unique to an instance by passing a block when initializing the class:
42
-
43
- ```ruby
44
- hello = Calyx::Grammar.new do
45
- start '{greeting} world.'
46
- greeting 'Hello', 'Hi', 'Hey', 'Yo'
47
- end
48
-
49
- hello.generate
50
- ```
@@ -1,37 +0,0 @@
1
- ---
2
- layout: default
3
- title: File Formats
4
- permalink: /guides/formats
5
- ---
6
-
7
- # File Formats
8
-
9
- In addition to defining grammars in pure Ruby, you can load them from external JSON and YAML files:
10
-
11
- ```ruby
12
- hello = Calyx::Grammar.load('hello.yml')
13
- hello.generate
14
- ```
15
-
16
- The format requires a flat map with keys representing the left-hand side named symbols and the values representing the right hand side substitution rules.
17
-
18
- In JSON:
19
-
20
- ```json
21
- {
22
- "start": "{greeting} world.",
23
- "greeting": ["Hello", "Hi", "Hey", "Yo"]
24
- }
25
- ```
26
-
27
- In YAML:
28
-
29
- ```yaml
30
- ---
31
- start: "{greeting} world."
32
- greeting:
33
- - Hello
34
- - Hi
35
- - Hey
36
- - Yo
37
- ```