yaml 0.1.2 → 0.2.3

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.
Files changed (39) hide show
  1. package/History.md +22 -0
  2. package/Makefile +2 -1
  3. package/examples/boolean.yaml +7 -0
  4. package/examples/config.yml +1 -1
  5. package/examples/dates.yaml +7 -0
  6. package/examples/null.yaml +8 -0
  7. package/lib/yaml.js +46 -11
  8. package/package.json +1 -1
  9. package/spec/fixtures/comments.yml +0 -6
  10. package/spec/fixtures/document.yml +0 -4
  11. package/spec/fixtures/hash.hash.yml +0 -7
  12. package/spec/fixtures/hash.inline.invalid.yml +0 -1
  13. package/spec/fixtures/hash.inline.whitespace.yml +0 -4
  14. package/spec/fixtures/hash.inline.yml +0 -1
  15. package/spec/fixtures/hash.list.yml +0 -3
  16. package/spec/fixtures/hash.yml +0 -2
  17. package/spec/fixtures/list.hash.yml +0 -4
  18. package/spec/fixtures/list.inline.invalid.yml +0 -1
  19. package/spec/fixtures/list.inline.yml +0 -1
  20. package/spec/fixtures/list.invalid.yml +0 -5
  21. package/spec/fixtures/list.list.yml +0 -7
  22. package/spec/fixtures/list.lists.yml +0 -6
  23. package/spec/fixtures/list.yml +0 -3
  24. package/spec/lib/images/bg.png +0 -0
  25. package/spec/lib/images/hr.png +0 -0
  26. package/spec/lib/images/loading.gif +0 -0
  27. package/spec/lib/images/sprites.bg.png +0 -0
  28. package/spec/lib/images/sprites.png +0 -0
  29. package/spec/lib/images/vr.png +0 -0
  30. package/spec/lib/jspec.css +0 -149
  31. package/spec/lib/jspec.growl.js +0 -115
  32. package/spec/lib/jspec.jquery.js +0 -79
  33. package/spec/lib/jspec.js +0 -1889
  34. package/spec/lib/jspec.nodejs.js +0 -18
  35. package/spec/lib/jspec.shell.js +0 -39
  36. package/spec/lib/jspec.timers.js +0 -90
  37. package/spec/lib/jspec.xhr.js +0 -208
  38. package/spec/node.js +0 -9
  39. package/spec/spec.core.js +0 -222
package/History.md CHANGED
@@ -1,4 +1,26 @@
1
1
 
2
+ 0.2.3 / 2011-12-05
3
+ ==================
4
+
5
+ * Added a "null.yaml" test case in the examples.
6
+ * Added support for NULL values.
7
+ * Fixed a global leak
8
+
9
+ 0.2.2 / 2011-08-31
10
+ ==================
11
+
12
+ * Made it so the first indentation in the input determines the indentation ammount (instead of it being statically set to 2 spaces) [joelverhagen]
13
+
14
+ 0.2.1 / 2011-05-22
15
+ ==================
16
+
17
+ * Fixed boolean support [Adrian Olaru]
18
+
19
+ 0.2.0 / 2011-05-21
20
+ ==================
21
+
22
+ * Added support for dates [Adrian Olaru]
23
+
2
24
  0.1.1 / 2010-12-15
3
25
  ==================
4
26
 
package/Makefile CHANGED
@@ -9,5 +9,6 @@ examples:
9
9
  @node examples/run.js examples/list.nested.yml
10
10
  @node examples/run.js examples/hash.yml
11
11
  @node examples/run.js examples/config.yml
12
+ @node examples/run.js examples/dates.yml
12
13
 
13
- .PHONY: test examples
14
+ .PHONY: test examples
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Some Title
3
+ falseme: I can see this
4
+ what: no
5
+ say: yes
6
+ trueme: found
7
+ hope: to see this
@@ -5,4 +5,4 @@
5
5
  timeout: 15
6
6
  servers: 2
7
7
  require: []
8
-
8
+ dbg-mode: false
@@ -0,0 +1,7 @@
1
+ ---
2
+ date0: 2011-05-21
3
+ date1: 2011-5-21
4
+ date2: 2011-1-2
5
+ date3: 2011-02-21 17:56
6
+ date4: 2011-04-21 5:35
7
+ date5: 2011-06-02 20:45:30
@@ -0,0 +1,8 @@
1
+ ---
2
+ test: A test for null values
3
+ thisis: null
4
+ thistoo: NULL
5
+ notnull: yes
6
+ tildeis: ~
7
+ capitalized: Null
8
+ end: test passed?
package/lib/yaml.js CHANGED
@@ -1,11 +1,10 @@
1
-
2
1
  // YAML - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
3
2
 
4
3
  /**
5
4
  * Version triplet.
6
5
  */
7
6
 
8
- exports.version = '0.1.2'
7
+ exports.version = '0.2.3'
9
8
 
10
9
  // --- Helpers
11
10
 
@@ -37,10 +36,12 @@ var tokens = [
37
36
  ['comment', /^#[^\n]*/],
38
37
  ['indent', /^\n( *)/],
39
38
  ['space', /^ +/],
40
- ['true', /^(enabled|true|yes|on)/],
41
- ['false', /^(disabled|false|no|off)/],
39
+ ['true', /^\b(enabled|true|yes|on)\b/],
40
+ ['false', /^\b(disabled|false|no|off)\b/],
41
+ ['null', /^\b(null|Null|NULL|~)\b/],
42
42
  ['string', /^"(.*?)"/],
43
43
  ['string', /^'(.*?)'/],
44
+ ['timestamp', /^((\d{4})-(\d\d?)-(\d\d?)(?:(?:[ \t]+)(\d\d?):(\d\d)(?::(\d\d))?)?)/],
44
45
  ['float', /^(\d+\.\d+)/],
45
46
  ['int', /^(\d+)/],
46
47
  ['doc', /^---/],
@@ -52,7 +53,7 @@ var tokens = [
52
53
  ['-', /^\-/],
53
54
  [':', /^[:]/],
54
55
  ['string', /^(?![^:\n\s]*:[^\/]{2})(([^:,\]\}\n\s]|(?!\n)\s(?!\s*?\n)|:\/\/|,(?=[^\n]*\s*[^\]\}\s\n]\s*\n)|[\]\}](?=[^\n]*\s*[^\]\}\s\n]\s*\n))*)(?=[,:\]\}\s\n]|$)/],
55
- ['id', /^([\w ]+)/],
56
+ ['id', /^([\w][\w -]*)/]
56
57
  ]
57
58
 
58
59
  /**
@@ -65,8 +66,8 @@ var tokens = [
65
66
 
66
67
  exports.tokenize = function (str) {
67
68
  var token, captures, ignore, input,
68
- indents = lastIndents = 0,
69
- stack = []
69
+ indents = 0, lastIndents = 0,
70
+ stack = [], indentAmount = -1
70
71
  while (str.length) {
71
72
  for (var i = 0, len = tokens.length; i < len; ++i)
72
73
  if (captures = tokens[i][1].exec(str)) {
@@ -77,8 +78,13 @@ exports.tokenize = function (str) {
77
78
  ignore = true
78
79
  break
79
80
  case 'indent':
80
- lastIndents = indents
81
- indents = token[1][1].length / 2
81
+ lastIndents = indents
82
+ // determine the indentation amount from the first indent
83
+ if (indentAmount == -1) {
84
+ indentAmount = token[1][1].length
85
+ }
86
+
87
+ indents = token[1][1].length / indentAmount
82
88
  if (indents === lastIndents)
83
89
  ignore = true
84
90
  else if (indents > lastIndents + 1)
@@ -217,6 +223,7 @@ Parser.prototype.ignoreWhitespace = function() {
217
223
  * | int
218
224
  * | true
219
225
  * | false
226
+ * | null
220
227
  */
221
228
 
222
229
  Parser.prototype.parse = function() {
@@ -233,14 +240,18 @@ Parser.prototype.parse = function() {
233
240
  return this.parseHash()
234
241
  case 'string':
235
242
  return this.advanceValue()
243
+ case 'timestamp':
244
+ return this.parseTimestamp()
236
245
  case 'float':
237
246
  return parseFloat(this.advanceValue())
238
247
  case 'int':
239
248
  return parseInt(this.advanceValue())
240
249
  case 'true':
241
- return true
250
+ this.advanceValue(); return true
242
251
  case 'false':
243
- return false
252
+ this.advanceValue(); return false
253
+ case 'null':
254
+ this.advanceValue(); return null
244
255
  }
245
256
  }
246
257
 
@@ -337,6 +348,30 @@ Parser.prototype.parseInlineList = function() {
337
348
  return list
338
349
  }
339
350
 
351
+ /**
352
+ * yyyy-mm-dd hh:mm:ss
353
+ *
354
+ * For full format: http://yaml.org/type/timestamp.html
355
+ */
356
+
357
+ Parser.prototype.parseTimestamp = function() {
358
+ var token = this.advance()[1]
359
+ var date = new Date
360
+ var year = token[2]
361
+ , month = token[3]
362
+ , day = token[4]
363
+ , hour = token[5] || 0
364
+ , min = token[6] || 0
365
+ , sec = token[7] || 0
366
+
367
+ date.setUTCFullYear(year, month-1, day)
368
+ date.setUTCHours(hour)
369
+ date.setUTCMinutes(min)
370
+ date.setUTCSeconds(sec)
371
+ date.setUTCMilliseconds(0)
372
+ return date
373
+ }
374
+
340
375
  /**
341
376
  * Evaluate a _str_ of yaml.
342
377
  *
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "yaml",
2
- "version": "0.1.2",
2
+ "version": "0.2.3",
3
3
  "description": "Yaml parser",
4
4
  "author": "TJ Holowaychuk <tj@vision-media.ca>",
5
5
  "main": "./lib/yaml.js"
@@ -1,6 +0,0 @@
1
- -1
2
- # rawr
3
- -2
4
- # foo bar
5
- # something
6
- -3
@@ -1,4 +0,0 @@
1
- ---
2
- - 1
3
- - 2
4
- - 3
@@ -1,7 +0,0 @@
1
- pets:
2
- niko: 2
3
- simon: 14
4
- birthMonths:
5
- niko: "May"
6
- simon: "June"
7
-
@@ -1 +0,0 @@
1
- { name: "tj" email: "tj@vision-media.ca" }
@@ -1,4 +0,0 @@
1
- tj: {
2
- name: "tj",
3
- age: 23
4
- }
@@ -1 +0,0 @@
1
- { name: "tj", email: "tj@vision-media.ca" }
@@ -1,3 +0,0 @@
1
- pets:
2
- - "niko"
3
- - "simon"
@@ -1,2 +0,0 @@
1
- a: 1
2
- b: 2
@@ -1,4 +0,0 @@
1
- -
2
- name: "tj"
3
- -
4
- name: "simon"
@@ -1 +0,0 @@
1
- [1 1]
@@ -1 +0,0 @@
1
- ["tj", 23]
@@ -1,5 +0,0 @@
1
- -
2
- - 1
3
- - 2
4
- -
5
- - 3
@@ -1,7 +0,0 @@
1
- -
2
- - 1
3
- - 2
4
- - 3
5
- -
6
- - 4
7
- - 5
@@ -1,6 +0,0 @@
1
- - 1
2
- -
3
- - 2
4
- -
5
- - 3
6
- - 4
@@ -1,3 +0,0 @@
1
- - 1
2
- - 2
3
- - 3
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,149 +0,0 @@
1
- body.jspec {
2
- margin: 45px 0;
3
- font: 12px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
4
- background: #efefef url(images/bg.png) top left repeat-x;
5
- text-align: center;
6
- }
7
- #jspec {
8
- margin: 0 auto;
9
- padding-top: 30px;
10
- width: 1008px;
11
- background: url(images/vr.png) top left repeat-y;
12
- text-align: left;
13
- }
14
- #jspec-top {
15
- position: relative;
16
- margin: 0 auto;
17
- width: 1008px;
18
- height: 40px;
19
- background: url(images/sprites.bg.png) top left no-repeat;
20
- }
21
- #jspec-bottom {
22
- margin: 0 auto;
23
- width: 1008px;
24
- height: 15px;
25
- background: url(images/sprites.bg.png) bottom left no-repeat;
26
- }
27
- #jspec .loading {
28
- margin-top: -45px;
29
- width: 1008px;
30
- height: 80px;
31
- background: url(images/loading.gif) 50% 50% no-repeat;
32
- }
33
- #jspec-title {
34
- position: absolute;
35
- top: 15px;
36
- left: 20px;
37
- width: 160px;
38
- font-size: 22px;
39
- font-weight: normal;
40
- background: url(images/sprites.png) 0 -126px no-repeat;
41
- text-align: center;
42
- }
43
- #jspec-title em {
44
- font-size: 10px;
45
- font-style: normal;
46
- color: #BCC8D1;
47
- }
48
- #jspec-report * {
49
- margin: 0;
50
- padding: 0;
51
- background: none;
52
- border: none;
53
- }
54
- #jspec-report {
55
- padding: 15px 40px;
56
- font: 11px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
57
- color: #7B8D9B;
58
- }
59
- #jspec-report.has-failures {
60
- padding-bottom: 30px;
61
- }
62
- #jspec-report .hidden {
63
- display: none;
64
- }
65
- #jspec-report .heading {
66
- margin-bottom: 15px;
67
- }
68
- #jspec-report .heading span {
69
- padding-right: 10px;
70
- }
71
- #jspec-report .heading .passes em {
72
- color: #0ea0eb;
73
- }
74
- #jspec-report .heading .failures em {
75
- color: #FA1616;
76
- }
77
- #jspec-report table {
78
- font-size: 11px;
79
- border-collapse: collapse;
80
- }
81
- #jspec-report td {
82
- padding: 8px;
83
- text-indent: 30px;
84
- color: #7B8D9B;
85
- }
86
- #jspec-report tr.body {
87
- display: none;
88
- }
89
- #jspec-report tr.body pre {
90
- margin: 0;
91
- padding: 0 0 5px 25px;
92
- }
93
- #jspec-report tr.even:hover + tr.body,
94
- #jspec-report tr.odd:hover + tr.body {
95
- display: block;
96
- }
97
- #jspec-report tr td:first-child em {
98
- display: block;
99
- clear: both;
100
- font-style: normal;
101
- font-weight: normal;
102
- color: #7B8D9B;
103
- }
104
- #jspec-report tr.even:hover,
105
- #jspec-report tr.odd:hover {
106
- text-shadow: 1px 1px 1px #fff;
107
- background: #F2F5F7;
108
- }
109
- #jspec-report td + td {
110
- padding-right: 0;
111
- width: 15px;
112
- }
113
- #jspec-report td.pass {
114
- background: url(images/sprites.png) 3px -7px no-repeat;
115
- }
116
- #jspec-report td.fail {
117
- background: url(images/sprites.png) 3px -158px no-repeat;
118
- font-weight: bold;
119
- color: #FC0D0D;
120
- }
121
- #jspec-report td.requires-implementation {
122
- background: url(images/sprites.png) 3px -333px no-repeat;
123
- }
124
- #jspec-report tr.description td {
125
- margin-top: 25px;
126
- padding-top: 25px;
127
- font-size: 12px;
128
- font-weight: bold;
129
- text-indent: 0;
130
- color: #1a1a1a;
131
- }
132
- #jspec-report tr.description:first-child td {
133
- border-top: none;
134
- }
135
- #jspec-report .assertion {
136
- display: block;
137
- float: left;
138
- margin: 0 0 0 1px;
139
- padding: 0;
140
- width: 1px;
141
- height: 5px;
142
- background: #7B8D9B;
143
- }
144
- #jspec-report .assertion.failed {
145
- background: red;
146
- }
147
- .jspec-sandbox {
148
- display: none;
149
- }
@@ -1,115 +0,0 @@
1
-
2
- // JSpec - Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
3
-
4
- ;(function(){
5
-
6
- Growl = {
7
-
8
- // --- Version
9
-
10
- version: '1.0.0',
11
-
12
- /**
13
- * Execute the given _cmd_, returning an array of lines from stdout.
14
- *
15
- * Examples:
16
- *
17
- * Growl.exec('growlnotify', '-m', msg)
18
- *
19
- * @param {string ...} cmd
20
- * @return {array}
21
- * @api public
22
- */
23
-
24
- exec: function(cmd) {
25
- var lines = [], line
26
- with (JavaImporter(java.lang, java.io)) {
27
- var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
28
- var stream = new DataInputStream(proccess.getInputStream())
29
- while (line = stream.readLine())
30
- lines.push(line + '')
31
- stream.close()
32
- }
33
- return lines
34
- },
35
-
36
- /**
37
- * Return the extension of the given _path_ or null.
38
- *
39
- * @param {string} path
40
- * @return {string}
41
- * @api private
42
- */
43
-
44
- extname: function(path) {
45
- return path.lastIndexOf('.') != -1 ?
46
- path.slice(path.lastIndexOf('.') + 1, path.length) :
47
- null
48
- },
49
-
50
- /**
51
- * Version of the 'growlnotify' binary.
52
- *
53
- * @return {string}
54
- * @api private
55
- */
56
-
57
- binVersion: function() {
58
- try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
59
- },
60
-
61
- /**
62
- * Send growl notification _msg_ with _options_.
63
- *
64
- * Options:
65
- *
66
- * - title Notification title
67
- * - sticky Make the notification stick (defaults to false)
68
- * - name Application name (defaults to growlnotify)
69
- * - image
70
- * - path to an icon sets --iconpath
71
- * - path to an image sets --image
72
- * - capitalized word sets --appIcon
73
- * - filename uses extname as --icon
74
- * - otherwise treated as --icon
75
- *
76
- * Examples:
77
- *
78
- * Growl.notify('New email')
79
- * Growl.notify('5 new emails', { title: 'Thunderbird' })
80
- *
81
- * @param {string} msg
82
- * @param {options} hash
83
- * @api public
84
- */
85
-
86
- notify: function(msg, options) {
87
- options = options || {}
88
- var args = ['growlnotify', '-m', msg]
89
- if (!this.binVersion()) throw new Error('growlnotify executable is required')
90
- if (image = options.image) {
91
- var flag, ext = this.extname(image)
92
- flag = flag || ext == 'icns' && 'iconpath'
93
- flag = flag || /^[A-Z]/.test(image) && 'appIcon'
94
- flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
95
- flag = flag || ext && (image = ext) && 'icon'
96
- flag = flag || 'icon'
97
- args.push('--' + flag, image)
98
- }
99
- if (options.sticky) args.push('--sticky')
100
- if (options.name) args.push('--name', options.name)
101
- if (options.title) args.push(options.title)
102
- this.exec.apply(this, args)
103
- }
104
- }
105
-
106
- JSpec.include({
107
- name: 'Growl',
108
- reporting: function(options){
109
- var stats = JSpec.stats
110
- if (stats.failures) Growl.notify('failed ' + stats.failures + ' assertions', { title: 'JSpec'})
111
- else Growl.notify('passed ' + stats.passes + ' assertions', { title: 'JSpec' })
112
- }
113
- })
114
-
115
- })()
@@ -1,79 +0,0 @@
1
-
2
- // JSpec - jQuery - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
3
-
4
- JSpec
5
- .requires('jQuery', 'when using jspec.jquery.js')
6
- .include({
7
- name: 'jQuery',
8
-
9
- // --- Initialize
10
-
11
- init : function() {
12
- jQuery.ajaxSetup({ async: false })
13
- },
14
-
15
- // --- Utilities
16
-
17
- utilities : {
18
- element: jQuery,
19
- elements: jQuery,
20
- sandbox : function() {
21
- return jQuery('<div class="sandbox"></div>')
22
- }
23
- },
24
-
25
- // --- Matchers
26
-
27
- matchers : {
28
- have_tag : "jQuery(expected, actual).length === 1",
29
- have_one : "alias have_tag",
30
- have_tags : "jQuery(expected, actual).length > 1",
31
- have_many : "alias have_tags",
32
- have_any : "alias have_tags",
33
- have_child : "jQuery(actual).children(expected).length === 1",
34
- have_children : "jQuery(actual).children(expected).length > 1",
35
- have_text : "jQuery(actual).text() === expected",
36
- have_value : "jQuery(actual).val() === expected",
37
- be_enabled : "!jQuery(actual).attr('disabled')",
38
- have_class : "jQuery(actual).hasClass(expected)",
39
- be_animated : "jQuery(actual).queue().length > 0",
40
-
41
- be_visible : function(actual) {
42
- return jQuery(actual).css('display') != 'none' &&
43
- jQuery(actual).css('visibility') != 'hidden' &&
44
- jQuery(actual).attr('type') != 'hidden'
45
- },
46
-
47
- be_hidden : function(actual) {
48
- return !JSpec.does(actual, 'be_visible')
49
- },
50
-
51
- have_classes : function(actual) {
52
- return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){
53
- return !JSpec.does(actual, 'have_class', arg)
54
- })
55
- },
56
-
57
- have_attr : function(actual, attr, value) {
58
- return value ? jQuery(actual).attr(attr) == value:
59
- jQuery(actual).attr(attr)
60
- },
61
-
62
- have_event_handlers : function(actual, expected) {
63
- return jQuery(actual).data('events') ?
64
- jQuery(actual).data('events').hasOwnProperty(expected) :
65
- false
66
- },
67
-
68
- 'be disabled selected checked' : function(attr) {
69
- return 'jQuery(actual).attr("' + attr + '")'
70
- },
71
-
72
- 'have type id title alt href src sel rev name target' : function(attr) {
73
- return function(actual, value) {
74
- return JSpec.does(actual, 'have_attr', attr, value)
75
- }
76
- }
77
- }
78
- })
79
-