styles 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +725 -0
  5. data/Rakefile +9 -0
  6. data/bin/styles +11 -0
  7. data/lib/styles.rb +18 -0
  8. data/lib/styles/application.rb +190 -0
  9. data/lib/styles/colors.rb +289 -0
  10. data/lib/styles/core_ext.rb +12 -0
  11. data/lib/styles/engine.rb +73 -0
  12. data/lib/styles/line.rb +55 -0
  13. data/lib/styles/properties.rb +34 -0
  14. data/lib/styles/properties/background_color.rb +15 -0
  15. data/lib/styles/properties/base.rb +68 -0
  16. data/lib/styles/properties/border.rb +147 -0
  17. data/lib/styles/properties/color.rb +16 -0
  18. data/lib/styles/properties/display.rb +10 -0
  19. data/lib/styles/properties/font_weight.rb +13 -0
  20. data/lib/styles/properties/function.rb +7 -0
  21. data/lib/styles/properties/margin.rb +83 -0
  22. data/lib/styles/properties/match_background_color.rb +28 -0
  23. data/lib/styles/properties/match_color.rb +21 -0
  24. data/lib/styles/properties/match_font_weight.rb +23 -0
  25. data/lib/styles/properties/match_text_decoration.rb +36 -0
  26. data/lib/styles/properties/padding.rb +81 -0
  27. data/lib/styles/properties/text_align.rb +10 -0
  28. data/lib/styles/properties/text_decoration.rb +20 -0
  29. data/lib/styles/properties/width.rb +11 -0
  30. data/lib/styles/rule.rb +67 -0
  31. data/lib/styles/stylesheet.rb +103 -0
  32. data/lib/styles/sub_engines.rb +4 -0
  33. data/lib/styles/sub_engines/base.rb +16 -0
  34. data/lib/styles/sub_engines/color.rb +115 -0
  35. data/lib/styles/sub_engines/layout.rb +158 -0
  36. data/lib/styles/sub_engines/pre_processor.rb +19 -0
  37. data/lib/styles/version.rb +3 -0
  38. data/styles.gemspec +26 -0
  39. data/test/application_test.rb +92 -0
  40. data/test/colors_test.rb +162 -0
  41. data/test/engine_test.rb +59 -0
  42. data/test/integration_test.rb +136 -0
  43. data/test/line_test.rb +24 -0
  44. data/test/properties/background_color_test.rb +36 -0
  45. data/test/properties/base_test.rb +11 -0
  46. data/test/properties/border_test.rb +154 -0
  47. data/test/properties/color_test.rb +28 -0
  48. data/test/properties/display_test.rb +26 -0
  49. data/test/properties/font_weight_test.rb +24 -0
  50. data/test/properties/function_test.rb +28 -0
  51. data/test/properties/margin_test.rb +98 -0
  52. data/test/properties/match_background_color_test.rb +71 -0
  53. data/test/properties/match_color_test.rb +79 -0
  54. data/test/properties/match_font_weight_test.rb +34 -0
  55. data/test/properties/match_text_decoration_test.rb +38 -0
  56. data/test/properties/padding_test.rb +87 -0
  57. data/test/properties/text_align_test.rb +107 -0
  58. data/test/properties/text_decoration_test.rb +25 -0
  59. data/test/properties/width_test.rb +41 -0
  60. data/test/rule_test.rb +39 -0
  61. data/test/stylesheet_test.rb +245 -0
  62. data/test/sub_engines/color_test.rb +144 -0
  63. data/test/sub_engines/layout_test.rb +110 -0
  64. data/test/test_helper.rb +5 -0
  65. metadata +184 -0
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aaron Royer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,725 @@
1
+ # Styles
2
+
3
+ plain text stylesheets
4
+
5
+ ## Introduction
6
+
7
+ _Styles_ is an attempt to apply useful CSS concepts to plain text processing. Rules operate on lines of text rather than DOM elements. Not all concepts from CSS are applicable. The most useful ones are:
8
+
9
+ * Selectors (including String and Regexp) to match lines
10
+ * Application of properties to matched lines with the familiar last-one-wins model
11
+
12
+ ## Dependencies
13
+
14
+ - Ruby 1.9 or better
15
+
16
+ ## Installation
17
+
18
+ Install with RubyGems.
19
+
20
+ ```
21
+ $ gem install styles
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Create a stylesheet
27
+
28
+ ```
29
+ $ styles --edit my_styles
30
+ ```
31
+ This will create a new stylesheet in ~/.styles (by default) called my_styles.rb and open it in your $EDITOR. If you don't specify a stylesheet name it will use 'default'.
32
+
33
+ ```ruby
34
+ 'important' - {
35
+ color: blue,
36
+ font_weight: bold,
37
+ text_decoration: underline
38
+ }
39
+
40
+ 'warning' - {
41
+ background_color: yellow
42
+ }
43
+
44
+ /annoying/i - {
45
+ display: none
46
+ }
47
+
48
+ /\d{3}-\d{3}-\d{4}/ - {
49
+ # match_color is like color except it applies to the matched portion of the line
50
+ match_color: green
51
+ }
52
+
53
+ :blank - {
54
+ display: none
55
+ }
56
+ ```
57
+ Stylesheets are written in a pure Ruby DSL that is vaguely similar to CSS. Instead of operating on DOM elements, rules operate on **lines of text**. Rules are specified with a selector, a ```-```, and a hash of properties. A selector can be one of three things.
58
+
59
+ - String - matches if a line contains the string
60
+ - Regexp - matches if the line matches regular expression
61
+ - Symbol - matches certain special types of lines, examples include ```:blank``` and ```:any```
62
+
63
+ To leverage you CSS knowledge, some familiar properties are available. You may notice that their form and the syntax in general is altered to make everything valid Ruby. There are also some others that have no CSS counterparts. See below for a list of all properties and values.
64
+
65
+ ### Apply the stylesheet to some text
66
+
67
+ Pipe some text to ```styles```, specifying which stylesheet you want to use.
68
+
69
+ Lets say example.txt contains this
70
+
71
+ <pre style="background-color:#f8f8ff; padding:5px;">
72
+ this is an important line
73
+ this line is warning you about something
74
+ THIS LINE IS SUPER ANNOYING!
75
+ here is my phone number: 555-234-6789
76
+
77
+ the line before this is blank
78
+ </pre>
79
+
80
+ Let’s use the stylesheet we just created above.
81
+
82
+ <pre style="color:white; background-color:black; padding: 5px;">
83
+ $ cat example.txt | styles my_styles
84
+ <span style="color:royalblue; font-weight:bold; text-decoration:underline;">this is an important line</span>
85
+ <span style="background-color:darkkhaki;">this line is warning you about something</span>
86
+ here is my phone number: <span style="color:green;">555-234-6789</span>
87
+ the line before this is blank
88
+ </pre>
89
+
90
+ The annoying and blank lines have been hidden and, if your terminal supports it, you should see the colors applied as you expect them.
91
+
92
+ ## More Examples
93
+
94
+ #### Only display interesting lines
95
+
96
+ Stylesheet
97
+
98
+ ```ruby
99
+ :all - {
100
+ display: none
101
+ }
102
+
103
+ 'interesting' - {
104
+ display: block # Could also use: display: true
105
+ }
106
+
107
+ /(very|quite|most) interesting/i - {
108
+ background_color: green
109
+ }
110
+ ```
111
+
112
+ Input
113
+
114
+ <pre style="background-color:#f8f8ff; padding:5px;">
115
+ a line
116
+ another line
117
+ nothing to see here
118
+ this is interesting
119
+ this is VERY interesting
120
+ this is not
121
+ </pre>
122
+
123
+ Output
124
+
125
+ <pre style="color:white; background-color:black; padding: 5px;">
126
+ this is interesting
127
+ <span style="background-color:green">this is VERY interesting</span>
128
+ </pre>
129
+
130
+
131
+ #### Do crazy stuff with CSS-style layout properties
132
+
133
+ Stylesheet
134
+
135
+ ```ruby
136
+ 'gimmicky' - {
137
+ padding: 1,
138
+ margin: 2,
139
+ border: 'solid blue',
140
+ width: 30,
141
+ text_align: right
142
+ }
143
+ ```
144
+
145
+ Input
146
+
147
+ <pre style="background-color:#f8f8ff; padding:5px;">
148
+ a bit gimmicky
149
+ </pre>
150
+
151
+ Output
152
+
153
+ <pre style="color:white; background-color:black; padding: 5px;">
154
+ <span style="display:inline-block; border:1px solid blue; padding:13px; margin:23px 23px 23px 23px; width: 220px; text-align:right">a bit gimmicky</span>
155
+ </pre>
156
+
157
+
158
+ #### Do arbitrary processing on lines
159
+
160
+ Stylesheet
161
+
162
+ ```ruby
163
+ 'password' - {
164
+ function: ->(line) { line.sub(/(password is:) (\S+)/, '\1 XXXXXX') }
165
+ }
166
+ ```
167
+
168
+ Input
169
+
170
+ <pre style="background-color:#f8f8ff; padding:5px;">
171
+ the password is: 5up3rs3cr3t
172
+ </pre>
173
+
174
+ Output
175
+
176
+ <pre style="color:white; background-color:black; padding: 5px;">
177
+ the password is: XXXXXX
178
+ </pre>
179
+
180
+
181
+
182
+ ## All Properties
183
+
184
+ Text Styling:
185
+
186
+ * [background_color](#background_color)
187
+ * [color](#color)
188
+ * [font_weight](#font_weight)
189
+ * [text_decoration](#text_decoration)
190
+ * [match_background_color](#match_background_color)
191
+ * [match_color](#match_color)
192
+ * [match_font_weight](#match_font_weight)
193
+ * [match_text_decoration](#match_text_decoration)
194
+
195
+ Layout:
196
+
197
+ * [border](#border)
198
+ * [display](#display)
199
+ * [margin](#margin)
200
+ * [padding](#padding)
201
+ * [text_align](#text_align)
202
+ * [width](#width)
203
+
204
+ Miscellaneous:
205
+
206
+ * [function](#function)
207
+
208
+ ### Text Styling Properties
209
+
210
+ ----
211
+
212
+ #### background_color
213
+ <a name="background_color" />
214
+
215
+ Sets the background color (where supported) for the matched line
216
+
217
+ Valid values: ```black, red, green, yellow, blue, magenta, cyan, white```
218
+
219
+ _See also: match_background_color_
220
+
221
+ ##### Example
222
+
223
+ ```ruby
224
+ 'back' - {
225
+ background_color: blue
226
+ }
227
+ ```
228
+
229
+ <pre style="color:white; background-color:black; padding: 5px;">
230
+ <span style="background-color:royalblue">this line should have background color</span>
231
+ </pre>
232
+
233
+ ----
234
+
235
+ #### color
236
+ <a name="color" />
237
+
238
+ Sets the foreground color (where supported) for the matched line
239
+
240
+ Valid values: ```black, red, green, yellow, blue, magenta, cyan, white```
241
+
242
+ _See also: match_color_
243
+
244
+ ##### Example
245
+
246
+ ```ruby
247
+ /color/i - {
248
+ color: red
249
+ }
250
+ ```
251
+
252
+ <pre style="color:white; background-color:black; padding: 5px;">
253
+ <span style="color:red">this line should have COLOR</span>
254
+ </pre>
255
+
256
+ ----
257
+
258
+ #### font_weight
259
+ <a name="font_weight" />
260
+
261
+ Makes the text bold (where supported) or normal weight for the matched line
262
+
263
+ Valid values: ```normal, bold```
264
+
265
+ ##### Examples
266
+
267
+ ```ruby
268
+ 'bold' - {
269
+ font_weight: bold
270
+ }
271
+ ```
272
+
273
+ <pre style="color:white; background-color:black; padding: 5px;">
274
+ <span style="font-weight:bold">this is bold</span>
275
+ </pre>
276
+
277
+ ```ruby
278
+ 'normal' - {
279
+ font_weight: normal
280
+ }
281
+ ```
282
+
283
+ <pre style="color:white; background-color:black; padding: 5px;">
284
+ <span style="font-weight:normal">this is normal</span>
285
+ </pre>
286
+
287
+ ----
288
+
289
+ #### text_decoration
290
+ <a name="text_decoration" />
291
+
292
+ Applies various text decorations (where supported) to the matched line
293
+
294
+ Valid values: ```none, underline, line_through, strikethrough, blink```
295
+
296
+ _```strikethrough``` is a synonym for ```line_through```_
297
+
298
+ ##### Example
299
+
300
+ ```ruby
301
+ /^decor/ - {
302
+ text_decoration: underline
303
+ }
304
+ ```
305
+
306
+ <pre style="color:white; background-color:black; padding: 5px;">
307
+ <span style="text-decoration:underline">decorate me</span>
308
+ </pre>
309
+
310
+ ----
311
+
312
+ #### match_background_color
313
+ <a name="match_background_color" />
314
+
315
+ Sets the background color (where supported) for the matched portion of a line
316
+
317
+ Valid values: ```black, red, green, yellow, blue, magenta, cyan, white```
318
+
319
+ Multiple colors are applied in the same way as with [match_color](#match_color).
320
+
321
+ ##### Examples
322
+
323
+ ```ruby
324
+ 'test' - {
325
+ match_background_color: blue
326
+ }
327
+ ```
328
+
329
+ <pre style="color:white; background-color:black; padding: 5px;">
330
+ this is a <span style="background-color:royalblue">test</span> line
331
+ </pre>
332
+
333
+ ```ruby
334
+ /\d+/ - {
335
+ match_background_color: red
336
+ }
337
+ ```
338
+
339
+ <pre style="color:white; background-color:black; padding: 5px;">
340
+ this has numbers <span style="background-color:red">5</span> and <span style="background-color:red">18</span>
341
+ </pre>
342
+
343
+ ----
344
+
345
+ #### match_color
346
+ <a name="match_color" />
347
+
348
+ Sets the color (where supported) for the matched portion of a line
349
+
350
+ Valid values: ```black, red, green, yellow, blue, magenta, cyan, white```
351
+
352
+ If a String selector is used then the color is applied to each matching portion of the string in
353
+ the matched line. For a Regexp selector, if there are no groups the color is applied portions of
354
+ the line that the whole Regexp matches. If there are groups then you can specify an Array of colors
355
+ to be applied to the respective groups in the Regexp.
356
+
357
+ ##### Examples
358
+
359
+ ```ruby
360
+ 'test' - {
361
+ match_color: blue
362
+ }
363
+ ```
364
+
365
+ <pre style="color:white; background-color:black; padding: 5px;">
366
+ this is a <span style="color:royalblue">test</span> line
367
+ </pre>
368
+
369
+ ```ruby
370
+ /\d+/ - {
371
+ match_color: red
372
+ }
373
+ ```
374
+
375
+ <pre style="color:white; background-color:black; padding: 5px;">
376
+ this has numbers <span style="color:red">5</span> and <span style="color:red">18</span>
377
+ </pre>
378
+
379
+ ```ruby
380
+ /(m\w*) (m\w*)/ - {
381
+ match_color: [blue, green]
382
+ }
383
+ ```
384
+
385
+ <pre style="color:white; background-color:black; padding: 5px;">
386
+ this line has <span style="color:royalblue">multiple</span> <span style="color:green">matches</span>
387
+ </pre>
388
+
389
+ ----
390
+
391
+ #### match_font_weight
392
+ <a name="match_font_weight" />
393
+
394
+ Makes the text bold (where supported) or normal weight for the matched portion of a line
395
+
396
+ Valid values: ```normal, bold```
397
+
398
+ Multiple match font weights are applied in the same way as with [match_color](#match_color).
399
+
400
+ ##### Example
401
+
402
+ ```ruby
403
+ 'bold' - {
404
+ match_font_weight: bold
405
+ }
406
+ ```
407
+
408
+ <pre style="color:white; background-color:black; padding: 5px;">
409
+ this is <span style="font-weight:bold">bold</span>
410
+ </pre>
411
+
412
+ ----
413
+
414
+ #### match_text_decoration
415
+ <a name="match_text_decoration" />
416
+
417
+ Applies various text decorations (where supported) to the matched portion of a line
418
+
419
+ Valid values: ```none, underline, line_through, strikethrough, blink```
420
+
421
+ _```strikethrough``` is a synonym for ```line_through```_
422
+
423
+ ##### Example
424
+
425
+ ```ruby
426
+ /^decor\w+/ - {
427
+ text_decoration: underline
428
+ }
429
+ ```
430
+
431
+ <pre style="color:white; background-color:black; padding: 5px;">
432
+ <span style="text-decoration:underline">decorate</span> me
433
+ </pre>
434
+
435
+ ----
436
+
437
+ ### Layout Properties
438
+
439
+ ----
440
+
441
+ #### border
442
+ <a name="border" />
443
+
444
+ Adds a one-character width border around matched lines. There are two attributes of the border
445
+ that can be configured: style and color.
446
+
447
+ Valid style values: ```solid, dashed, dotted, double```
448
+
449
+ _```dotted``` is a synonym for ```dashed```_
450
+
451
+ Valid color values: ```black, red, green, yellow, blue, magenta, cyan, white```
452
+
453
+ Style _must_ be specified, color is optional. There is no border width configuration as with CSS.
454
+ If only a style is specified you do not need to put the value in a string. If you are specifying a
455
+ color along with the style you must use a string.
456
+
457
+ ##### Example
458
+
459
+ ```ruby
460
+ 'test' - {
461
+ border: 'solid red'
462
+ }
463
+ ```
464
+
465
+ <pre style="color:white; background-color:black; padding: 5px;">
466
+ <span style="display:inline-block; border:1px solid red; padding:7px; margin:7px 0px 7px 5px;">this is a line for testing</span>
467
+ </pre>
468
+
469
+ ----
470
+
471
+ #### display
472
+ <a name="display" />
473
+
474
+ This may do more in the future, but for now just basically specifies whether to hide or show
475
+ particular lines. This is generally useful for filtering out lines you don't want to see and
476
+ overriding the hiding later if necessary.
477
+
478
+ ```none``` and ```false``` will cause the line to not display. Any other value will cause it to
479
+ display as normal. It is recommended to use ```true``` or ```block``` to show lines as values
480
+ line ```inline``` may have a different meaning later.
481
+
482
+ Valid values: ```block, inline, inline_block, none, true, false```
483
+
484
+ ##### Examples
485
+
486
+ ```ruby
487
+ # Hide lines that contain a string
488
+
489
+ 'test' - {
490
+ display: none
491
+ }
492
+ ```
493
+
494
+ ```ruby
495
+ # Hide all lines except ones that contain a phone number
496
+
497
+ :all - {
498
+ display: none
499
+ }
500
+
501
+ /\d{3}-\d{3}-\d{4}/ - {
502
+ display: block
503
+ }
504
+ ```
505
+
506
+ ----
507
+
508
+ #### margin
509
+ <a name="margin" />
510
+
511
+ Adds space around a line, outside any border or padding, if present. For top and bottom margins,
512
+ lines are added above and below the line. For left and right margins spaces are added on either
513
+ side of the line.
514
+
515
+ Values are specified as integers with no units. If the margin should be the same on every side,
516
+ use a single integer for a value. If margins should be different, use a string with multiple integers.
517
+ A value of ```auto``` can also be used and will center the line in the terminal if specified for
518
+ the left or right margin.
519
+
520
+ Like CSS, sides are configured in this order: top, right, bottom, left. Any number of sides can be
521
+ specified (that is: if you only give 2 integers then only top and right will be set).
522
+
523
+ You can also use the property names ```margin_top```, ```margin_right```, ```margin_bottom```, and
524
+ ```margin_left``` to specify a margin for a single side.
525
+
526
+ ##### Examples
527
+
528
+ ```ruby
529
+ 'special' - {
530
+ margin: 1
531
+ }
532
+ ```
533
+
534
+ <pre style="color:white; background-color:black; padding: 5px;">
535
+ a normal line
536
+ <span style="margin:25px 5px 25px 5px;">a special line</span>
537
+ another normal line
538
+ </pre>
539
+
540
+ ```ruby
541
+ # Different margins can be specified for each side
542
+ # Order is: top, right, bottom, left
543
+ 'special' - {
544
+ margin: '2 1 1 5'
545
+ }
546
+
547
+ # You can also just set the margin for one side
548
+ 'move me to the right' - {
549
+ margin_left: 10
550
+ }
551
+
552
+ # The following sets a margin of 3 on every side except for the bottom, which is 1
553
+ 'another example' - {
554
+ margin: 3,
555
+ margin_bottom: 1
556
+ }
557
+ ```
558
+
559
+ ----
560
+
561
+ #### padding
562
+ <a name="padding" />
563
+
564
+ Adds space around a line, inside any border or margin, if present. For top and bottom padding,
565
+ lines are added above and below the line. For left and right padding spaces are added on either
566
+ side of the line.
567
+
568
+ Valid values are integers with no units. If the padding should be the same on every side, use a
569
+ single integer for a value. If padding should be different, use a string with multiple integers.
570
+
571
+ Like CSS, sides are configured in this order: top, right, bottom, left. Any number of sides can be
572
+ specified (that is: if you only give 2 integers then only top and right will be set).
573
+
574
+ You can also use the property names ```padding_top```, ```padding_right```, ```padding_bottom```, and
575
+ ```padding_left``` to specify padding for a single side.
576
+
577
+ ##### Examples
578
+
579
+ ```ruby
580
+ # Different padding can be specified for each side
581
+ # Order is: top, right, bottom, left
582
+ 'special' - {
583
+ padding: '2 1 1 5'
584
+ }
585
+
586
+ # You can also just set the padding for one side
587
+ 'move me to the right' - {
588
+ padding_left: 10
589
+ }
590
+
591
+ # The following sets padding of 3 on every side except for the bottom, which is 1
592
+ 'another example' - {
593
+ padding: 3,
594
+ padding_bottom: 1
595
+ }
596
+ ```
597
+
598
+ ----
599
+
600
+ #### text_align
601
+ <a name="text_align" />
602
+
603
+ Aligns text within the available width it can occupy. This behaves differently depending on whether
604
+ other layout properties are applied to the line.
605
+
606
+ If there is no padding, border, or margin applied to the line, the text is aligned according to
607
+ the terminal width. ```right``` aligned lines will be moved as far right in the terminal as
608
+ possible. ```center``` aligned lines will appear in the middle of the terminal. ```left```
609
+ alignment usually does nothing, but it can be used to override previous ```text_align``` settings.
610
+ If the terminal width cannot be determined, 80 is used. If the line is longer than the terminal is
611
+ wide then no alignment will be applied.
612
+
613
+ If there is any of padding, border, or margin applied to the line, then the text of the line is
614
+ aligned, inside any border and padding, within the width of the line, set by the ```width```
615
+ property. If no width is specified, or the length of the line text exceeds the width, then nothing
616
+ is done.
617
+
618
+ Valid values: ```left, right, center```
619
+
620
+ ----
621
+
622
+ #### width
623
+ <a name="width" />
624
+
625
+ Sets the width of the line. The W3C box model is used, so this specifies the horizontal area inside
626
+ any border and padding for the line.
627
+
628
+ A valid value is an integer with no units.
629
+
630
+ ----
631
+
632
+ ### Miscellaneous Properties
633
+
634
+ ----
635
+
636
+ #### function
637
+ <a name="function" />
638
+
639
+ This is a catch-all property that allows you to process a line with arbitrary Ruby code.
640
+
641
+ The value for the ```function``` property is any callable object (like a lambda or a proc). The
642
+ "stabby lambda" may be the most convenient to use.
643
+
644
+ The callable should have one parameter. The callable will be called with the text of the matched
645
+ line as its only argument. Whatever is returned will replace the line. An empty string will cause
646
+ a blank line to be output. To skip the line, return ```nil```.
647
+
648
+ ```function``` processing works with the line exactly as it was input, before any other properties
649
+ are applied. Other properties are applied afterward, if any.
650
+
651
+ ##### Examples
652
+
653
+ Stylesheet
654
+
655
+ ```ruby
656
+ /loud/i - {
657
+ function: ->(line) { line.downcase }
658
+ }
659
+ ```
660
+
661
+ Input
662
+
663
+ <pre style="background-color:#f8f8ff; padding:5px;">
664
+ normal volume
665
+ TOO LOUD
666
+ ALSO TOO LOUD
667
+ this is ok
668
+ </pre>
669
+
670
+ Output
671
+
672
+ <pre style="color:white; background-color:black; padding: 5px;">
673
+ normal volume
674
+ too loud
675
+ also too loud
676
+ this is ok
677
+ </pre>
678
+
679
+
680
+ Stylesheet
681
+
682
+ ```ruby
683
+ 'temperature' - {
684
+ function: lambda do |line|
685
+ temp = line.scan(/\d+/).first.to_i
686
+ if temp < 80
687
+ nil # No output, line is skipped
688
+ elsif temp >= 90 && temp < 100
689
+ "WARNING: #{line}"
690
+ elsif temp >= 100
691
+ "EMERGENCY: #{line}"
692
+ else
693
+ line
694
+ end
695
+ end
696
+ }
697
+ ```
698
+
699
+ Input
700
+
701
+ <pre style="background-color:#f8f8ff; padding:5px;">
702
+ the temperature is 75 degrees
703
+ the temperature is 82 degrees
704
+ the temperature is 90 degrees
705
+ the temperature is 103 degrees
706
+ the temperature is 95 degrees
707
+ the temperature is 88 degrees
708
+ the temperature is 77 degrees
709
+ </pre>
710
+
711
+ Output
712
+
713
+ <pre style="color:white; background-color:black; padding: 5px;">
714
+ the temperature is 82 degrees
715
+ WARNING: the temperature is 90 degrees
716
+ EMERGENCY: the temperature is 103 degrees
717
+ WARNING: the temperature is 95 degrees
718
+ the temperature is 88 degrees
719
+ </pre>
720
+
721
+ ----
722
+
723
+ ## License
724
+
725
+ Styles is MIT licensed (see LICENSE.txt)