zucker 1 → 2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/CHANGELOG +14 -0
  2. data/Rakefile +14 -4
  3. data/lib/zucker.rb +0 -4
  4. data/lib/zucker/2/D.rb +19 -0
  5. data/lib/zucker/2/aliases.rb +28 -0
  6. data/lib/zucker/2/all.rb +6 -0
  7. data/lib/zucker/2/array.rb +17 -0
  8. data/lib/zucker/2/array2proc.rb +16 -0
  9. data/lib/zucker/2/binding.rb +25 -0
  10. data/lib/zucker/2/blank.rb +26 -0
  11. data/lib/zucker/2/class2proc.rb +10 -0
  12. data/lib/zucker/2/debug.rb +4 -0
  13. data/lib/zucker/2/default.rb +25 -0
  14. data/lib/zucker/2/desc/D.yaml +23 -0
  15. data/lib/zucker/2/desc/aliases.yaml +16 -0
  16. data/lib/zucker/2/desc/array.yaml +14 -0
  17. data/lib/zucker/2/desc/array2proc.yaml +17 -0
  18. data/lib/zucker/2/desc/binding.yaml +10 -0
  19. data/lib/zucker/2/desc/blank.yaml +10 -0
  20. data/lib/zucker/2/desc/class2proc.yaml +12 -0
  21. data/lib/zucker/2/desc/egonil.yaml +17 -0
  22. data/lib/zucker/2/desc/enumerable.yaml +11 -0
  23. data/lib/zucker/2/desc/hash.yaml +14 -0
  24. data/lib/zucker/2/desc/hash2proc.yaml +11 -0
  25. data/lib/zucker/2/desc/info.yaml +12 -0
  26. data/lib/zucker/2/desc/iterate.yaml +17 -0
  27. data/lib/zucker/2/desc/ivars.yaml +20 -0
  28. data/lib/zucker/2/desc/kernel.yaml +13 -0
  29. data/lib/zucker/2/desc/mcopy.yaml +12 -0
  30. data/lib/zucker/2/desc/mm.yaml +12 -0
  31. data/lib/zucker/2/desc/regexp2proc.yaml +13 -0
  32. data/lib/zucker/2/desc/sandbox.yaml +19 -0
  33. data/lib/zucker/2/desc/square_brackets_for.yaml +23 -0
  34. data/lib/zucker/2/desc/string.yaml +13 -0
  35. data/lib/zucker/2/desc/unary.yaml +15 -0
  36. data/lib/zucker/2/desc/union.yaml +11 -0
  37. data/lib/zucker/2/doc/zucker_doc.html +1494 -0
  38. data/lib/zucker/2/doc/zucker_doc.rb +498 -0
  39. data/lib/zucker/2/egonil.rb +14 -0
  40. data/lib/zucker/2/enumerable.rb +12 -0
  41. data/lib/zucker/2/hash.rb +19 -0
  42. data/lib/zucker/2/hash2proc.rb +14 -0
  43. data/lib/zucker/2/info.rb +164 -0
  44. data/lib/zucker/2/iterate.rb +23 -0
  45. data/lib/zucker/2/ivars.rb +26 -0
  46. data/lib/zucker/2/kernel.rb +18 -0
  47. data/lib/zucker/2/mcopy.rb +9 -0
  48. data/lib/zucker/2/mm.rb +31 -0
  49. data/lib/zucker/2/regexp2proc.rb +10 -0
  50. data/lib/zucker/2/sandbox.rb +19 -0
  51. data/lib/zucker/2/spec/D_spec.rb +35 -0
  52. data/lib/zucker/2/spec/aliases_spec.rb +13 -0
  53. data/lib/zucker/2/spec/array2proc_spec.rb +12 -0
  54. data/lib/zucker/2/spec/array_spec.rb +23 -0
  55. data/lib/zucker/2/spec/binding_spec.rb +8 -0
  56. data/lib/zucker/2/spec/blank_spec.rb +20 -0
  57. data/lib/zucker/2/spec/class2proc_spec.rb +9 -0
  58. data/lib/zucker/2/spec/egonil_spec.rb +30 -0
  59. data/lib/zucker/2/spec/enumerable_spec.rb +8 -0
  60. data/lib/zucker/2/spec/hash2proc_spec.rb +12 -0
  61. data/lib/zucker/2/spec/hash_spec.rb +17 -0
  62. data/lib/zucker/2/spec/info_spec.rb +8 -0
  63. data/lib/zucker/2/spec/iterate_spec.rb +54 -0
  64. data/lib/zucker/2/spec/ivars_spec.rb +20 -0
  65. data/lib/zucker/2/spec/kernel_spec.rb +28 -0
  66. data/lib/zucker/2/spec/mcopy_spec.rb +13 -0
  67. data/lib/zucker/2/spec/mm_spec.rb +8 -0
  68. data/lib/zucker/2/spec/regexp2proc_spec.rb +9 -0
  69. data/lib/zucker/2/spec/sandbox_spec.rb +26 -0
  70. data/lib/zucker/2/spec/spec_helper.rb +18 -0
  71. data/lib/zucker/2/spec/square_brackets_for_spec.rb +59 -0
  72. data/lib/zucker/2/spec/string_spec.rb +29 -0
  73. data/lib/zucker/2/spec/unary_spec.rb +26 -0
  74. data/lib/zucker/2/spec/union_spec.rb +15 -0
  75. data/lib/zucker/2/square_brackets_for.rb +20 -0
  76. data/lib/zucker/2/string.rb +25 -0
  77. data/lib/zucker/2/unary.rb +22 -0
  78. data/lib/zucker/2/union.rb +14 -0
  79. data/lib/zucker/all.rb +2 -2
  80. data/lib/zucker/array2proc.rb +7 -1
  81. data/lib/zucker/debug.rb +3 -3
  82. data/lib/zucker/default.rb +1 -1
  83. data/lib/zucker/desc/D.yaml +1 -1
  84. data/lib/zucker/desc/array.yaml +1 -1
  85. data/lib/zucker/desc/array2proc.yaml +5 -1
  86. data/lib/zucker/desc/binding.yaml +2 -2
  87. data/lib/zucker/desc/blank.yaml +1 -3
  88. data/lib/zucker/desc/egonil.yaml +1 -1
  89. data/lib/zucker/desc/enumerable.yaml +1 -1
  90. data/lib/zucker/desc/hash.yaml +4 -2
  91. data/lib/zucker/desc/info.yaml +12 -0
  92. data/lib/zucker/desc/kernel.yaml +2 -2
  93. data/lib/zucker/desc/mm.yaml +3 -3
  94. data/lib/zucker/desc/regexp2proc.yaml +1 -1
  95. data/lib/zucker/desc/sandbox.yaml +6 -1
  96. data/lib/zucker/desc/string.yaml +1 -1
  97. data/lib/zucker/desc/unary.yaml +2 -2
  98. data/lib/zucker/desc/union.yaml +1 -1
  99. data/lib/zucker/doc/zucker_doc.html +441 -233
  100. data/lib/zucker/doc/zucker_doc.rb +32 -27
  101. data/lib/zucker/hash.rb +3 -3
  102. data/lib/zucker/info.rb +164 -0
  103. data/lib/zucker/ivars.rb +1 -1
  104. data/lib/zucker/kernel.rb +2 -4
  105. data/lib/zucker/sandbox.rb +7 -3
  106. data/lib/zucker/spec/D_spec.rb +15 -7
  107. data/lib/zucker/spec/aliases_spec.rb +3 -24
  108. data/lib/zucker/spec/array2proc_spec.rb +5 -1
  109. data/lib/zucker/spec/array_spec.rb +1 -1
  110. data/lib/zucker/spec/binding_spec.rb +4 -2
  111. data/lib/zucker/spec/blank_spec.rb +1 -1
  112. data/lib/zucker/spec/class2proc_spec.rb +1 -1
  113. data/lib/zucker/spec/egonil_spec.rb +1 -1
  114. data/lib/zucker/spec/enumerable_spec.rb +1 -1
  115. data/lib/zucker/spec/hash2proc_spec.rb +1 -1
  116. data/lib/zucker/spec/hash_spec.rb +10 -3
  117. data/lib/zucker/spec/info_spec.rb +8 -0
  118. data/lib/zucker/spec/iterate_spec.rb +1 -1
  119. data/lib/zucker/spec/ivars_spec.rb +1 -1
  120. data/lib/zucker/spec/kernel_spec.rb +1 -7
  121. data/lib/zucker/spec/mcopy_spec.rb +1 -1
  122. data/lib/zucker/spec/mm_spec.rb +4 -2
  123. data/lib/zucker/spec/regexp2proc_spec.rb +1 -1
  124. data/lib/zucker/spec/sandbox_spec.rb +22 -3
  125. data/lib/zucker/spec/spec_helper.rb +18 -0
  126. data/lib/zucker/spec/square_brackets_for_spec.rb +1 -1
  127. data/lib/zucker/spec/string_spec.rb +7 -7
  128. data/lib/zucker/spec/unary_spec.rb +1 -1
  129. data/lib/zucker/spec/union_spec.rb +8 -6
  130. metadata +207 -131
  131. data/lib/zucker/doc/meta.yaml +0 -4
@@ -1,8 +1,12 @@
1
1
  # Ruby 1.9, encoding: utf-8
2
+ # creates the documentation for Zucker
3
+
2
4
  require 'yaml'
3
5
  require 'coderay'
4
6
 
5
7
  class ZuckerDoc
8
+ PACKAGES = %w|default debug|
9
+ ORDER = %w|summary why methods info spec source versions|
6
10
  DESCRIPTIONS = {
7
11
  'summary' => 'Summary',
8
12
  'why' => 'Why?',
@@ -13,15 +17,15 @@ class ZuckerDoc
13
17
  'versions' => 'Compatibility',
14
18
  'authors' => 'Authors',
15
19
  }
16
- ORDER = %w|summary why methods info spec source versions|
17
20
 
18
21
  # template vars
19
- @version = 1
22
+ @version = 2
20
23
 
21
24
  class << self
22
- def generate
25
+ def generate(path = '../')
26
+ @path = path
23
27
 
24
- cubes = Dir['../desc/*'].inject({}) do |res, cube_file; a|
28
+ cubes = Dir[ File.join(path, 'desc', '*') ].inject({}) do |res, cube_file; a|
25
29
  a = YAML.load_file cube_file
26
30
  if a.instance_of? Hash
27
31
  res.merge a
@@ -30,13 +34,12 @@ class ZuckerDoc
30
34
  end
31
35
  end
32
36
 
33
- @meta = YAML.load_file 'meta.yaml'
37
+ output_path = File.join(path, 'doc', 'zucker_doc.html')
34
38
 
35
- output = 'zucker_doc.html'
36
39
  result = DATA.read
37
40
 
38
- cubes_html = cubes.sort.map{ |name, hash|
39
- cube name, hash
41
+ cubes_html = PACKAGES.map{ |pkg_name|
42
+ package pkg_name, cubes.select{|name, hash| hash['package'] == pkg_name }
40
43
  }.join
41
44
 
42
45
  # insert cubes
@@ -47,16 +50,28 @@ class ZuckerDoc
47
50
  result.gsub! /⇧(.+?)⇧/, '<code>\1</code>'
48
51
  # strong
49
52
  result.gsub! /●(.+?)●/, '<strong>\1</strong>'
50
- # hyper!links
53
+ # hyperlinks
51
54
  result.gsub! /→(.+?)→(.+?)→/, '<a href="\2">\1</a>'
52
55
 
53
- File.open output, 'w' do |file|
56
+ File.open output_path, 'w' do |file|
54
57
  file.puts result
55
58
  end
56
59
  end
57
60
 
58
61
  protected
59
62
 
63
+ def package(name, cubes)
64
+ cube_html = cubes.sort.map{ |name, hash|
65
+ cube name, hash
66
+ }.join
67
+
68
+ %{
69
+ <h2 title="require 'zucker/#{name}'">Cubes[#{name}]</h2>
70
+ <div class="cubes">
71
+ #{cube_html}
72
+ </div> }
73
+ end
74
+
60
75
  def cube(name, hash)
61
76
  @cube_name = name
62
77
  %{ <h3 title="require 'zucker/#{name}'">#{ name }</h3>
@@ -110,17 +125,17 @@ class ZuckerDoc
110
125
  end
111
126
 
112
127
  def spec(s)
113
- source_helper(:spec, '../spec/', '_spec')
128
+ source_helper(:spec, File.join( @path, 'spec/' ), '_spec')
114
129
  end
115
130
 
116
131
  def source(s)
117
- source_helper(:source, '../')
132
+ source_helper(:source, @path)
118
133
  end
119
134
 
120
135
  def source_helper(kind, file_prefix, suffix='')
121
136
  %{ <span id="show_#{@cube_name}_#{kind}">(<a href="javascript:show('#{@cube_name}_#{kind}')">show</a>)</span>
122
137
  <pre class="source" id="#{@cube_name}_#{kind}">#{
123
- get_source_file( file_prefix + @cube_name + suffix + '.rb' )
138
+ get_source_file( File.join file_prefix, ( @cube_name + suffix + '.rb' ) )
124
139
  }</pre> }
125
140
  end
126
141
 
@@ -149,7 +164,7 @@ class ZuckerDoc
149
164
  end
150
165
  end
151
166
 
152
- ZuckerDoc.generate
167
+ ZuckerDoc.generate *ARGV
153
168
 
154
169
  __END__
155
170
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@@ -288,19 +303,12 @@ code, pre{
288
303
 
289
304
  .source{
290
305
  display:none;
291
- border:1px solid #005;
292
- # background:#111;
293
306
  width:98%;
294
-
295
- # background-color: #232323;
296
- # border: 1px solid black;
297
- # font-family: 'Courier New', 'Terminal', monospace;
298
- # color: #E6E0DB;
299
307
  padding: 3px 5px;
300
- # margin-right:1em;
301
308
  overflow: auto;
302
309
  font-size: 12px;
303
310
  background-color: #f8f8f8;
311
+ border:1px solid #005;
304
312
  border: 1px solid silver;
305
313
  font-family: 'Courier New', 'Terminal', monospace;
306
314
  color: #000;
@@ -454,7 +462,7 @@ table.source td { padding: 2px 4px; vertical-align: top; }
454
462
 
455
463
  <h1>Ruby Zucker ..version..</h1>
456
464
  <h2>What is it?</h2>
457
- <p class="text">Zucker is the German word for sugar (<a href="http://www.forvo.com/word/zucker/">pronunciation</a>). This gem adds syntactical sugar in the form of independent, lightweight scripts that make Ruby even more sweet. Read <a href="http://rbjl.net/32-introducing-ruby-zucker-a-new-syntactical-sugar-gem">this blog post</a> for a little introduction.</p>
465
+ <p class="text">Zucker is the German word for sugar (<a href="http://www.forvo.com/word/zucker/">pronunciation</a>). It adds syntactical sugar in the form of independent, small scripts that make Ruby even more sweet. Read <a href="http://rbjl.net/32-introducing-ruby-zucker-a-new-syntactical-sugar-gem">this blog post</a> for a little introduction.</p>
458
466
 
459
467
  <h2>Install</h2>
460
468
  <p class="text">
@@ -475,10 +483,7 @@ table.source td { padding: 2px 4px; vertical-align: top; }
475
483
  <p class="text">You can also lock your require to a specific version of Zucker by simply putting the version before the cube name in this way:
476
484
  <code>require 'zucker/1/egonil'</code>. Future releases of the gem will include all previous (main) versions, so the behaviour of these directly required cubes will not change (except for critical bugs).</p>
477
485
 
478
- <h2 title="require 'zucker/all'">Cubes</h2>
479
- <div class="cubes">
480
- ....
481
- </div>
486
+ ....
482
487
  <br/>
483
488
  </div>
484
489
  <div id="foot">
@@ -1,16 +1,16 @@
1
1
  class Hash
2
2
  def self.zip(keys,values)
3
- Hash[ *[1,2,3].zip( [4,5,6] ).flatten ]
3
+ Hash[ *keys.zip( values ).flatten ]
4
4
  end
5
5
 
6
6
  def <<(other)
7
7
  case
8
8
  when other.is_a?(Hash)
9
9
  merge! other
10
- when other.respond_to?(:to_splat)
10
+ when other.is_a?(Enumerable) || other.respond_to?(:to_splat)
11
11
  merge! Hash[*other]
12
12
  else
13
- raise TypeError, 'can only append other Hashs and Enumerables'
13
+ raise TypeError, 'can only append other Hashs and Enumerables (or Classes that implement to_splat)'
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,164 @@
1
+ module Info
2
+ class << Info
3
+ # hash like access
4
+ def [](what)
5
+ send what
6
+ end
7
+
8
+ # TODO: maybe add a descriptions method
9
+ end
10
+
11
+ module_function
12
+
13
+ # current script file
14
+ def current_file
15
+ __FILE__
16
+ end
17
+
18
+ def current_file_directory
19
+ File.dirname(__FILE__)
20
+ end
21
+
22
+ # input
23
+ def last_input_file
24
+ $FILENAME
25
+ end
26
+
27
+ def last_input_line_number
28
+ $.
29
+ end
30
+
31
+ def last_input
32
+ $_
33
+ end
34
+
35
+ # program
36
+ def program_name
37
+ $0
38
+ end
39
+
40
+ def program_arguments
41
+ $:
42
+ end
43
+
44
+ def loaded_programs
45
+ $"
46
+ end
47
+
48
+ def program_data
49
+ ::DATA
50
+ end
51
+
52
+ def child_program_status
53
+ $CHILD_STATUS
54
+ end
55
+
56
+ # system info
57
+ def environment
58
+ ::ENV
59
+ end
60
+ alias env environment
61
+
62
+ def working_directory
63
+ Dir.pwd
64
+ end
65
+
66
+ def platform
67
+ ::RUBY_PLATFORM
68
+ end
69
+
70
+ def process_id
71
+ $$
72
+ end
73
+
74
+ def load_path
75
+ $:
76
+ end
77
+
78
+ # current
79
+ def current_line
80
+ __LINE__
81
+ end
82
+
83
+ def current_method # 1.9
84
+ __method__
85
+ end
86
+
87
+ def current_callstack
88
+ caller
89
+ end
90
+
91
+ # dealing with strings
92
+ def gets_separator
93
+ $/
94
+ end
95
+
96
+ def join_separator
97
+ $,
98
+ end
99
+
100
+ def print_separator
101
+ $,
102
+ end
103
+
104
+ def split_separator
105
+ $;
106
+ end
107
+
108
+ # misc
109
+ def security_level
110
+ $SAFE
111
+ end
112
+
113
+ def warnings_activated?
114
+ $VERBOSE
115
+ end
116
+
117
+ def debug_activated?
118
+ $DEBUG
119
+ end
120
+
121
+ def last_exception
122
+ $!
123
+ end
124
+
125
+ # defined objects
126
+ def global_variables
127
+ global_variables
128
+ end
129
+
130
+ def global_constants
131
+ Object.constants
132
+ end
133
+
134
+ # encoding (1.9)
135
+ def source_encoding
136
+ __ENCODING__
137
+ end
138
+
139
+ def external_encoding
140
+ Encoding.default_external
141
+ end
142
+
143
+ def internal_encoding
144
+ Encoding.default_internal
145
+ end
146
+
147
+ # ruby version info
148
+ def ruby_version
149
+ ::RUBY_VERSION
150
+ end
151
+
152
+ def ruby_patchlevel
153
+ ::RUBY_PATCHLEVEL
154
+ end
155
+
156
+ def ruby_description
157
+ ::RUBY_DESCRIPTION
158
+ end
159
+
160
+ def ruby_release_date
161
+ ::RUBY_RELEASE_DATE
162
+ end
163
+ end
164
+
@@ -1,7 +1,7 @@
1
1
  def instance_variables_from(obj, *only)
2
2
  iter =
3
3
  if obj.is_a? Binding
4
- obj.eval('local_variables').map{|e| [obj.eval(e), e] }
4
+ obj.eval('local_variables').map{|e| [obj.eval("#{e}"), e] }
5
5
  elsif obj.is_a? Hash
6
6
  obj.map{|k,v| [v,k] }
7
7
  else
@@ -6,10 +6,6 @@ def deactivate_warnings!
6
6
  $VERBOSE = false
7
7
  end
8
8
 
9
- def warnings_activated?
10
- $VERBOSE
11
- end
12
-
13
9
  def library?
14
10
  __FILE__ != $PROGRAM_NAME
15
11
  end
@@ -18,3 +14,5 @@ def ignore_sigint! # ctrl+c
18
14
  Signal.trap *%w|SIGINT IGNORE|
19
15
  end
20
16
 
17
+ # J-_-L
18
+
@@ -1,11 +1,15 @@
1
- def sandbox(rescueblock=nil)
1
+ def sandbox(rescueblock_or_default=nil)
2
2
  Thread.start do
3
3
  $SAFE = 4
4
4
  yield
5
5
  end.value
6
6
  rescue SecurityError => e
7
- if rescueblock
8
- rescueblock.call e
7
+ if !rescueblock_or_default.nil?
8
+ if rescueblock_or_default.is_a? Proc
9
+ rescueblock_or_default.call e
10
+ else
11
+ rescueblock_or_default
12
+ end
9
13
  else
10
14
  raise e
11
15
  end
@@ -1,4 +1,4 @@
1
- require 'D'
1
+ require 'zucker/D'
2
2
 
3
3
  describe 'Object#D' do
4
4
 
@@ -10,18 +10,26 @@ describe 'Object#D' do
10
10
  a.each{ |e|
11
11
  (e.D).should == e
12
12
  }
13
+
14
+ a.each{ |e|
15
+ (e.D{|value| "This is a: #{value}"}).should == e
16
+ }
13
17
  end
14
18
 
15
19
  it "should puts .inspect if no block is given (and not change the object's value)" do
16
- # a.each{ |e|
17
- # (e.D).should == e
18
- # }
20
+ capture_stdout do
21
+ a[0].D
22
+ a[1].D
23
+ a[6].D
24
+ end.should == %{1\n"1"\ntrue\n}
19
25
  end
20
26
 
21
27
  it "should puts the block if it is given (and not change the object's value)" do
22
- a.each{ |e|
23
- (e.D{|value| "This is a: #{value}"}).should == e
24
- }
28
+ capture_stdout do
29
+ a[0].D{|value| "This is a: #{value}"}
30
+ a[1].D{|value| "This is a: #{value}"}
31
+ a[6].D{|value| "This is a: #{value}"}
32
+ end.should == %{This is a: 1\nThis is a: 1\nThis is a: true\n}
25
33
  end
26
34
  end
27
35
 
@@ -1,29 +1,8 @@
1
- require 'aliases'
1
+ require 'zucker/aliases'
2
2
 
3
3
  describe '(aliases)' do
4
- it 'should create these aliases [ sorry, no real spec for this one :P ] ' do
5
- # alias is_an? is_a?
6
-
7
- # module Enumerable
8
- # alias with zip
9
- # alias % zip
10
- # end
11
-
12
- # class Array
13
- # alias ** product
14
- # end
15
-
16
- # class Hash
17
- # alias + merge
18
- # end
19
-
20
- # class Binding
21
- # #alias [] eval
22
- # def [](expr)
23
- # self.eval "#{expr}"
24
- # end
25
- # end
26
-
4
+ it 'should create these aliases' do
5
+ # see aliases.rb for aliase list
27
6
  end
28
7
 
29
8
  it 'should define these constants' do