psychgus 1.3.5 → 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 -2
- data/CHANGELOG.md +15 -4
- data/Gemfile +5 -5
- data/README.md +164 -173
- data/Rakefile +9 -12
- data/lib/psychgus/blueberry.rb +2 -2
- data/lib/psychgus/ext/core_ext.rb +6 -5
- data/lib/psychgus/ext/yaml_tree_ext.rb +1 -2
- data/lib/psychgus/stylables.rb +7 -7
- data/lib/psychgus/styled_document_stream.rb +1 -1
- data/lib/psychgus/styled_tree_builder.rb +2 -2
- data/lib/psychgus/stylers.rb +19 -15
- data/lib/psychgus/version.rb +1 -1
- data/lib/psychgus.rb +47 -306
- data/psychgus.gemspec +13 -10
- data/test/blueberry_test.rb +57 -58
- data/test/psychgus_test.rb +35 -36
- data/test/sniffer_test.rb +6 -6
- data/test/styler_test.rb +32 -33
- data/test/stylers_test.rb +25 -25
- data/test/{psychgus_tester.rb → test_helper.rb} +8 -8
- metadata +6 -6
- data/yard/templates/default/layout/html/footer.erb +0 -5
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/psychgus)
|
4
4
|
[](https://github.com/esotericpig/psychgus/actions/workflows/ci.yml)
|
5
|
-
[](https://inch-ci.org/github/esotericpig/psychgus)
|
6
6
|
|
7
7
|
[](https://esotericpig.github.io/docs/psychgus/yardoc/index.html)
|
8
8
|
[](https://github.com/esotericpig/psychgus)
|
@@ -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,18 +44,15 @@ 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
|
63
56
|
|
64
57
|
Pick your poison...
|
65
58
|
|
@@ -67,33 +60,30 @@ 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
|
94
84
|
```
|
95
85
|
|
96
|
-
##
|
86
|
+
## Using
|
97
87
|
|
98
88
|
Documentation (YARDoc) is available on my [GitHub Page](https://esotericpig.github.io/docs/psychgus/yardoc/index.html) and on [RubyDoc.info](https://www.rubydoc.info/gems/psychgus).
|
99
89
|
|
@@ -103,15 +93,72 @@ 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
|
-
| [Common Stylers](#common-stylers)
|
113
101
|
|
114
|
-
###
|
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
|
+
```
|
160
|
+
|
161
|
+
### Simple Example
|
115
162
|
|
116
163
|
```Ruby
|
117
164
|
require 'psychgus'
|
@@ -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)
|
@@ -157,7 +204,7 @@ puts Coffee.new.to_yaml
|
|
157
204
|
# style: [Cappuccino, Espresso, Latte, Mocha]
|
158
205
|
```
|
159
206
|
|
160
|
-
###
|
207
|
+
### Hash Example
|
161
208
|
|
162
209
|
```Ruby
|
163
210
|
require 'psychgus'
|
@@ -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
|
# ---
|
@@ -252,64 +294,59 @@ puts burgers.to_yaml({:indent => 3,:stylers => BurgerStyler.new,:deref_aliases =
|
|
252
294
|
# Bun: Kaiser
|
253
295
|
```
|
254
296
|
|
255
|
-
###
|
297
|
+
### Class Example
|
256
298
|
|
257
299
|
```Ruby
|
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
|
@@ -423,7 +460,7 @@ puts burgers.to_yaml({:indent => 3,:deref_aliases => true})
|
|
423
460
|
# Sauce: 'Honey BBQ'
|
424
461
|
```
|
425
462
|
|
426
|
-
###
|
463
|
+
### Advanced Usage
|
427
464
|
|
428
465
|
```Ruby
|
429
466
|
require 'psychgus'
|
@@ -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,64 +570,7 @@ puts parser.handler.root.to_ruby
|
|
514
570
|
puts
|
515
571
|
```
|
516
572
|
|
517
|
-
|
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
|
-
#### [//](#common-stylers) 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
|
-
## [//](#contents) Hacking
|
573
|
+
## Hacking
|
575
574
|
|
576
575
|
```
|
577
576
|
$ git clone 'https://github.com/esotericpig/psychgus.git'
|
@@ -580,28 +579,20 @@ $ bundle install
|
|
580
579
|
$ bundle exec rake -T
|
581
580
|
```
|
582
581
|
|
583
|
-
### [//](#hacking) Testing
|
584
|
-
|
585
582
|
Run tests:
|
586
583
|
|
587
584
|
`$ bundle exec rake test`
|
588
585
|
|
589
|
-
### [//](#hacking) 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
|
600
591
|
|
601
592
|
[GNU LGPL v3+](LICENSE.txt)
|
602
593
|
|
603
594
|
> Psychgus (<https://github.com/esotericpig/psychgus>)
|
604
|
-
> Copyright (c) 2017-
|
595
|
+
> Copyright (c) 2017-2025 Bradley Whited
|
605
596
|
>
|
606
597
|
> Psychgus is free software: you can redistribute it and/or modify
|
607
598
|
> it under the terms of the GNU Lesser General Public License as published by
|
data/Rakefile
CHANGED
@@ -7,14 +7,13 @@ require 'yard'
|
|
7
7
|
require 'yard_ghurt'
|
8
8
|
|
9
9
|
require 'psychgus/version'
|
10
|
-
|
11
10
|
require 'rake/clean'
|
12
11
|
require 'rake/testtask'
|
13
12
|
|
14
|
-
task default: [
|
13
|
+
task default: %i[test]
|
15
14
|
|
16
15
|
CLEAN.exclude('.git/','stock/')
|
17
|
-
CLOBBER.include('doc/')
|
16
|
+
CLOBBER.include('.yardoc/','doc/')
|
18
17
|
|
19
18
|
# Execute "rake clobber doc" for pristine docs.
|
20
19
|
desc 'Generate documentation (YARDoc)'
|
@@ -24,30 +23,28 @@ task doc: %i[yard yard_gfm_fix]
|
|
24
23
|
# GST=1 bundle update && bundle exec rake test
|
25
24
|
Rake::TestTask.new do |task|
|
26
25
|
task.libs = ['lib','test']
|
27
|
-
task.pattern =
|
28
|
-
task.
|
29
|
-
#task.options = '--verbose' # Execute "rake test TESTOPT=-v" instead.
|
26
|
+
task.pattern = 'test/**/*_test.rb'
|
27
|
+
# task.options = '--verbose' # Execute "rake test TESTOPT=-v" instead.
|
30
28
|
task.verbose = true
|
31
29
|
task.warning = true
|
32
30
|
end
|
33
31
|
|
34
32
|
YARD::Rake::YardocTask.new do |task|
|
35
|
-
task.files = [
|
33
|
+
task.files = ['lib/**/*.rb']
|
34
|
+
task.options += ['--title',"Psychgus v#{Psychgus::VERSION}"]
|
36
35
|
end
|
37
36
|
|
38
37
|
YardGhurt::GFMFixTask.new do |task|
|
39
|
-
task.description = 'Fix (find & replace) text in the YARD files for GitHub differences'
|
40
|
-
|
41
38
|
task.arg_names = [:dev]
|
42
39
|
task.dry_run = false
|
43
40
|
task.fix_code_langs = true
|
44
41
|
task.md_files = ['index.html']
|
45
42
|
|
46
|
-
task.before = proc do |t2,
|
47
|
-
# Delete this file as it's never used (index.html is an exact copy)
|
43
|
+
task.before = proc do |t2,_args|
|
44
|
+
# Delete this file as it's never used (index.html is an exact copy).
|
48
45
|
YardGhurt.rm_exist(File.join(t2.doc_dir,'file.README.html'))
|
49
46
|
|
50
47
|
t2.css_styles << '<link rel="stylesheet" type="text/css" href="/css/prism.css" />'
|
51
|
-
t2.js_scripts << '<script src="/js/prism.js"></script>
|
48
|
+
t2.js_scripts << '<script src="/js/prism.js"></script>'
|
52
49
|
end
|
53
50
|
end
|