opal 0.3.20 → 0.3.21

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 (122) hide show
  1. data/.gitignore +2 -7
  2. data/.rspec +2 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +8 -2
  5. data/LICENSE +2 -3
  6. data/README.md +106 -239
  7. data/Rakefile +58 -16
  8. data/bin/opal +1 -0
  9. data/core/array.rb +180 -160
  10. data/core/basic_object.rb +8 -4
  11. data/core/boolean.rb +6 -6
  12. data/core/class.rb +9 -15
  13. data/core/dir.rb +89 -0
  14. data/core/enumerable.rb +83 -86
  15. data/core/error.rb +9 -4
  16. data/core/file.rb +85 -0
  17. data/core/hash.rb +67 -67
  18. data/core/kernel.rb +38 -42
  19. data/core/module.rb +57 -54
  20. data/core/numeric.rb +41 -41
  21. data/core/proc.rb +1 -5
  22. data/core/range.rb +11 -11
  23. data/core/regexp.rb +27 -22
  24. data/core/runtime.js +152 -221
  25. data/core/string.rb +86 -73
  26. data/core/time.rb +22 -18
  27. data/docs/post.html +9 -0
  28. data/docs/pre.html +32 -0
  29. data/lib/opal.rb +43 -3
  30. data/lib/opal/builder.rb +9 -26
  31. data/lib/opal/grammar.rb +1 -1
  32. data/lib/opal/grammar.y +1 -1
  33. data/lib/opal/lexer.rb +21 -15
  34. data/lib/opal/parser.rb +100 -111
  35. data/lib/opal/rake_task.rb +66 -0
  36. data/lib/opal/scope.rb +13 -5
  37. data/lib/opal/version.rb +1 -1
  38. data/opal.gemspec +2 -0
  39. data/spec/browser_spec.rb +28 -0
  40. data/spec/builder/lib_name_for_spec.rb +1 -6
  41. data/spec/grammar/alias_spec.rb +1 -1
  42. data/spec/grammar/and_spec.rb +1 -1
  43. data/spec/grammar/array_spec.rb +1 -1
  44. data/spec/grammar/attrasgn_spec.rb +1 -1
  45. data/spec/grammar/begin_spec.rb +1 -1
  46. data/spec/grammar/block_spec.rb +1 -1
  47. data/spec/grammar/break_spec.rb +1 -1
  48. data/spec/grammar/call_spec.rb +1 -1
  49. data/spec/grammar/class_spec.rb +1 -1
  50. data/spec/grammar/const_spec.rb +1 -1
  51. data/spec/grammar/cvar_spec.rb +1 -1
  52. data/spec/grammar/def_spec.rb +1 -1
  53. data/spec/grammar/false_spec.rb +1 -1
  54. data/spec/grammar/file_spec.rb +1 -1
  55. data/spec/grammar/gvar_spec.rb +1 -1
  56. data/spec/grammar/hash_spec.rb +1 -1
  57. data/spec/grammar/iasgn_spec.rb +1 -1
  58. data/spec/grammar/if_spec.rb +1 -1
  59. data/spec/grammar/iter_spec.rb +1 -1
  60. data/spec/grammar/ivar_spec.rb +1 -1
  61. data/spec/grammar/lambda_spec.rb +1 -1
  62. data/spec/grammar/lasgn_spec.rb +1 -1
  63. data/spec/grammar/line_spec.rb +1 -1
  64. data/spec/grammar/lvar_spec.rb +1 -1
  65. data/spec/grammar/masgn_spec.rb +1 -1
  66. data/spec/grammar/module_spec.rb +1 -1
  67. data/spec/grammar/nil_spec.rb +1 -1
  68. data/spec/grammar/not_spec.rb +1 -1
  69. data/spec/grammar/op_asgn1_spec.rb +1 -1
  70. data/spec/grammar/op_asgn2_spec.rb +1 -1
  71. data/spec/grammar/or_spec.rb +1 -1
  72. data/spec/grammar/return_spec.rb +1 -1
  73. data/spec/grammar/sclass_spec.rb +1 -1
  74. data/spec/grammar/self_spec.rb +1 -1
  75. data/spec/grammar/str_spec.rb +1 -1
  76. data/spec/grammar/super_spec.rb +1 -1
  77. data/spec/grammar/true_spec.rb +1 -1
  78. data/spec/grammar/undef_spec.rb +1 -1
  79. data/spec/grammar/unless_spec.rb +1 -1
  80. data/spec/grammar/while_spec.rb +1 -1
  81. data/spec/grammar/xstr_spec.rb +1 -1
  82. data/spec/grammar/yield_spec.rb +1 -1
  83. data/spec/spec_helper.rb +6 -1
  84. data/test/core/array/minus_spec.rb +13 -0
  85. data/test/core/enumerable/drop_while_spec.rb +0 -5
  86. data/test/core/range/case_compare_spec.rb +0 -1
  87. data/test/index.html +1 -1
  88. data/test/index.min.html +12 -0
  89. data/test/language/alias_spec.rb +0 -4
  90. data/test/language/fixtures/next.rb +62 -0
  91. data/test/language/metaclass_spec.rb +4 -4
  92. data/test/language/next_spec.rb +0 -63
  93. data/test/language/send_spec.rb +0 -5
  94. data/test/language/singleton_class_spec.rb +4 -0
  95. data/test/opal/array/subclassing_spec.rb +1 -1
  96. data/test/opal/class/bridge_class_spec.rb +2 -2
  97. data/test/opal/runtime/class_hierarchy_spec.rb +1 -2
  98. data/test/opal/runtime/method_missing_spec.rb +17 -0
  99. data/test/spec_helper.rb +4 -1
  100. metadata +32 -28
  101. data/docs/CNAME +0 -1
  102. data/docs/Rakefile +0 -55
  103. data/docs/css/styles.css +0 -50
  104. data/docs/css/syntax.css +0 -63
  105. data/docs/layout/post.html +0 -3
  106. data/docs/layout/pre.html +0 -11
  107. data/examples/dependencies/.gitignore +0 -1
  108. data/examples/dependencies/Gemfile +0 -6
  109. data/examples/dependencies/README.md +0 -41
  110. data/examples/dependencies/Rakefile +0 -10
  111. data/examples/dependencies/app.rb +0 -19
  112. data/examples/dependencies/build/.gitkeep +0 -0
  113. data/examples/dependencies/index.html +0 -13
  114. data/examples/hello_world/.gitignore +0 -1
  115. data/examples/hello_world/Gemfile +0 -3
  116. data/examples/hello_world/README.md +0 -27
  117. data/examples/hello_world/Rakefile +0 -23
  118. data/examples/hello_world/app.rb +0 -7
  119. data/examples/hello_world/index.html +0 -12
  120. data/lib/opal/builder_task.rb +0 -91
  121. data/spec/builder/build_order_spec.rb +0 -20
  122. data/test/opal/runtime/_methods_spec.rb +0 -48
data/docs/CNAME DELETED
@@ -1 +0,0 @@
1
- opalrb.org
@@ -1,55 +0,0 @@
1
- desc "Clone repo"
2
- task :clone do
3
- if File.exists? 'gh-pages'
4
- Dir.chdir('gh-pages') { sh 'git pull origin gh-pages' }
5
- else
6
- FileUtils.mkdir_p 'gh-pages'
7
- Dir.chdir('gh-pages') do
8
- sh 'git clone git@github.com:/adambeynon/opal.git .'
9
- sh 'git checkout gh-pages'
10
- end
11
- end
12
- end
13
-
14
- desc "Copy files"
15
- task :build do
16
- files = {
17
- '../build/opal.js' => 'gh-pages/opal.js',
18
- 'CNAME' => 'gh-pages/CNAME',
19
- 'css/styles.css' => 'gh-pages/css/styles.css',
20
- 'css/syntax.css' => 'gh-pages/css/syntax.css'
21
- }
22
-
23
- files.each do |src, dest|
24
- puts dest
25
- FileUtils.mkdir_p File.dirname(dest)
26
- FileUtils.cp src, dest
27
- end
28
-
29
- require 'redcarpet'
30
- require 'albino'
31
-
32
- klass = Class.new(Redcarpet::Render::HTML) do
33
- def block_code(code, language)
34
- Albino.new(code, language || :text).colorize
35
- end
36
- end
37
-
38
- puts 'gh-pages/index.html'
39
- markdown = Redcarpet::Markdown.new(klass, :fenced_code_blocks => true)
40
-
41
- File.open('gh-pages/index.html', 'w+') do |o|
42
- o.write File.read('layout/pre.html')
43
- o.write markdown.render(File.read "../README.md")
44
- o.write File.read('layout/post.html')
45
- end
46
- end
47
-
48
- desc "commit and push"
49
- task :push do
50
- Dir.chdir('gh-pages') do
51
- sh "git add ."
52
- sh "git commit -a -m \"Documentation update #{Time.new}\""
53
- sh "git push origin gh-pages"
54
- end
55
- end
@@ -1,50 +0,0 @@
1
- body {
2
- line-height: 22px;
3
- font-size: 14px;
4
- font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
5
- }
6
-
7
- .content {
8
- padding: 50px 50px 50px 50px;
9
- width: 650px;
10
- }
11
-
12
- p {
13
- width: 650px;
14
- }
15
-
16
- pre, code {
17
- font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
18
- font-size: 12px;
19
- }
20
-
21
- pre {
22
- line-height: 17px;
23
- color: #444444;
24
- white-space: pre;
25
- padding: 3px 0px 3px 12px;
26
- margin: 0px 0px 8px;
27
-
28
- background: #FAFAFA;
29
- -webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
30
- -webkit-border-radius: 3px;
31
- -moz-border-radius: 3px;
32
- border-radius: 3px;
33
- border: 1px solid #DDDDDD;
34
- }
35
-
36
- code {
37
- background-color: #FAFAFA;
38
- padding: 1px;
39
- color: #444444;
40
- border: 1px solid #DEDEDE;
41
- }
42
-
43
- pre code {
44
- border: none;
45
- padding: 0px;
46
- }
47
-
48
- a {
49
- color: #212121;
50
- }
@@ -1,63 +0,0 @@
1
- /* syntax.css for pygments */
2
- /* from http://github.com/mojombo/tpw/blob/master/css/syntax.css */
3
-
4
- .highlight { background: #ffffff; }
5
- .highlight .c { color: #999988; font-style: italic } /* Comment */
6
- .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
7
- .highlight .k { font-weight: bold } /* Keyword */
8
- .highlight .o { font-weight: bold } /* Operator */
9
- .highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
10
- .highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
11
- .highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
12
- .highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
13
- .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
14
- .highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
15
- .highlight .ge { font-style: italic } /* Generic.Emph */
16
- .highlight .gr { color: #aa0000 } /* Generic.Error */
17
- .highlight .gh { color: #999999 } /* Generic.Heading */
18
- .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
19
- .highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
20
- .highlight .go { color: #888888 } /* Generic.Output */
21
- .highlight .gp { color: #555555 } /* Generic.Prompt */
22
- .highlight .gs { font-weight: bold } /* Generic.Strong */
23
- .highlight .gu { color: #aaaaaa } /* Generic.Subheading */
24
- .highlight .gt { color: #aa0000 } /* Generic.Traceback */
25
- .highlight .kc { font-weight: bold } /* Keyword.Constant */
26
- .highlight .kd { font-weight: bold } /* Keyword.Declaration */
27
- .highlight .kp { font-weight: bold } /* Keyword.Pseudo */
28
- .highlight .kr { font-weight: bold } /* Keyword.Reserved */
29
- .highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
30
- .highlight .m { color: #009999 } /* Literal.Number */
31
- .highlight .s { color: #d14 } /* Literal.String */
32
- .highlight .na { color: #008080 } /* Name.Attribute */
33
- .highlight .nb { color: #0086B3 } /* Name.Builtin */
34
- .highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
35
- .highlight .no { color: #008080 } /* Name.Constant */
36
- .highlight .ni { color: #800080 } /* Name.Entity */
37
- .highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
38
- .highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
39
- .highlight .nn { color: #555555 } /* Name.Namespace */
40
- .highlight .nt { color: #000080 } /* Name.Tag */
41
- .highlight .nv { color: #008080 } /* Name.Variable */
42
- .highlight .ow { font-weight: bold } /* Operator.Word */
43
- .highlight .w { color: #bbbbbb } /* Text.Whitespace */
44
- .highlight .mf { color: #009999 } /* Literal.Number.Float */
45
- .highlight .mh { color: #009999 } /* Literal.Number.Hex */
46
- .highlight .mi { color: #009999 } /* Literal.Number.Integer */
47
- .highlight .mo { color: #009999 } /* Literal.Number.Oct */
48
- .highlight .sb { color: #d14 } /* Literal.String.Backtick */
49
- .highlight .sc { color: #d14 } /* Literal.String.Char */
50
- .highlight .sd { color: #d14 } /* Literal.String.Doc */
51
- .highlight .s2 { color: #d14 } /* Literal.String.Double */
52
- .highlight .se { color: #d14 } /* Literal.String.Escape */
53
- .highlight .sh { color: #d14 } /* Literal.String.Heredoc */
54
- .highlight .si { color: #d14 } /* Literal.String.Interpol */
55
- .highlight .sx { color: #d14 } /* Literal.String.Other */
56
- .highlight .sr { color: #009926 } /* Literal.String.Regex */
57
- .highlight .s1 { color: #d14 } /* Literal.String.Single */
58
- .highlight .ss { color: #990073 } /* Literal.String.Symbol */
59
- .highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
60
- .highlight .vc { color: #008080 } /* Name.Variable.Class */
61
- .highlight .vg { color: #008080 } /* Name.Variable.Global */
62
- .highlight .vi { color: #008080 } /* Name.Variable.Instance */
63
- .highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
@@ -1,3 +0,0 @@
1
- </div>
2
- </body>
3
- </html>
@@ -1,11 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
-
6
- <title>Opal</title>
7
- <link rel="stylesheet" href="css/syntax.css" type="text/css">
8
- <link rel="stylesheet" href="css/styles.css" type="text/css">
9
- </head>
10
- <body>
11
- <div class="content">
@@ -1 +0,0 @@
1
- build/*.js
@@ -1,6 +0,0 @@
1
- source :rubygems
2
-
3
- gem "opal"
4
-
5
- # dependencies used in opal app
6
- gem "opal-json"
@@ -1,41 +0,0 @@
1
- # Opal Dependency Example
2
-
3
- This example shows how easy it is to use gem dependencies with opal to
4
- easily maintain app dependencies.
5
-
6
- Dependencies in opal are referenced from the rake task, and they must
7
- be installed as system gems, or through bundler.
8
-
9
- ## Setting up
10
-
11
- To ensure the required gems are installed, just run bundler:
12
-
13
- ```
14
- bundle install
15
- ```
16
-
17
- ## Building dependencies
18
-
19
- To build the gem dependency (`opal-json`), as well as the opal runtime
20
- `opal.js`, just use the simple rake task:
21
-
22
- ```
23
- rake dependencies
24
- ```
25
-
26
- This will build the two files into `./build`.
27
-
28
- ## Building the app
29
-
30
- Again, a simple rake task is available:
31
-
32
- ```
33
- rake build
34
- ```
35
-
36
- Which will build `./build/my-app.js` ready for use.
37
-
38
- ## Running application
39
-
40
- Simply open `index.html` and observe the parsed json string as a ruby
41
- hash instance.
@@ -1,10 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'opal'
5
-
6
- Opal::BuilderTask.new do |t|
7
- t.name = 'my-app'
8
- t.files = ['app.rb']
9
- t.dependencies = %w[opal-json]
10
- end
@@ -1,19 +0,0 @@
1
- # need to require dependencies first
2
- require 'json'
3
-
4
- # alert() doesnt exist without rquery or opal-browser
5
- def alert(msg)
6
- `window.alert(msg)`
7
- end
8
-
9
- json = <<-JSON
10
- {
11
- "adam": null,
12
- "fred": [1, 2, 3],
13
- "bill": false
14
- }
15
- JSON
16
-
17
- hash = JSON.parse json
18
-
19
- alert hash.inspect
File without changes
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>Opal Dependency App</title>
5
-
6
- <script src="build/opal.js"></script>
7
- <script src="build/opal-json.js"></script>
8
- <script src="build/my-app.js"></script>
9
- </head>
10
- <body>
11
-
12
- </body>
13
- </html>
@@ -1 +0,0 @@
1
- *.js
@@ -1,3 +0,0 @@
1
- source :rubygems
2
-
3
- gem "opal"
@@ -1,27 +0,0 @@
1
- # Hello World Example App
2
-
3
- This is a very basic example Opal App. To get this running, firstly
4
- install the dependencies (which is just opal):
5
-
6
- ```
7
- bundle install
8
- ```
9
-
10
- Next we need the opal runtime. You can either download it from
11
- [http://opalrb.org/opal.js](http://opalrb.org/opal.js), or use
12
- the handy rake task:
13
-
14
- ```
15
- rake runtime
16
- ```
17
-
18
- This builds `opal.js`.
19
-
20
- Finally, to build the `app.rb` file, run the simple rake task:
21
-
22
- ```
23
- rake build
24
- ```
25
-
26
- Which builds the app into `app.js`. Open `index.html` and observe the
27
- alert dialog.
@@ -1,23 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'opal'
5
-
6
- desc "Build app"
7
- task :build do
8
- src = File.read 'app.rb'
9
- js = Opal.parse src
10
-
11
- File.open('app.js', 'w+') do |out|
12
- out.write js
13
- end
14
- end
15
-
16
- desc "Make sure opal.js exists"
17
- task :runtime do
18
- unless File.exist? 'opal.js'
19
- File.open('opal.js', 'w+') do |out|
20
- out.write Opal.runtime
21
- end
22
- end
23
- end
@@ -1,7 +0,0 @@
1
- # Without rquery or opal-browser, opal doesn't know about the browser
2
- def alert(msg)
3
- `window.alert(msg)`
4
- end
5
-
6
- # Alert a simple message
7
- alert "Hello World!"
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>First Opal App</title>
5
-
6
- <script src="opal.js"></script>
7
- <script src="app.js"></script>
8
- </head>
9
- <body>
10
-
11
- </body>
12
- </html>
@@ -1,91 +0,0 @@
1
- require 'opal/builder'
2
-
3
- module Opal
4
- class BuilderTask
5
- include Rake::DSL if defined? Rake::DSL
6
-
7
- attr_accessor :name, :build_dir, :specs_dir, :files, :dependencies
8
-
9
- def initialize(namespace = nil)
10
- @project_dir = Dir.getwd
11
-
12
- @name = 'app'
13
- @build_dir = 'build'
14
- @specs_dir = 'spec'
15
- @files = Dir['lib/**/*.{rb,js}']
16
- @dependencies = []
17
- @debug_mode = false
18
-
19
- yield self if block_given?
20
-
21
- define_tasks
22
- end
23
-
24
- def to_config
25
- {
26
- :name => @name,
27
- :build_dir => @build_dir,
28
- :specs_dir => @specs_dir,
29
- :files => @files,
30
- :dependencies => @dependencies
31
- }
32
- end
33
-
34
- def build_gem(name, debug)
35
- spec = Gem::Specification.find_by_name name
36
- out = File.join @build_dir, "#{name}#{debug ? '.debug' : ''}.js"
37
- build_files :files => spec.require_paths,
38
- :out => out,
39
- :debug => debug,
40
- :dir => spec.full_gem_path
41
- rescue Gem::LoadError => e
42
- puts " - Error: Could not find gem #{name}"
43
- end
44
-
45
- def build_files(opts)
46
- puts " * #{opts[:out]}"
47
- Builder.build opts
48
- end
49
-
50
- def define_tasks
51
- define_task :build, "Build Opal Project" do
52
- name = @debug_mode ? "#@name.debug.js" : "#@name.js"
53
- build_files :files => @files,
54
- :out => File.join(@build_dir, "#@name.js")
55
- end
56
-
57
- define_task :spec, "Build Specs" do
58
- name = @debug_mode ? "#@name.specs.debug.js" : "#@name.specs.js"
59
- build_files :files => @specs_dir,
60
- :out => File.join(@build_dir, name),
61
- :debug => @debug_mode
62
- end
63
-
64
- define_task :dependencies, "Build dependencies" do
65
- out = File.join @build_dir, 'opal.js'
66
- puts " * #{out}"
67
- File.open(out, 'w+') do |out|
68
- out.write Opal.runtime
69
- end
70
-
71
- @dependencies.each { |dep| build_gem dep, @debug_mode }
72
- end
73
-
74
- define_task :debug, "Build debug mode" do
75
- @debug_mode = true
76
- Rake::Task[:build].invoke
77
- Rake::Task[:dependencies].invoke
78
- Rake::Task[:spec].invoke
79
- end
80
-
81
- define_task :config, "Show Build Config" do
82
- to_config.each { |key, val| puts "#{key}: #{val.inspect}" }
83
- end
84
- end
85
-
86
- def define_task(name, desc, &block)
87
- desc desc
88
- task name, &block
89
- end
90
- end
91
- end