psychgus 1.3.6 → 1.3.7
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 +4 -4
- data/.yardopts +0 -1
- data/CHANGELOG.md +4 -3
- data/Gemfile +1 -0
- data/README.md +154 -163
- data/Rakefile +21 -4
- data/lib/psychgus/blueberry.rb +1 -1
- data/lib/psychgus/ext/core_ext.rb +5 -4
- data/lib/psychgus/stylers.rb +19 -15
- data/lib/psychgus/version.rb +1 -1
- data/lib/psychgus.rb +38 -300
- data/psychgus.gemspec +3 -3
- data/test/psychgus_test.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffadac29265886dcd2b06d12d45405cb7a204ca891dff23c2d67a5f8cdf2f454
|
4
|
+
data.tar.gz: e3648eebf1425c030b6dadfa580a4a41d1ef562b16e652204eb1ec4577e74f5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6b41b74666b0de6f2cde69261f7958b113b4e030d35fe01cae9c11e3dc1a9a5738c777328bdc48497e831d8d8d0008c0e15562ed772487b09fd5cc0a3635283
|
7
|
+
data.tar.gz: eaa81c7b6b374aa09c9a959af0d788bdaa86567783eb78fc64e1a49b9d9d5a947a14feaf08912351b6030c5b16efc8de1e91627a000d8936be4165e5db887858
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
- [Keep a Changelog v1.0.0](https://keepachangelog.com/en/1.0.0)
|
4
4
|
- [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html)
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
## [v1.3.7] - 2025-05-01
|
8
|
+
### Fixed
|
9
|
+
- Fixed up code examples in README and doc.
|
8
10
|
|
9
11
|
|
10
12
|
## [v1.3.6] - 2025-05-01
|
@@ -15,7 +17,6 @@
|
|
15
17
|
- Renamed `master` branch to `main`.
|
16
18
|
- Applied RuboCop suggestions.
|
17
19
|
- Refactored tests.
|
18
|
-
- Removed `yard_ghurt` gem.
|
19
20
|
|
20
21
|
|
21
22
|
## [v1.3.5] - 2024-09-06
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,10 +17,7 @@ Turn this YAML...
|
|
17
17
|
---
|
18
18
|
Psych Gus:
|
19
19
|
Aliases:
|
20
|
-
- Longbranch Pennywhistle
|
21
20
|
- Squirts Macintosh
|
22
|
-
- Clementine Woolysocks
|
23
|
-
- Lavender Gooms
|
24
21
|
- Big Baby Burton
|
25
22
|
- Chocolate Einstein
|
26
23
|
- MC Clap Yo Handz
|
@@ -35,8 +32,7 @@ Into this:
|
|
35
32
|
```YAML
|
36
33
|
---
|
37
34
|
Psych Gus:
|
38
|
-
Aliases: [
|
39
|
-
Gooms, Big Baby Burton, Chocolate Einstein, MC Clap Yo Handz]
|
35
|
+
Aliases: [Squirts Macintosh, Big Baby Burton, Chocolate Einstein, MC Clap Yo Handz]
|
40
36
|
Skills: [The Blueberry, The Super Sniffer, Positive Work Attitude]
|
41
37
|
```
|
42
38
|
|
@@ -48,15 +44,12 @@ The Psychgus name comes from the well-styled character Gus from the TV show Psyc
|
|
48
44
|
|
49
45
|
- [Setup](#setup)
|
50
46
|
- [Using](#using)
|
47
|
+
- [Common Stylers](#common-stylers)
|
51
48
|
- [Simple Example](#simple-example)
|
52
49
|
- [Hash Example](#hash-example)
|
53
50
|
- [Class Example](#class-example)
|
54
51
|
- [Advanced Usage](#advanced-usage)
|
55
|
-
- [Common Stylers](#common-stylers)
|
56
|
-
- [Stylers Example](#stylers-example)
|
57
52
|
- [Hacking](#hacking)
|
58
|
-
- [Testing](#testing)
|
59
|
-
- [Generating Doc](#generating-doc)
|
60
53
|
- [License](#license)
|
61
54
|
|
62
55
|
## Setup
|
@@ -67,27 +60,24 @@ With the RubyGems CLI package manager:
|
|
67
60
|
|
68
61
|
`$ gem install psychgus`
|
69
62
|
|
70
|
-
In your *
|
63
|
+
In your *.gemspec* file:
|
71
64
|
|
72
65
|
```Ruby
|
73
|
-
# Pick one...
|
74
66
|
spec.add_dependency 'psychgus', '~> X.X.X'
|
75
|
-
spec.add_development_dependency 'psychgus', '~> X.X.X'
|
76
67
|
```
|
77
68
|
|
78
69
|
In your *Gemfile*:
|
79
70
|
|
80
71
|
```Ruby
|
81
72
|
# Pick one...
|
82
|
-
gem 'psychgus', '~> X.X.X'
|
83
|
-
gem 'psychgus', '
|
84
|
-
gem 'psychgus', :git => 'https://github.com/esotericpig/psychgus.git', :tag => 'vX.X.X'
|
73
|
+
gem 'psychgus', '~> X.X.X', group: :development
|
74
|
+
gem 'psychgus', git: 'https://github.com/esotericpig/psychgus.git', tag: 'vX.X.X'
|
85
75
|
```
|
86
76
|
|
87
77
|
Manually:
|
88
78
|
|
89
79
|
```
|
90
|
-
$ git clone 'https://github.com/esotericpig/psychgus.git'
|
80
|
+
$ git clone --depth 1 'https://github.com/esotericpig/psychgus.git'
|
91
81
|
$ cd psychgus
|
92
82
|
$ bundle install
|
93
83
|
$ bundle exec rake install:local
|
@@ -103,13 +93,70 @@ For classes, you can optionally include `Psychgus::Blueberry` and return the sty
|
|
103
93
|
|
104
94
|
Instead of making your own styler, you can also use one of the [pre-defined stylers](#common-stylers).
|
105
95
|
|
106
|
-
|
107
|
-
|
108
|
-
[Simple Example](#simple-example)
|
96
|
+
[Common Stylers](#common-stylers)
|
97
|
+
| [Simple Example](#simple-example)
|
109
98
|
| [Hash Example](#hash-example)
|
110
99
|
| [Class Example](#class-example)
|
111
100
|
| [Advanced Usage](#advanced-usage)
|
112
|
-
|
101
|
+
|
102
|
+
### Common Stylers
|
103
|
+
|
104
|
+
A collection of commonly-used [Stylers](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers.html) and [Stylables](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylables.html) are included with Psychgus. They're the easiest & quickest way to get started.
|
105
|
+
|
106
|
+
| Styler | Description |
|
107
|
+
| --- | --- |
|
108
|
+
| [CapStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/CapStyler.html) | Capitalizer for Scalars |
|
109
|
+
| [FlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/FlowStyler.html) | FLOW style changer for Mappings & Sequences |
|
110
|
+
| [MapFlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/MapFlowStyler.html) | FLOW style changer for Mappings only |
|
111
|
+
| [NoSymStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/NoSymStyler.html) | Symbol remover for Scalars |
|
112
|
+
| [NoTagStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/NoTagStyler.html) | Tag remover for classes |
|
113
|
+
| [SeqFlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/SeqFlowStyler.html) | FLOW style changer for Sequences only |
|
114
|
+
|
115
|
+
Example usage:
|
116
|
+
|
117
|
+
```Ruby
|
118
|
+
require 'psychgus'
|
119
|
+
|
120
|
+
class EggCarton
|
121
|
+
def initialize
|
122
|
+
@eggs = {
|
123
|
+
styles: ['fried', 'scrambled', ['BBQ', 'ketchup & mustard']],
|
124
|
+
colors: ['brown', 'white', ['blue', 'green']],
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
puts EggCarton.new.to_yaml(
|
130
|
+
stylers: [
|
131
|
+
Psychgus::NoSymStyler.new,
|
132
|
+
Psychgus::NoTagStyler.new,
|
133
|
+
Psychgus::CapStyler.new,
|
134
|
+
Psychgus::FlowStyler.new(4),
|
135
|
+
]
|
136
|
+
)
|
137
|
+
|
138
|
+
# Output:
|
139
|
+
# ---
|
140
|
+
# Eggs:
|
141
|
+
# Styles: [Fried, Scrambled, [BBQ, Ketchup & Mustard]]
|
142
|
+
# Colors: [Brown, White, [Blue, Green]]
|
143
|
+
|
144
|
+
puts EggCarton.new.to_yaml
|
145
|
+
|
146
|
+
# Output (without Stylers):
|
147
|
+
# --- !ruby/object:EggCarton
|
148
|
+
# eggs:
|
149
|
+
# :styles:
|
150
|
+
# - fried
|
151
|
+
# - scrambled
|
152
|
+
# - - BBQ
|
153
|
+
# - ketchup & mustard
|
154
|
+
# :colors:
|
155
|
+
# - brown
|
156
|
+
# - white
|
157
|
+
# - - blue
|
158
|
+
# - green
|
159
|
+
```
|
113
160
|
|
114
161
|
### Simple Example
|
115
162
|
|
@@ -125,8 +172,8 @@ class CoffeeStyler
|
|
125
172
|
end
|
126
173
|
|
127
174
|
coffee = {
|
128
|
-
'Roast'=>['Light', 'Medium', 'Dark', 'Extra Dark'],
|
129
|
-
'Style'=>['Cappuccino', 'Espresso', 'Latte', 'Mocha']
|
175
|
+
'Roast' => ['Light', 'Medium', 'Dark', 'Extra Dark'],
|
176
|
+
'Style' => ['Cappuccino', 'Espresso', 'Latte', 'Mocha'],
|
130
177
|
}
|
131
178
|
|
132
179
|
puts coffee.to_yaml(stylers: CoffeeStyler.new)
|
@@ -165,59 +212,54 @@ require 'psychgus'
|
|
165
212
|
class BurgerStyler
|
166
213
|
include Psychgus::Styler # Mix in methods needed for styling
|
167
214
|
|
168
|
-
# Style maps (Psych::Nodes::Mapping)
|
169
|
-
# - Hashes (key/value pairs)
|
170
|
-
# - Example: "Burgers: Classic {}"
|
215
|
+
# Style hash maps (Psych::Nodes::Mapping).
|
171
216
|
def style_mapping(sniffer,node)
|
172
217
|
node.style = Psychgus::MAPPING_FLOW if sniffer.level >= 4
|
173
218
|
end
|
174
219
|
|
175
|
-
# Style
|
176
|
-
# - Any text (non-alias)
|
220
|
+
# Style non-alias text (Psych::Nodes::Scalar).
|
177
221
|
def style_scalar(sniffer,node)
|
178
|
-
# Remove colon (change symbols into strings)
|
222
|
+
# Remove colon (change symbols into strings).
|
179
223
|
node.value = node.value.sub(':','')
|
180
224
|
|
181
225
|
# Capitalize each word
|
182
226
|
node.value = node.value.split(' ').map do |v|
|
183
227
|
if v.casecmp('BBQ') == 0
|
184
|
-
v.upcase
|
228
|
+
v.upcase
|
185
229
|
else
|
186
|
-
v.capitalize
|
230
|
+
v.capitalize
|
187
231
|
end
|
188
232
|
end.join(' ')
|
189
233
|
|
190
|
-
# Change lettuce to spinach
|
234
|
+
# Change lettuce to spinach.
|
191
235
|
node.value = 'Spinach' if node.value == 'Lettuce'
|
192
236
|
end
|
193
237
|
|
194
|
-
# Style
|
195
|
-
# - Arrays
|
196
|
-
# - Example: "[Lettuce, Onions, Pickles, Tomatoes]"
|
238
|
+
# Style arrays (Psych::Nodes::Sequence).
|
197
239
|
def style_sequence(sniffer,node)
|
198
240
|
node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 4
|
199
241
|
end
|
200
242
|
end
|
201
243
|
|
202
244
|
burgers = {
|
203
|
-
:
|
204
|
-
:
|
205
|
-
|
206
|
-
|
207
|
-
:
|
208
|
-
|
209
|
-
|
210
|
-
:
|
211
|
-
|
212
|
-
|
245
|
+
burgers: {
|
246
|
+
classic: {sauce: %w[Ketchup Mustard],
|
247
|
+
cheese: 'American',
|
248
|
+
bun: 'Sesame Seed'},
|
249
|
+
bbq: {sauce: 'Honey BBQ',
|
250
|
+
cheese: 'Cheddar',
|
251
|
+
bun: 'Kaiser'},
|
252
|
+
fancy: {sauce: 'Spicy Wasabi',
|
253
|
+
cheese: 'Smoked Gouda',
|
254
|
+
bun: 'Hawaiian'},
|
213
255
|
},
|
214
|
-
:
|
256
|
+
toppings: [
|
215
257
|
'Mushrooms',
|
216
|
-
%w
|
217
|
-
[%w
|
258
|
+
%w[Lettuce Onions Pickles Tomatoes],
|
259
|
+
[%w[Ketchup Mustard], %w[Salt Pepper]],
|
218
260
|
]
|
219
261
|
}
|
220
|
-
burgers[:favorite] = burgers[:burgers][:bbq] # Alias
|
262
|
+
burgers[:favorite] = burgers[:burgers][:bbq] # Alias.
|
221
263
|
|
222
264
|
puts burgers.to_yaml(indent: 3,stylers: BurgerStyler.new)
|
223
265
|
|
@@ -234,7 +276,7 @@ puts burgers.to_yaml(indent: 3,stylers: BurgerStyler.new)
|
|
234
276
|
# Favorite: *1
|
235
277
|
|
236
278
|
# Or pass in a Hash. Can also dereference aliases.
|
237
|
-
puts burgers.to_yaml({:
|
279
|
+
puts burgers.to_yaml({indent: 3,stylers: BurgerStyler.new,deref_aliases: true})
|
238
280
|
|
239
281
|
# Output:
|
240
282
|
# ---
|
@@ -258,58 +300,53 @@ puts burgers.to_yaml({:indent => 3,:stylers => BurgerStyler.new,:deref_aliases =
|
|
258
300
|
require 'psychgus'
|
259
301
|
|
260
302
|
class BurgerStyler
|
261
|
-
include Psychgus::Styler # Mix in methods needed for styling
|
303
|
+
include Psychgus::Styler # Mix in methods needed for styling.
|
262
304
|
|
263
305
|
def initialize(sniffer)
|
264
306
|
@class_level = sniffer.level
|
265
307
|
@class_position = sniffer.position
|
266
308
|
end
|
267
309
|
|
268
|
-
# Style all nodes (Psych::Nodes::Node)
|
310
|
+
# Style all nodes (Psych::Nodes::Node).
|
269
311
|
def style(sniffer,node)
|
270
|
-
# Remove
|
312
|
+
# Remove `!ruby/object:...` for Burger classes (not Burgers class).
|
271
313
|
node.tag = nil if node.node_of?(:mapping,:scalar,:sequence)
|
272
314
|
|
273
|
-
# This is another way to do the above
|
315
|
+
# This is another way to do the above.
|
274
316
|
#node.tag = nil if node.respond_to?(:tag=)
|
275
317
|
end
|
276
318
|
|
277
|
-
# Style maps (Psych::Nodes::Mapping)
|
278
|
-
# - Hashes (key/value pairs)
|
279
|
-
# - Example: "Burgers: Classic {}"
|
319
|
+
# Style hash maps (Psych::Nodes::Mapping).
|
280
320
|
def style_mapping(sniffer,node)
|
281
321
|
parent = sniffer.parent
|
282
322
|
|
283
|
-
if !parent.nil?
|
323
|
+
if !parent.nil?
|
284
324
|
# BBQ
|
285
325
|
node.style = Psychgus::MAPPING_FLOW if parent.node_of?(:scalar) &&
|
286
326
|
parent.value.casecmp('BBQ') == 0
|
287
327
|
end
|
288
328
|
end
|
289
329
|
|
290
|
-
# Style
|
291
|
-
# - Any text (non-alias)
|
330
|
+
# Style non-alias text (Psych::Nodes::Scalar).
|
292
331
|
def style_scalar(sniffer,node)
|
293
332
|
parent = sniffer.parent
|
294
333
|
|
295
|
-
# Single quote scalars that are not keys to a map
|
296
|
-
# -
|
297
|
-
node.style = Psychgus::SCALAR_SINGLE_QUOTED unless parent.child_key?
|
334
|
+
# Single quote scalars that are not keys to a map.
|
335
|
+
# - `child_key?` is the same as `child_type == :key`
|
336
|
+
node.style = Psychgus::SCALAR_SINGLE_QUOTED unless parent.child_key?
|
298
337
|
end
|
299
338
|
|
300
|
-
# Style
|
301
|
-
# - Arrays
|
302
|
-
# - Example: "[Lettuce, Onions, Pickles, Tomatoes]"
|
339
|
+
# Style arrays (Psych::Nodes::Sequence).
|
303
340
|
def style_sequence(sniffer,node)
|
304
341
|
relative_level = (sniffer.level - @class_level) + 1
|
305
342
|
|
306
|
-
#
|
343
|
+
# `[Ketchup, Mustard]`
|
307
344
|
node.style = Psychgus::SEQUENCE_FLOW if relative_level == 3
|
308
345
|
end
|
309
346
|
end
|
310
347
|
|
311
348
|
class Burger
|
312
|
-
include Psychgus::Blueberry # Mix in methods needed to be stylable
|
349
|
+
include Psychgus::Blueberry # Mix in methods needed to be stylable.
|
313
350
|
|
314
351
|
attr_accessor :bun
|
315
352
|
attr_accessor :cheese
|
@@ -321,13 +358,13 @@ class Burger
|
|
321
358
|
@sauce = sauce
|
322
359
|
end
|
323
360
|
|
324
|
-
# Return our styler(s)
|
361
|
+
# Return our styler(s).
|
325
362
|
# - Can be an Array: [MyStyler1.new, MyStyler2.new]
|
326
363
|
def psychgus_stylers(sniffer)
|
327
364
|
return BurgerStyler.new(sniffer)
|
328
365
|
end
|
329
366
|
|
330
|
-
# You can still use Psych's encode_with(), no problem
|
367
|
+
# You can still use Psych's encode_with(), no problem.
|
331
368
|
def encode_with(coder)
|
332
369
|
coder['Bun'] = @bun
|
333
370
|
coder['Cheese'] = @cheese
|
@@ -340,23 +377,23 @@ class Burgers
|
|
340
377
|
attr_accessor :toppings
|
341
378
|
attr_accessor :favorite
|
342
379
|
|
343
|
-
def initialize
|
380
|
+
def initialize
|
344
381
|
@burgers = {
|
345
382
|
'Classic' => Burger.new(['Ketchup','Mustard'],'American' ,'Sesame Seed'),
|
346
383
|
'BBQ' => Burger.new('Honey BBQ' ,'Cheddar' ,'Kaiser'),
|
347
|
-
'Fancy' => Burger.new('Spicy Wasabi' ,'Smoked Gouda','Hawaiian')
|
384
|
+
'Fancy' => Burger.new('Spicy Wasabi' ,'Smoked Gouda','Hawaiian'),
|
348
385
|
}
|
349
386
|
|
350
387
|
@toppings = [
|
351
388
|
'Mushrooms',
|
352
|
-
%w
|
353
|
-
[%w
|
389
|
+
%w[Lettuce Onions Pickles Tomatoes],
|
390
|
+
[%w[Ketchup Mustard],%w[Salt Pepper]],
|
354
391
|
]
|
355
392
|
|
356
393
|
@favorite = @burgers['BBQ'] # Alias
|
357
394
|
end
|
358
395
|
|
359
|
-
# You can still use Psych's encode_with(), no problem
|
396
|
+
# You can still use Psych's encode_with(), no problem.
|
360
397
|
def encode_with(coder)
|
361
398
|
coder['Burgers'] = @burgers
|
362
399
|
coder['Toppings'] = @toppings
|
@@ -393,7 +430,7 @@ puts burgers.to_yaml(indent: 3)
|
|
393
430
|
# Favorite: *1
|
394
431
|
|
395
432
|
# Or pass in a Hash. Can also dereference aliases.
|
396
|
-
puts burgers.to_yaml({:
|
433
|
+
puts burgers.to_yaml({indent: 3,deref_aliases: true})
|
397
434
|
|
398
435
|
# Output:
|
399
436
|
# --- !ruby/object:Burgers
|
@@ -438,65 +475,80 @@ end
|
|
438
475
|
|
439
476
|
coffee = {
|
440
477
|
'Coffee' => {
|
441
|
-
'Roast'=>['Light', 'Medium', 'Dark', 'Extra Dark'],
|
442
|
-
'Style'=>['Cappuccino', 'Espresso', 'Latte', 'Mocha']
|
478
|
+
'Roast' => ['Light', 'Medium', 'Dark', 'Extra Dark'],
|
479
|
+
'Style' => ['Cappuccino', 'Espresso', 'Latte', 'Mocha'],
|
443
480
|
}
|
444
481
|
}
|
445
482
|
eggs = {
|
446
483
|
'Eggs' => {
|
447
|
-
'Color'=>['Brown', 'White', 'Blue', 'Olive'],
|
448
|
-
'Style'=>['Fried', 'Scrambled', 'Omelette', 'Poached']
|
484
|
+
'Color' => ['Brown', 'White', 'Blue', 'Olive'],
|
485
|
+
'Style' => ['Fried', 'Scrambled', 'Omelette', 'Poached'],
|
449
486
|
}
|
450
487
|
}
|
451
488
|
|
452
489
|
filename = 'coffee-and-eggs.yaml'
|
453
490
|
styler = MyStyler.new
|
454
|
-
options = {:
|
491
|
+
options = {indentation: 3, stylers: styler, deref_aliases: true}
|
455
492
|
|
456
|
-
coffee_yaml = coffee.to_yaml(options)
|
457
|
-
coffee_and_eggs_yaml = Psychgus.dump_stream(coffee,eggs
|
493
|
+
coffee_yaml = coffee.to_yaml(**options)
|
494
|
+
coffee_and_eggs_yaml = Psychgus.dump_stream(coffee,eggs,**options)
|
458
495
|
|
496
|
+
# High-level emitting.
|
497
|
+
puts '+=====================+'
|
498
|
+
puts '| High-level emitting |'
|
499
|
+
puts '+=====================+'
|
459
500
|
|
460
|
-
|
461
|
-
puts Psychgus.dump(coffee,options)
|
501
|
+
puts Psychgus.dump(coffee,**options)
|
462
502
|
puts
|
463
503
|
|
464
|
-
Psychgus.dump_file(filename,coffee,eggs
|
504
|
+
Psychgus.dump_file(filename,coffee,eggs,**options)
|
465
505
|
puts File.readlines(filename)
|
466
506
|
puts
|
467
507
|
|
468
|
-
puts Psychgus.dump_stream(coffee,eggs
|
508
|
+
puts Psychgus.dump_stream(coffee,eggs,**options)
|
469
509
|
puts
|
470
510
|
|
471
|
-
puts coffee.to_yaml(options)
|
511
|
+
puts coffee.to_yaml(**options)
|
472
512
|
puts
|
473
513
|
|
474
514
|
# High-level parsing
|
475
515
|
# - Because to_ruby() will be called, just use Psych:
|
476
516
|
# - load(), load_file(), load_stream(), safe_load()
|
477
517
|
|
478
|
-
# Mid-level emitting
|
479
|
-
|
518
|
+
# Mid-level emitting.
|
519
|
+
puts '+====================+'
|
520
|
+
puts '| Mid-level emitting |'
|
521
|
+
puts '+====================+'
|
480
522
|
|
481
|
-
|
523
|
+
stream = Psychgus.parse_stream(coffee_and_eggs_yaml,**options)
|
524
|
+
|
525
|
+
puts stream.to_yaml
|
482
526
|
puts
|
483
527
|
|
484
|
-
# Mid-level parsing
|
485
|
-
puts
|
528
|
+
# Mid-level parsing.
|
529
|
+
puts '+===================+'
|
530
|
+
puts '| Mid-level parsing |'
|
531
|
+
puts '+===================+'
|
532
|
+
|
533
|
+
puts Psychgus.parse(coffee_yaml,**options).to_ruby
|
486
534
|
puts
|
487
535
|
|
488
|
-
puts Psychgus.parse_file(filename
|
536
|
+
puts Psychgus.parse_file(filename,**options).to_ruby
|
489
537
|
puts
|
490
538
|
|
491
539
|
i = 0
|
492
|
-
Psychgus.parse_stream(coffee_and_eggs_yaml
|
540
|
+
Psychgus.parse_stream(coffee_and_eggs_yaml,**options) do |doc|
|
493
541
|
puts "Doc ##{i += 1}:"
|
494
542
|
puts " #{doc.to_ruby}"
|
495
543
|
end
|
496
544
|
puts
|
497
545
|
|
498
|
-
# Low-level emitting
|
499
|
-
|
546
|
+
# Low-level emitting.
|
547
|
+
puts '+====================+'
|
548
|
+
puts '| Low-level emitting |'
|
549
|
+
puts '+====================+'
|
550
|
+
|
551
|
+
tree_builder = Psychgus::StyledTreeBuilder.new(styler,**options)
|
500
552
|
visitor = Psych::Visitors::YAMLTree.create(options,tree_builder)
|
501
553
|
|
502
554
|
visitor << coffee
|
@@ -505,8 +557,12 @@ visitor << eggs
|
|
505
557
|
puts visitor.tree.to_yaml
|
506
558
|
puts
|
507
559
|
|
508
|
-
# Low-level parsing
|
509
|
-
|
560
|
+
# Low-level parsing.
|
561
|
+
puts '+===================+'
|
562
|
+
puts '| Low-level parsing |'
|
563
|
+
puts '+===================+'
|
564
|
+
|
565
|
+
parser = Psychgus.parser(**options)
|
510
566
|
|
511
567
|
parser.parse(coffee_yaml)
|
512
568
|
|
@@ -514,63 +570,6 @@ puts parser.handler.root.to_ruby
|
|
514
570
|
puts
|
515
571
|
```
|
516
572
|
|
517
|
-
### Common Stylers
|
518
|
-
|
519
|
-
A collection of commonly-used [Stylers](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers.html) and [Stylables](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylables.html) are included with Psychgus.
|
520
|
-
|
521
|
-
| Styler | Description |
|
522
|
-
| --- | --- |
|
523
|
-
| [CapStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/CapStyler.html) | Capitalizer for Scalars |
|
524
|
-
| [FlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/FlowStyler.html) | FLOW style changer for Mappings & Sequences |
|
525
|
-
| [MapFlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/MapFlowStyler.html) | FLOW style changer for Mappings only |
|
526
|
-
| [NoSymStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/NoSymStyler.html) | Symbol remover for Scalars |
|
527
|
-
| [NoTagStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/NoTagStyler.html) | Tag remover for classes |
|
528
|
-
| [SeqFlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/SeqFlowStyler.html) | FLOW style changer for Sequences only |
|
529
|
-
|
530
|
-
#### Stylers Example
|
531
|
-
|
532
|
-
```Ruby
|
533
|
-
require 'psychgus'
|
534
|
-
|
535
|
-
class EggCarton
|
536
|
-
def initialize
|
537
|
-
@eggs = {
|
538
|
-
:styles => ['fried', 'scrambled', ['BBQ', 'ketchup & mustard']],
|
539
|
-
:colors => ['brown', 'white', ['blue', 'green']]
|
540
|
-
}
|
541
|
-
end
|
542
|
-
end
|
543
|
-
|
544
|
-
puts EggCarton.new.to_yaml(stylers: [
|
545
|
-
Psychgus::NoSymStyler.new,
|
546
|
-
Psychgus::NoTagStyler.new,
|
547
|
-
Psychgus::CapStyler.new,
|
548
|
-
Psychgus::FlowStyler.new(4)
|
549
|
-
])
|
550
|
-
|
551
|
-
# Output:
|
552
|
-
# ---
|
553
|
-
# Eggs:
|
554
|
-
# Styles: [Fried, Scrambled, [BBQ, Ketchup & Mustard]]
|
555
|
-
# Colors: [Brown, White, [Blue, Green]]
|
556
|
-
|
557
|
-
puts EggCarton.new.to_yaml
|
558
|
-
|
559
|
-
# Output (without Stylers):
|
560
|
-
# --- !ruby/object:EggCarton
|
561
|
-
# eggs:
|
562
|
-
# :styles:
|
563
|
-
# - fried
|
564
|
-
# - scrambled
|
565
|
-
# - - BBQ
|
566
|
-
# - ketchup & mustard
|
567
|
-
# :colors:
|
568
|
-
# - brown
|
569
|
-
# - white
|
570
|
-
# - - blue
|
571
|
-
# - green
|
572
|
-
```
|
573
|
-
|
574
573
|
## Hacking
|
575
574
|
|
576
575
|
```
|
@@ -580,20 +579,12 @@ $ bundle install
|
|
580
579
|
$ bundle exec rake -T
|
581
580
|
```
|
582
581
|
|
583
|
-
### Testing
|
584
|
-
|
585
582
|
Run tests:
|
586
583
|
|
587
584
|
`$ bundle exec rake test`
|
588
585
|
|
589
|
-
### Generating Doc
|
590
|
-
|
591
586
|
Generate doc:
|
592
587
|
|
593
|
-
`$ bundle exec rake doc`
|
594
|
-
|
595
|
-
Clean & generate pristine doc:
|
596
|
-
|
597
588
|
`$ bundle exec rake clobber doc`
|
598
589
|
|
599
590
|
## License
|
data/Rakefile
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require 'bundler/gem_tasks'
|
5
5
|
|
6
6
|
require 'yard'
|
7
|
+
require 'yard_ghurt'
|
7
8
|
|
8
9
|
require 'psychgus/version'
|
9
10
|
require 'rake/clean'
|
@@ -12,22 +13,38 @@ require 'rake/testtask'
|
|
12
13
|
task default: %i[test]
|
13
14
|
|
14
15
|
CLEAN.exclude('.git/','stock/')
|
15
|
-
CLOBBER.include('doc/')
|
16
|
+
CLOBBER.include('.yardoc/','doc/')
|
16
17
|
|
17
18
|
# Execute "rake clobber doc" for pristine docs.
|
18
19
|
desc 'Generate documentation (YARDoc)'
|
19
|
-
task doc: %i[yard]
|
20
|
+
task doc: %i[yard yard_gfm_fix]
|
20
21
|
|
21
22
|
# To test using different Gem versions:
|
22
23
|
# GST=1 bundle update && bundle exec rake test
|
23
24
|
Rake::TestTask.new do |task|
|
24
25
|
task.libs = ['lib','test']
|
25
|
-
task.pattern =
|
26
|
+
task.pattern = 'test/**/*_test.rb'
|
26
27
|
# task.options = '--verbose' # Execute "rake test TESTOPT=-v" instead.
|
27
28
|
task.verbose = true
|
28
29
|
task.warning = true
|
29
30
|
end
|
30
31
|
|
31
32
|
YARD::Rake::YardocTask.new do |task|
|
32
|
-
task.files = [
|
33
|
+
task.files = ['lib/**/*.rb']
|
34
|
+
task.options += ['--title',"Psychgus v#{Psychgus::VERSION}"]
|
35
|
+
end
|
36
|
+
|
37
|
+
YardGhurt::GFMFixTask.new do |task|
|
38
|
+
task.arg_names = [:dev]
|
39
|
+
task.dry_run = false
|
40
|
+
task.fix_code_langs = true
|
41
|
+
task.md_files = ['index.html']
|
42
|
+
|
43
|
+
task.before = proc do |t2,_args|
|
44
|
+
# Delete this file as it's never used (index.html is an exact copy).
|
45
|
+
YardGhurt.rm_exist(File.join(t2.doc_dir,'file.README.html'))
|
46
|
+
|
47
|
+
t2.css_styles << '<link rel="stylesheet" type="text/css" href="/css/prism.css" />'
|
48
|
+
t2.js_scripts << '<script src="/js/prism.js"></script>'
|
49
|
+
end
|
33
50
|
end
|
data/lib/psychgus/blueberry.rb
CHANGED
@@ -30,10 +30,11 @@ module Psychgus
|
|
30
30
|
# end
|
31
31
|
#
|
32
32
|
# my_obj = {
|
33
|
-
# :
|
34
|
-
# :
|
35
|
-
# :
|
36
|
-
#
|
33
|
+
# Foods: {
|
34
|
+
# Fruits: %w[Apple Banana Blueberry Pear],
|
35
|
+
# Veggies: %w[Bean Carrot Celery Pea],
|
36
|
+
# }
|
37
|
+
# }
|
37
38
|
#
|
38
39
|
# puts my_obj.to_yaml(indentation: 5,stylers: MyStyler.new)
|
39
40
|
#
|
data/lib/psychgus/stylers.rb
CHANGED
@@ -20,21 +20,23 @@ module Psychgus
|
|
20
20
|
# class EggCarton
|
21
21
|
# def initialize
|
22
22
|
# @eggs = {
|
23
|
-
# :
|
24
|
-
# :
|
23
|
+
# styles: ['fried', 'scrambled', ['BBQ', 'ketchup & mustard']],
|
24
|
+
# colors: ['brown', 'white', ['blue', 'green']],
|
25
25
|
# }
|
26
26
|
# end
|
27
27
|
# end
|
28
28
|
#
|
29
29
|
# hierarchy = Psychgus::HierarchyStyler.new(io: $stdout)
|
30
30
|
#
|
31
|
-
# puts EggCarton.new.to_yaml(
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
31
|
+
# puts EggCarton.new.to_yaml(
|
32
|
+
# stylers: [
|
33
|
+
# Psychgus::NoSymStyler.new,
|
34
|
+
# Psychgus::NoTagStyler.new,
|
35
|
+
# Psychgus::CapStyler.new,
|
36
|
+
# Psychgus::FlowStyler.new(4),
|
37
|
+
# hierarchy,
|
38
|
+
# ]
|
39
|
+
# )
|
38
40
|
#
|
39
41
|
# # Output:
|
40
42
|
# # ---
|
@@ -78,8 +80,9 @@ module Psychgus
|
|
78
80
|
# 'BBQ eggs',
|
79
81
|
# 'hard-boiled eggs',
|
80
82
|
# 'soft_boiled eggs',
|
81
|
-
# 'fried@eggs'
|
82
|
-
#
|
83
|
+
# 'fried@eggs',
|
84
|
+
# ]
|
85
|
+
# }
|
83
86
|
#
|
84
87
|
# seq_flow = Psychgus::SeqFlowStyler.new
|
85
88
|
#
|
@@ -205,10 +208,11 @@ module Psychgus
|
|
205
208
|
# require 'psychgus'
|
206
209
|
#
|
207
210
|
# data = {
|
208
|
-
# :
|
209
|
-
# :
|
210
|
-
# :
|
211
|
-
#
|
211
|
+
# eggs: {
|
212
|
+
# styles: ['Fried', 'Scrambled', ['BBQ', 'Ketchup']],
|
213
|
+
# colors: ['Brown', 'White', ['Blue', 'Green']],
|
214
|
+
# }
|
215
|
+
# }
|
212
216
|
#
|
213
217
|
# flow = Psychgus::FlowStyler.new(4)
|
214
218
|
#
|
data/lib/psychgus/version.rb
CHANGED
data/lib/psychgus.rb
CHANGED
@@ -22,7 +22,6 @@ require 'psychgus/version'
|
|
22
22
|
require 'psychgus/ext/core_ext'
|
23
23
|
require 'psychgus/ext/node_ext'
|
24
24
|
require 'psychgus/ext/yaml_tree_ext'
|
25
|
-
|
26
25
|
require 'psychgus/super_sniffer/parent'
|
27
26
|
|
28
27
|
###
|
@@ -31,267 +30,6 @@ require 'psychgus/super_sniffer/parent'
|
|
31
30
|
# Thank you to the people that worked and continue to work hard on that project.
|
32
31
|
#
|
33
32
|
# The name comes from the well-styled character Gus from the TV show Psych.
|
34
|
-
#
|
35
|
-
# == Create a Styler
|
36
|
-
#
|
37
|
-
# First, we will create a {Styler}.
|
38
|
-
#
|
39
|
-
# All you need to do is add +include Psychgus::Styler+ to a class.
|
40
|
-
#
|
41
|
-
# Here is a complex {Styler} for the examples below:
|
42
|
-
# require 'psychgus'
|
43
|
-
#
|
44
|
-
# class BurgerStyler
|
45
|
-
# # Mix in methods needed for styling
|
46
|
-
# include Psychgus::Styler
|
47
|
-
#
|
48
|
-
# def initialize(sniffer=nil)
|
49
|
-
# if sniffer.nil?()
|
50
|
-
# @class_level = 0
|
51
|
-
# @class_position = 0
|
52
|
-
# else
|
53
|
-
# # For the Class Example
|
54
|
-
# @class_level = sniffer.level
|
55
|
-
# @class_position = sniffer.position
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# # Style all nodes (Psych::Nodes::Node)
|
60
|
-
# def style(sniffer,node)
|
61
|
-
# # Remove "!ruby/object:..." for classes
|
62
|
-
# node.tag = nil if node.node_of?(:mapping,:scalar,:sequence)
|
63
|
-
#
|
64
|
-
# # This is another way to do the above
|
65
|
-
# #node.tag = nil if node.respond_to?(:tag=)
|
66
|
-
# end
|
67
|
-
#
|
68
|
-
# # Style aliases (Psych::Nodes::Alias)
|
69
|
-
# def style_alias(sniffer,node)
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
# # Style maps (Psych::Nodes::Mapping)
|
73
|
-
# # - Hashes (key/value pairs)
|
74
|
-
# # - Example: "Burgers: Classic {}"
|
75
|
-
# def style_mapping(sniffer,node)
|
76
|
-
# parent = sniffer.parent
|
77
|
-
#
|
78
|
-
# if !parent.nil?()
|
79
|
-
# # BBQ
|
80
|
-
# node.style = Psychgus::MAPPING_FLOW if parent.node_of?(:scalar) &&
|
81
|
-
# parent.value.casecmp('BBQ') == 0
|
82
|
-
# end
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# # Style scalars (Psych::Nodes::Scalar)
|
86
|
-
# # - Any text (non-alias)
|
87
|
-
# def style_scalar(sniffer,node)
|
88
|
-
# parent = sniffer.parent
|
89
|
-
#
|
90
|
-
# # Single quote scalars that are not keys to a map
|
91
|
-
# # - "child_key?" is the same as "child_type == :key"
|
92
|
-
# node.style = Psychgus::SCALAR_SINGLE_QUOTED unless parent.child_key?()
|
93
|
-
#
|
94
|
-
# # Remove colon (change symbols into strings)
|
95
|
-
# node.value = node.value.sub(':','')
|
96
|
-
#
|
97
|
-
# # Change lettuce to spinach
|
98
|
-
# node.value = 'Spinach' if node.value.casecmp('Lettuce') == 0
|
99
|
-
#
|
100
|
-
# # Capitalize each word
|
101
|
-
# node.value = node.value.split(' ').map do |v|
|
102
|
-
# if v.casecmp('BBQ') == 0
|
103
|
-
# v.upcase()
|
104
|
-
# else
|
105
|
-
# v.capitalize()
|
106
|
-
# end
|
107
|
-
# end.join(' ')
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# # Style sequences (Psych::Nodes::Sequence)
|
111
|
-
# # - Arrays
|
112
|
-
# # - Example: "[Lettuce, Onions, Pickles, Tomatoes]"
|
113
|
-
# def style_sequence(sniffer,node)
|
114
|
-
# relative_level = (sniffer.level - @class_level) + 1
|
115
|
-
#
|
116
|
-
# node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 4
|
117
|
-
#
|
118
|
-
# # Make "[Ketchup, Mustard]" a block for the Class Example
|
119
|
-
# node.style = Psychgus::SEQUENCE_BLOCK if relative_level == 7
|
120
|
-
# end
|
121
|
-
# end
|
122
|
-
#
|
123
|
-
# @example Hash example
|
124
|
-
# require 'psychgus'
|
125
|
-
#
|
126
|
-
# burgers = {
|
127
|
-
# :Burgers => {
|
128
|
-
# :Classic => {
|
129
|
-
# :Sauce => %w(Ketchup Mustard),
|
130
|
-
# :Cheese => 'American',
|
131
|
-
# :Bun => 'Sesame Seed'
|
132
|
-
# },
|
133
|
-
# :BBQ => {
|
134
|
-
# :Sauce => 'Honey BBQ',
|
135
|
-
# :Cheese => 'Cheddar',
|
136
|
-
# :Bun => 'Kaiser'
|
137
|
-
# },
|
138
|
-
# :Fancy => {
|
139
|
-
# :Sauce => 'Spicy Wasabi',
|
140
|
-
# :Cheese => 'Smoked Gouda',
|
141
|
-
# :Bun => 'Hawaiian'
|
142
|
-
# }
|
143
|
-
# },
|
144
|
-
# :Toppings => [
|
145
|
-
# 'Mushrooms',
|
146
|
-
# %w(Lettuce Onions Pickles Tomatoes),
|
147
|
-
# [%w(Ketchup Mustard), %w(Salt Pepper)]
|
148
|
-
# ]
|
149
|
-
# }
|
150
|
-
# burgers[:Favorite] = burgers[:Burgers][:BBQ] # Alias
|
151
|
-
#
|
152
|
-
# puts burgers.to_yaml(indent: 3,stylers: BurgerStyler.new,deref_aliases: true)
|
153
|
-
#
|
154
|
-
# # Output:
|
155
|
-
# # ---
|
156
|
-
# # Burgers:
|
157
|
-
# # Classic:
|
158
|
-
# # Sauce: ['Ketchup', 'Mustard']
|
159
|
-
# # Cheese: 'American'
|
160
|
-
# # Bun: 'Sesame Seed'
|
161
|
-
# # BBQ: {Sauce: 'Honey BBQ', Cheese: 'Cheddar', Bun: 'Kaiser'}
|
162
|
-
# # Fancy:
|
163
|
-
# # Sauce: 'Spicy Wasabi'
|
164
|
-
# # Cheese: 'Smoked Gouda'
|
165
|
-
# # Bun: 'Hawaiian'
|
166
|
-
# # Toppings:
|
167
|
-
# # - 'Mushrooms'
|
168
|
-
# # - ['Spinach', 'Onions', 'Pickles', 'Tomatoes']
|
169
|
-
# # - [['Ketchup', 'Mustard'], ['Salt', 'Pepper']]
|
170
|
-
# # Favorite:
|
171
|
-
# # Sauce: 'Honey BBQ'
|
172
|
-
# # Cheese: 'Cheddar'
|
173
|
-
# # Bun: 'Kaiser'
|
174
|
-
#
|
175
|
-
# @example Class example
|
176
|
-
# require 'psychgus'
|
177
|
-
#
|
178
|
-
# class Burger
|
179
|
-
# attr_accessor :bun
|
180
|
-
# attr_accessor :cheese
|
181
|
-
# attr_accessor :sauce
|
182
|
-
#
|
183
|
-
# def initialize(sauce,cheese,bun)
|
184
|
-
# @bun = bun
|
185
|
-
# @cheese = cheese
|
186
|
-
# @sauce = sauce
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# # You can still use Psych's encode_with(), no problem
|
190
|
-
# #def encode_with(coder)
|
191
|
-
# # coder['Bun'] = @bun
|
192
|
-
# # coder['Cheese'] = @cheese
|
193
|
-
# # coder['Sauce'] = @sauce
|
194
|
-
# #end
|
195
|
-
# end
|
196
|
-
#
|
197
|
-
# class Burgers
|
198
|
-
# include Psychgus::Blueberry
|
199
|
-
#
|
200
|
-
# attr_accessor :burgers
|
201
|
-
# attr_accessor :toppings
|
202
|
-
# attr_accessor :favorite
|
203
|
-
#
|
204
|
-
# def initialize()
|
205
|
-
# @burgers = {
|
206
|
-
# 'Classic' => Burger.new(['Ketchup','Mustard'],'American','Sesame Seed'),
|
207
|
-
# 'BBQ' => Burger.new('Honey BBQ','Cheddar','Kaiser'),
|
208
|
-
# 'Fancy' => Burger.new('Spicy Wasabi','Smoked Gouda','Hawaiian')
|
209
|
-
# }
|
210
|
-
#
|
211
|
-
# @toppings = [
|
212
|
-
# 'Mushrooms',
|
213
|
-
# %w(Lettuce Onions Pickles Tomatoes),
|
214
|
-
# [%w(Ketchup Mustard),%w(Salt Pepper)]
|
215
|
-
# ]
|
216
|
-
#
|
217
|
-
# @favorite = @burgers['BBQ'] # Alias
|
218
|
-
# end
|
219
|
-
#
|
220
|
-
# def psychgus_stylers(sniffer)
|
221
|
-
# return BurgerStyler.new(sniffer)
|
222
|
-
# end
|
223
|
-
#
|
224
|
-
# # You can still use Psych's encode_with(), no problem
|
225
|
-
# #def encode_with(coder)
|
226
|
-
# # coder['Burgers'] = @burgers
|
227
|
-
# # coder['Toppings'] = @toppings
|
228
|
-
# # coder['Favorite'] = @favorite
|
229
|
-
# #end
|
230
|
-
# end
|
231
|
-
#
|
232
|
-
# burgers = Burgers.new
|
233
|
-
# puts burgers.to_yaml(indent: 3,deref_aliases: true)
|
234
|
-
#
|
235
|
-
# # Output:
|
236
|
-
# # ---
|
237
|
-
# # Burgers:
|
238
|
-
# # Classic:
|
239
|
-
# # Bun: 'Sesame Seed'
|
240
|
-
# # Cheese: 'American'
|
241
|
-
# # Sauce:
|
242
|
-
# # - 'Ketchup'
|
243
|
-
# # - 'Mustard'
|
244
|
-
# # BBQ: {Bun: 'Kaiser', Cheese: 'Cheddar', Sauce: 'Honey BBQ'}
|
245
|
-
# # Fancy:
|
246
|
-
# # Bun: 'Hawaiian'
|
247
|
-
# # Cheese: 'Smoked Gouda'
|
248
|
-
# # Sauce: 'Spicy Wasabi'
|
249
|
-
# # Toppings:
|
250
|
-
# # - 'Mushrooms'
|
251
|
-
# # - ['Spinach', 'Onions', 'Pickles', 'Tomatoes']
|
252
|
-
# # - [['Ketchup', 'Mustard'], ['Salt', 'Pepper']]
|
253
|
-
# # Favorite:
|
254
|
-
# # Bun: 'Kaiser'
|
255
|
-
# # Cheese: 'Cheddar'
|
256
|
-
# # Sauce: 'Honey BBQ'
|
257
|
-
#
|
258
|
-
# @example Emitting / Parsing examples
|
259
|
-
# styler = BurgerStyler.new()
|
260
|
-
# options = {:indentation=>3,:stylers=>styler,:deref_aliases=>true}
|
261
|
-
# yaml = burgers.to_yaml(options)
|
262
|
-
#
|
263
|
-
# # High-level emitting
|
264
|
-
# Psychgus.dump(burgers,options)
|
265
|
-
# Psychgus.dump_file('burgers.yaml',burgers,options)
|
266
|
-
# burgers.to_yaml(options)
|
267
|
-
#
|
268
|
-
# # High-level parsing
|
269
|
-
# # - Because to_ruby() will be called, just use Psych:
|
270
|
-
# # - load(), load_file(), load_stream(), safe_load()
|
271
|
-
#
|
272
|
-
# # Mid-level emitting
|
273
|
-
# stream = Psychgus.parse_stream(yaml,stylers: styler,deref_aliases: true)
|
274
|
-
#
|
275
|
-
# stream.to_yaml()
|
276
|
-
#
|
277
|
-
# # Mid-level parsing
|
278
|
-
# Psychgus.parse(yaml,stylers: styler,deref_aliases: true)
|
279
|
-
# Psychgus.parse_file('burgers.yaml',stylers: styler,deref_aliases: true)
|
280
|
-
# Psychgus.parse_stream(yaml,stylers: styler,deref_aliases: true)
|
281
|
-
#
|
282
|
-
# # Low-level emitting
|
283
|
-
# tree_builder = Psychgus::StyledTreeBuilder.new(styler,deref_aliases: true)
|
284
|
-
# visitor = Psych::Visitors::YAMLTree.create(options,tree_builder)
|
285
|
-
#
|
286
|
-
# visitor << burgers
|
287
|
-
# visitor.tree.to_yaml
|
288
|
-
#
|
289
|
-
# # Low-level parsing
|
290
|
-
# parser = Psychgus.parser(stylers: styler,deref_aliases: true)
|
291
|
-
#
|
292
|
-
# parser.parse(yaml)
|
293
|
-
# parser.handler
|
294
|
-
# parser.handler.root
|
295
33
|
###
|
296
34
|
module Psychgus
|
297
35
|
# Include these in the top namespace for convenience (i.e., less typing).
|
@@ -443,7 +181,7 @@ module Psychgus
|
|
443
181
|
# then options will be set to the Hash, instead of objects.
|
444
182
|
#
|
445
183
|
# For example, the below will be stored in options, not objects:
|
446
|
-
# - dump_stream({:
|
184
|
+
# - dump_stream({coffee: {roast: [],style: []}})
|
447
185
|
#
|
448
186
|
# This if-statement is guaranteed because dump_stream([]) and dump_stream(nil)
|
449
187
|
# will produce [[]] and [nil], which are not empty.
|
@@ -474,8 +212,8 @@ module Psychgus
|
|
474
212
|
|
475
213
|
if objects.empty?
|
476
214
|
# Else, will throw a cryptic NoMethodError:
|
477
|
-
#
|
478
|
-
#
|
215
|
+
# psych/tree_builder.rb:in `set_end_location':
|
216
|
+
# undefined method `end_line=' for nil:NilClass (NoMethodError)
|
479
217
|
#
|
480
218
|
# This should never occur because of the if-statement at the top of this method.
|
481
219
|
visitor << nil
|
@@ -496,21 +234,21 @@ module Psychgus
|
|
496
234
|
# require 'psychgus'
|
497
235
|
#
|
498
236
|
# burgers = {
|
499
|
-
# :
|
500
|
-
# :
|
501
|
-
#
|
502
|
-
#
|
503
|
-
# :
|
504
|
-
#
|
505
|
-
#
|
506
|
-
# :
|
507
|
-
#
|
508
|
-
#
|
237
|
+
# burgers: {
|
238
|
+
# classic: {sauce: %w[Ketchup Mustard],
|
239
|
+
# cheese: 'American',
|
240
|
+
# bun: 'Sesame Seed'},
|
241
|
+
# bbq: {sauce: 'Honey BBQ',
|
242
|
+
# cheese: 'Cheddar',
|
243
|
+
# bun: 'Kaiser'},
|
244
|
+
# fancy: {sauce: 'Spicy Wasabi',
|
245
|
+
# cheese: 'Smoked Gouda',
|
246
|
+
# bun: 'Hawaiian'},
|
509
247
|
# },
|
510
|
-
# :
|
248
|
+
# toppings: [
|
511
249
|
# 'Mushrooms',
|
512
|
-
# %w
|
513
|
-
# [%w
|
250
|
+
# %w[Lettuce Onions Pickles Tomatoes],
|
251
|
+
# [%w[Ketchup Mustard], %w[Salt Pepper]],
|
514
252
|
# ]
|
515
253
|
# }
|
516
254
|
#
|
@@ -637,17 +375,17 @@ module Psychgus
|
|
637
375
|
# and the styler(s) will do nothing for you.
|
638
376
|
#
|
639
377
|
# @example
|
640
|
-
# burgers =
|
641
|
-
#
|
642
|
-
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
#
|
646
|
-
#
|
647
|
-
#
|
648
|
-
#
|
649
|
-
#
|
650
|
-
#
|
378
|
+
# burgers = <<~EOY
|
379
|
+
# ---
|
380
|
+
# Burgers:
|
381
|
+
# Classic:
|
382
|
+
# BBQ: {Sauce: Honey BBQ, Cheese: Cheddar, Bun: Kaiser}
|
383
|
+
# ---
|
384
|
+
# Toppings:
|
385
|
+
# - [Mushrooms, Mustard]
|
386
|
+
# - [Salt, Pepper, Pickles]
|
387
|
+
# ---
|
388
|
+
# `Invalid`
|
651
389
|
# EOY
|
652
390
|
#
|
653
391
|
# i = 0
|
@@ -707,16 +445,16 @@ module Psychgus
|
|
707
445
|
# end
|
708
446
|
# end
|
709
447
|
#
|
710
|
-
# coffee =
|
711
|
-
#
|
712
|
-
#
|
713
|
-
#
|
714
|
-
#
|
715
|
-
#
|
716
|
-
#
|
717
|
-
#
|
718
|
-
#
|
719
|
-
#
|
448
|
+
# coffee = <<~EOY
|
449
|
+
# Coffee:
|
450
|
+
# Roast:
|
451
|
+
# - Light
|
452
|
+
# - Medium
|
453
|
+
# - Dark
|
454
|
+
# Style:
|
455
|
+
# - Cappuccino
|
456
|
+
# - Latte
|
457
|
+
# - Mocha
|
720
458
|
# EOY
|
721
459
|
#
|
722
460
|
# parser = Psychgus.parser(stylers: CoffeeStyler.new)
|
@@ -752,7 +490,7 @@ module Psychgus
|
|
752
490
|
#
|
753
491
|
# Private methods of Psych are not defined.
|
754
492
|
#
|
755
|
-
# @note For devs/hacking: because extend is used, do not prefix methods with
|
493
|
+
# @note For devs/hacking: because extend is used, do not prefix methods with `self.`.
|
756
494
|
###
|
757
495
|
module PsychDropIn
|
758
496
|
# @see Psych.add_builtin_type
|
data/psychgus.gemspec
CHANGED
@@ -27,9 +27,9 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.bindir = 'bin'
|
28
28
|
|
29
29
|
spec.files = [
|
30
|
-
Dir.glob(
|
31
|
-
Dir.glob(
|
32
|
-
Dir.glob(
|
30
|
+
Dir.glob("{#{spec.require_paths.join(',')}}/**/*.{erb,rb}"),
|
31
|
+
Dir.glob("#{spec.bindir}/*"),
|
32
|
+
Dir.glob('{samples,test,yard}/**/*.{erb,rb}'),
|
33
33
|
%W[Gemfile #{spec.name}.gemspec Rakefile .yardopts],
|
34
34
|
%w[LICENSE.txt CHANGELOG.md README.md],
|
35
35
|
].flatten
|
data/test/psychgus_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psychgus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley Whited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: psych
|