opal 0.3.33 → 0.3.34

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 (49) hide show
  1. data/.travis.yml +1 -1
  2. data/Gemfile +6 -1
  3. data/README.md +7 -7
  4. data/Rakefile +29 -31
  5. data/bin/opal +1 -1
  6. data/{core/parser/browser.js → lib/assets/javascripts/opal-parser.js.erb} +9 -1
  7. data/lib/assets/javascripts/opal.js.erb +321 -0
  8. data/{core → lib/assets/javascripts/opal}/alpha.rb +0 -0
  9. data/{core → lib/assets/javascripts/opal}/array.rb +14 -1
  10. data/{core → lib/assets/javascripts/opal}/basic_object.rb +0 -0
  11. data/{core → lib/assets/javascripts/opal}/boolean.rb +0 -0
  12. data/{core → lib/assets/javascripts/opal}/class.rb +3 -3
  13. data/{core → lib/assets/javascripts/opal}/comparable.rb +0 -0
  14. data/lib/assets/javascripts/opal/core.js +18 -0
  15. data/lib/assets/javascripts/opal/date.rb +156 -0
  16. data/{core → lib/assets/javascripts/opal}/enumerable.rb +0 -0
  17. data/{core → lib/assets/javascripts/opal}/error.rb +0 -0
  18. data/{core → lib/assets/javascripts/opal}/hash.rb +0 -0
  19. data/{core → lib/assets/javascripts/opal}/json.rb +1 -1
  20. data/{core → lib/assets/javascripts/opal}/kernel.rb +2 -2
  21. data/{core → lib/assets/javascripts/opal}/nil_class.rb +0 -0
  22. data/{core → lib/assets/javascripts/opal}/numeric.rb +0 -0
  23. data/{core → lib/assets/javascripts/opal}/proc.rb +0 -0
  24. data/{core/parser → lib/assets/javascripts/opal}/racc.rb +0 -0
  25. data/{core → lib/assets/javascripts/opal}/range.rb +0 -0
  26. data/{core → lib/assets/javascripts/opal}/regexp.rb +0 -0
  27. data/{core → lib/assets/javascripts/opal}/string.rb +0 -0
  28. data/{core/parser → lib/assets/javascripts/opal}/strscan.rb +0 -0
  29. data/{core → lib/assets/javascripts/opal}/time.rb +0 -0
  30. data/lib/opal.rb +25 -58
  31. data/lib/opal/lexer.rb +1 -1
  32. data/lib/opal/parser.rb +1 -1
  33. data/lib/opal/processor.rb +26 -0
  34. data/lib/opal/version.rb +1 -1
  35. data/opal.gemspec +1 -1
  36. data/spec/core/array/shuffle_spec.rb +11 -0
  37. data/spec/index.html +4 -6
  38. data/spec/spec_helper.rb +3 -1
  39. metadata +29 -35
  40. data/core/date.rb +0 -34
  41. data/core/erb.rb +0 -20
  42. data/core/load_order +0 -20
  43. data/core/runtime.js +0 -305
  44. data/core/test_runner/runner.js +0 -37
  45. data/lib/opal/builder.rb +0 -88
  46. data/lib/opal/erb.rb +0 -14
  47. data/lib/opal/rake_task.rb +0 -80
  48. data/spec/parser/erb_spec.rb +0 -32
  49. data/spec/test_case.html +0 -13
@@ -1,37 +0,0 @@
1
- var args = phantom.args;
2
- var page = require('webpage').create();
3
-
4
- page.onConsoleMessage = function(msg) {
5
- console.log(msg);
6
- };
7
-
8
- page.onInitialized = function() {
9
- page.evaluate(function () {
10
- window.OPAL_SPEC_PHANTOM = true;
11
- });
12
- };
13
-
14
- page.open(args[0], function(status) {
15
- if (status !== 'success') {
16
- console.error("Cannot load: " + args[0]);
17
- phantom.exit(1);
18
- } else {
19
- var timeout = parseInt(args[1] || 60000, 10);
20
- var start = Date.now();
21
- var interval = setInterval(function() {
22
- if (Date.now() > start + timeout) {
23
- console.error("Specs timed out");
24
- phantom.exit(124);
25
- } else {
26
- var code = page.evaluate(function() {
27
- return window.OPAL_SPEC_CODE;
28
- });
29
-
30
- if (code === 0 || code === 1) {
31
- clearInterval(interval);
32
- phantom.exit(code);
33
- }
34
- }
35
- }, 500);
36
- }
37
- });
data/lib/opal/builder.rb DELETED
@@ -1,88 +0,0 @@
1
- require 'opal/parser'
2
-
3
- module Opal
4
-
5
- # Used to build gems/libs/directories of opal code
6
- class Builder
7
-
8
- def initialize(options = {})
9
- @sources = Array(options[:files])
10
- @options = options
11
- end
12
-
13
- def build
14
- @dir = File.expand_path(@options[:dir] || Dir.getwd)
15
-
16
- files = files_for @sources
17
-
18
- @files = {}
19
- @requires = {}
20
- @parser = Parser.new
21
-
22
- files.each { |f| build_file f }
23
-
24
- build_order(@requires).map { |r| @files[r] }.join("\n")
25
- end
26
-
27
- def files_for(sources)
28
- files = []
29
-
30
- sources.each do |s|
31
- s = File.expand_path(File.join @dir, s)
32
- if File.directory? s
33
- files.push *Dir[File.join(s, '**/*.rb')]
34
- elsif File.extname(s) == '.rb'
35
- files << s
36
- end
37
- end
38
-
39
- files
40
- end
41
-
42
- # @param [Hash<Array<String>>] files hash of dependencies
43
- def build_order(files)
44
- all = files.keys
45
- result = []
46
- handled = {}
47
-
48
- all.each { |r| _find_build_order r, files, handled, result }
49
- result
50
- end
51
-
52
- def _find_build_order(file, files, handled, result)
53
- if handled[file] or !files[file]
54
- return
55
- end
56
-
57
- handled[file] = true
58
-
59
- files[file].each do |r|
60
- _find_build_order r, files, handled, result
61
- end
62
-
63
- result << file
64
- end
65
-
66
- def build_file(file)
67
- lib_name = lib_name_for file
68
- parser_name = parser_name_for file
69
-
70
- if File.extname(file) == '.rb'
71
- code = @parser.parse File.read(file), lib_name
72
- @requires[lib_name] = @parser.requires
73
- end
74
-
75
- @files[lib_name] = "// #{ parser_name }\n#{ code }"
76
- end
77
-
78
- def parser_name_for(file)
79
- file.sub(/^#{@dir}\//, '')
80
- end
81
-
82
- def lib_name_for(file)
83
- file = file.sub(/^#{@dir}\//, '')
84
- file = file.chomp File.extname(file)
85
- file.sub(/^(lib|spec|app)\//, '')
86
- end
87
- end
88
- end
data/lib/opal/erb.rb DELETED
@@ -1,14 +0,0 @@
1
- module Opal
2
- def self.parse_erb(str, name = '(erb)')
3
- body = str.gsub('"', '\\"').gsub(/<%=([\s\S]+?)%>/) do
4
- inner = $1.gsub(/\\'/, "'").gsub(/\\"/, '"')
5
- "\")\nout.<<(#{ inner })\nout.<<(\""
6
- end.gsub(/<%([\s\S]+?)%>/) do
7
- "\")\n#{ $1 }\nout.<<(\""
8
- end
9
-
10
- code = "ERB.new('#{name}') do\nout = []\nout.<<(\"#{ body }\")\nout.join\nend\n"
11
- "// #{ name } (erb)\n#{ Opal.parse(code) }\n"
12
- end
13
- end
14
-
@@ -1,80 +0,0 @@
1
- require 'opal'
2
- require 'opal/builder'
3
- require 'fileutils'
4
-
5
- module Opal
6
- class RakeTask
7
- include Rake::DSL if defined? Rake::DSL
8
-
9
- attr_accessor :name, :build_dir, :specs_dir, :files, :dependencies, :parser, :dir
10
-
11
- def initialize(namespace = nil)
12
- @project_dir = Dir.getwd
13
-
14
- @name = File.basename(@project_dir)
15
- @dir = @project_dir
16
- @build_dir = 'build'
17
- @specs_dir = 'spec'
18
- @files = Dir['lib/**/*.rb']
19
- @dependencies = []
20
-
21
- yield self if block_given?
22
-
23
- define_tasks
24
- end
25
-
26
- def build_gem(name)
27
- out = File.join @build_dir, "#{ name }.js"
28
- puts " * #{out}"
29
- write_code Opal.build_gem(name), out
30
- rescue Gem::LoadError => e
31
- puts " - Error: Could not find gem #{name}"
32
- end
33
-
34
- def write_code(code, out)
35
- FileUtils.mkdir_p File.dirname(out)
36
- File.open(out, 'w+') { |o| o.puts code }
37
- end
38
-
39
- def define_tasks
40
- desc "Build opal project"
41
- task 'opal:build' do
42
- out = File.join @build_dir, "#{ @name }.js"
43
- puts " * #{out}"
44
- write_code Opal.build_files(@files, @dir), out
45
- end
46
-
47
- desc "Build specs"
48
- task 'opal:spec' do
49
- out = File.join @build_dir, 'specs.js'
50
- puts " * #{out}"
51
- write_code Opal.build_files(@specs_dir), out
52
- end
53
-
54
- desc "Build dependencies"
55
- task 'opal:dependencies' do
56
- out = File.join @build_dir, 'opal.js'
57
- puts " * #{out}"
58
- write_code Opal.runtime, out
59
-
60
- # build opal-parser?
61
- if @parser
62
- out = File.join @build_dir, 'opal-parser.js'
63
- puts " * #{out}"
64
- write_code Opal.parser_code, out
65
- end
66
-
67
- @dependencies.each { |dep| build_gem dep }
68
- end
69
-
70
- desc "Run specs in spec/index.html"
71
- task 'opal:test' do
72
- runner = File.join Opal.core_dir, 'test_runner', 'runner.js'
73
- sh "phantomjs #{runner} spec/index.html"
74
- end
75
-
76
- desc "Build opal files, dependencies and specs"
77
- task :opal => %w(opal:build opal:dependencies opal:spec)
78
- end
79
- end
80
- end
@@ -1,32 +0,0 @@
1
- describe "Opal.parse_erb" do
2
- before do
3
- @simple = opal_eval_compiled(Opal.parse_erb("<div><%= @some_data %></div>", "simple_test"))
4
- @quoted = opal_eval_compiled(Opal.parse_erb('<div class="foo">hello <%= "there " + @name %></div>', "quoted_test"))
5
- end
6
-
7
- it "should be an instance of ERB" do
8
- @simple.should be_kind_of(ERB)
9
- end
10
-
11
- it "calling the block with a context should render the block" do
12
- @some_data = "hello"
13
- @simple.render(self).should == "<div>hello</div>"
14
- end
15
-
16
- it "should accept quotes in strings" do
17
- @name = "adam"
18
- @quoted.render(self).should == "<div class=\"foo\">hello there adam</div>"
19
- end
20
-
21
- it 'stores created templates in ERB[] by name' do
22
- ERB['simple_test'].should == @simple
23
- ERB['quoted_test'].should == @quoted
24
- end
25
-
26
- describe '.parse' do
27
- it 'parses erb content by running it through compiler' do
28
- opal_eval_compiled Opal.parse_erb("hi there", 'test_parse')
29
- ERB['test_parse'].should be_kind_of(ERB)
30
- end
31
- end
32
- end
data/spec/test_case.html DELETED
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>Opal Test Case</title>
5
- <script type="text/javascript" src="../../opal.js"></script>
6
- <script type="text/javascript" src="../../opal-parser.js"></script>
7
- <script type="text/javascript" src="../../opal-spec.js"></script>
8
- <script type="text/javascript" src="specs.js"></script>
9
- <script type="text/javascript" src="../runner.js"></script>
10
- </head>
11
- <body>
12
- </body>
13
- </html>