opal 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile +0 -1
- data/Rakefile +1 -0
- data/lib/opal.rb +0 -2
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +3 -3
- data/opal/opal.rb +20 -20
- metadata +23 -27
- data/lib/opal/processor.rb +0 -83
- data/lib/opal/server.rb +0 -150
- data/lib/opal/sprockets_parser.rb +0 -77
- data/lib/opal/sprockets_source_map_header.rb +0 -21
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/opal.rb
CHANGED
data/lib/opal/version.rb
CHANGED
data/opal.gemspec
CHANGED
@@ -14,11 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
15
|
s.require_paths = ['lib']
|
16
16
|
|
17
|
-
s.add_dependency 'rake'
|
18
|
-
s.add_dependency 'racc'
|
19
|
-
s.add_dependency 'sprockets'
|
20
17
|
s.add_dependency 'source_map'
|
21
18
|
|
22
19
|
s.add_development_dependency 'mspec', '1.5.18'
|
23
20
|
s.add_development_dependency 'uglifier'
|
21
|
+
s.add_development_dependency 'rake'
|
22
|
+
s.add_development_dependency 'racc'
|
23
|
+
s.add_development_dependency 'opal-sprockets', '~> 0.1.0'
|
24
24
|
end
|
data/opal/opal.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
require 'opal/runtime'
|
2
|
-
require 'opal/class'
|
3
|
-
require 'opal/basic_object'
|
4
|
-
require 'opal/kernel'
|
5
|
-
require 'opal/nil_class'
|
6
|
-
require 'opal/boolean'
|
7
|
-
require 'opal/error'
|
8
|
-
require 'opal/regexp'
|
9
|
-
require 'opal/comparable'
|
10
|
-
require 'opal/enumerable'
|
11
|
-
require 'opal/enumerator'
|
12
|
-
require 'opal/array'
|
13
|
-
require 'opal/hash'
|
14
|
-
require 'opal/string'
|
15
|
-
require 'opal/numeric'
|
16
|
-
require 'opal/proc'
|
17
|
-
require 'opal/range'
|
18
|
-
require 'opal/time'
|
19
|
-
require 'opal/json'
|
20
|
-
require 'opal/native'
|
1
|
+
#= require 'opal/runtime'
|
2
|
+
#= require 'opal/class'
|
3
|
+
#= require 'opal/basic_object'
|
4
|
+
#= require 'opal/kernel'
|
5
|
+
#= require 'opal/nil_class'
|
6
|
+
#= require 'opal/boolean'
|
7
|
+
#= require 'opal/error'
|
8
|
+
#= require 'opal/regexp'
|
9
|
+
#= require 'opal/comparable'
|
10
|
+
#= require 'opal/enumerable'
|
11
|
+
#= require 'opal/enumerator'
|
12
|
+
#= require 'opal/array'
|
13
|
+
#= require 'opal/hash'
|
14
|
+
#= require 'opal/string'
|
15
|
+
#= require 'opal/numeric'
|
16
|
+
#= require 'opal/proc'
|
17
|
+
#= require 'opal/range'
|
18
|
+
#= require 'opal/time'
|
19
|
+
#= require 'opal/json'
|
20
|
+
#= require 'opal/native'
|
21
21
|
|
22
22
|
# regexp matches
|
23
23
|
$& = $~ = $` = $' = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: source_map
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: mspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
38
|
-
type: :
|
37
|
+
version: 1.5.18
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 1.5.18
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: uglifier
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
type: :
|
54
|
+
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
@@ -60,14 +60,14 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
-
type: :
|
70
|
+
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
@@ -76,37 +76,37 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: racc
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- - '
|
83
|
+
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
85
|
+
version: '0'
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- - '
|
91
|
+
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: opal-sprockets
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
|
-
- -
|
99
|
+
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 0.1.0
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 0.1.0
|
110
110
|
description: Ruby runtime and core library for javascript.
|
111
111
|
email: adam.beynon@gmail.com
|
112
112
|
executables: []
|
@@ -147,11 +147,7 @@ files:
|
|
147
147
|
- lib/opal/lexer.rb
|
148
148
|
- lib/opal/lexer_scope.rb
|
149
149
|
- lib/opal/parser.rb
|
150
|
-
- lib/opal/processor.rb
|
151
|
-
- lib/opal/server.rb
|
152
150
|
- lib/opal/source_map.rb
|
153
|
-
- lib/opal/sprockets_parser.rb
|
154
|
-
- lib/opal/sprockets_source_map_header.rb
|
155
151
|
- lib/opal/target_scope.rb
|
156
152
|
- lib/opal/version.rb
|
157
153
|
- opal.gemspec
|
data/lib/opal/processor.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
require 'opal/sprockets_parser'
|
3
|
-
|
4
|
-
module Opal
|
5
|
-
# Proccess using Sprockets
|
6
|
-
#
|
7
|
-
# Opal.process('opal-jquery') # => String
|
8
|
-
def self.process asset
|
9
|
-
Environment.new[asset].to_s
|
10
|
-
end
|
11
|
-
|
12
|
-
# The Processor class is used to make ruby files (with rb or opal extensions)
|
13
|
-
# available to any sprockets based server. Processor will then get passed any
|
14
|
-
# ruby source file to build. There are some options you can override globally
|
15
|
-
# which effect how certain ruby features are handled:
|
16
|
-
#
|
17
|
-
# * method_missing_enabled [true by default]
|
18
|
-
# * optimized_operators_enabled [true by default]
|
19
|
-
# * arity_check_enabled [false by default]
|
20
|
-
# * const_missing_enabled [true by default]
|
21
|
-
# * dynamic_require_severity [true by default]
|
22
|
-
# * source_map_enabled [true by default]
|
23
|
-
# * irb_enabled [false by default]
|
24
|
-
#
|
25
|
-
class Processor < Tilt::Template
|
26
|
-
self.default_mime_type = 'application/javascript'
|
27
|
-
|
28
|
-
def self.engine_initialized?
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
class << self
|
33
|
-
attr_accessor :method_missing_enabled
|
34
|
-
attr_accessor :optimized_operators_enabled
|
35
|
-
attr_accessor :arity_check_enabled
|
36
|
-
attr_accessor :const_missing_enabled
|
37
|
-
attr_accessor :dynamic_require_severity
|
38
|
-
attr_accessor :source_map_enabled
|
39
|
-
attr_accessor :irb_enabled
|
40
|
-
end
|
41
|
-
|
42
|
-
self.method_missing_enabled = true
|
43
|
-
self.optimized_operators_enabled = true
|
44
|
-
self.arity_check_enabled = false
|
45
|
-
self.const_missing_enabled = true
|
46
|
-
self.dynamic_require_severity = :error # :error, :warning or :ignore
|
47
|
-
self.source_map_enabled = true
|
48
|
-
self.irb_enabled = false
|
49
|
-
|
50
|
-
def initialize_engine
|
51
|
-
require_template_library 'opal'
|
52
|
-
end
|
53
|
-
|
54
|
-
def prepare
|
55
|
-
end
|
56
|
-
|
57
|
-
def evaluate(context, locals, &block)
|
58
|
-
options = {
|
59
|
-
:method_missing => self.class.method_missing_enabled,
|
60
|
-
:optimized_operators => self.class.optimized_operators_enabled,
|
61
|
-
:arity_check => self.class.arity_check_enabled,
|
62
|
-
:const_missing => self.class.const_missing_enabled,
|
63
|
-
:dynamic_require_severity => self.class.dynamic_require_severity,
|
64
|
-
:source_map_enabled => self.class.source_map_enabled,
|
65
|
-
:irb => self.class.irb_enabled,
|
66
|
-
:file => context.logical_path,
|
67
|
-
:source_file => context.pathname.to_s,
|
68
|
-
}
|
69
|
-
|
70
|
-
parser = Opal::SprocketsParser.new
|
71
|
-
result = parser.parse data, options
|
72
|
-
|
73
|
-
parser.requires.each { |r| context.require_asset r }
|
74
|
-
result
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
Tilt.register 'rb', Opal::Processor
|
80
|
-
Sprockets.register_engine '.rb', Opal::Processor
|
81
|
-
|
82
|
-
Tilt.register 'opal', Opal::Processor
|
83
|
-
Sprockets.register_engine '.opal', Opal::Processor
|
data/lib/opal/server.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'rack'
|
3
|
-
require 'rack/showexceptions'
|
4
|
-
require 'opal/sprockets_source_map_header'
|
5
|
-
require 'opal/source_map'
|
6
|
-
|
7
|
-
module Opal
|
8
|
-
class Environment < ::Sprockets::Environment
|
9
|
-
def initialize *args
|
10
|
-
super
|
11
|
-
Opal.paths.each { |p| append_path p }
|
12
|
-
end
|
13
|
-
|
14
|
-
def use_gem gem_name
|
15
|
-
append_path File.join(Gem::Specification.find_by_name(gem_name).gem_dir, 'lib')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class SourceMapServer
|
20
|
-
def initialize sprockets
|
21
|
-
@sprockets = sprockets
|
22
|
-
end
|
23
|
-
|
24
|
-
attr_reader :sprockets
|
25
|
-
|
26
|
-
attr_writer :prefix
|
27
|
-
|
28
|
-
def prefix
|
29
|
-
@prefix ||= '/__opal_source_maps__'
|
30
|
-
end
|
31
|
-
|
32
|
-
def inspect
|
33
|
-
"#<#{self.class}:#{object_id}>"
|
34
|
-
end
|
35
|
-
|
36
|
-
def call(env)
|
37
|
-
path = env['PATH_INFO'].gsub(/^\/|\.js\.map$/, '')
|
38
|
-
asset = sprockets[path]
|
39
|
-
return [404, {}, []] if asset.nil?
|
40
|
-
|
41
|
-
source = asset.to_s
|
42
|
-
map = Opal::SourceMap.new(source, asset.pathname.to_s)
|
43
|
-
|
44
|
-
return [200, {"Content-Type" => "text/json"}, [map.to_s]]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class Server
|
49
|
-
|
50
|
-
attr_accessor :debug, :index_path, :main, :public_dir, :sprockets
|
51
|
-
|
52
|
-
def initialize debug = true
|
53
|
-
@public_dir = '.'
|
54
|
-
@sprockets = Environment.new
|
55
|
-
@debug = debug
|
56
|
-
|
57
|
-
yield self if block_given?
|
58
|
-
create_app
|
59
|
-
end
|
60
|
-
|
61
|
-
def append_path path
|
62
|
-
@sprockets.append_path path
|
63
|
-
end
|
64
|
-
|
65
|
-
def use_gem gem_name
|
66
|
-
@sprockets.use_gem gem_name
|
67
|
-
end
|
68
|
-
|
69
|
-
def create_app
|
70
|
-
server, sprockets = self, @sprockets
|
71
|
-
|
72
|
-
@app = Rack::Builder.app do
|
73
|
-
use Rack::ShowExceptions
|
74
|
-
map('/assets') { run sprockets }
|
75
|
-
map(server.source_maps.prefix) { run server.source_maps }
|
76
|
-
use Index, server
|
77
|
-
run Rack::Directory.new(server.public_dir)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def source_maps
|
82
|
-
@source_maps ||= SourceMapServer.new(@sprockets)
|
83
|
-
end
|
84
|
-
|
85
|
-
def call(env)
|
86
|
-
@app.call env
|
87
|
-
end
|
88
|
-
|
89
|
-
class Index
|
90
|
-
|
91
|
-
def initialize(app, server)
|
92
|
-
@app = app
|
93
|
-
@server = server
|
94
|
-
@index_path = server.index_path
|
95
|
-
end
|
96
|
-
|
97
|
-
def call(env)
|
98
|
-
if %w[/ /index.html].include? env['PATH_INFO']
|
99
|
-
[200, { 'Content-Type' => 'text/html' }, [html]]
|
100
|
-
else
|
101
|
-
@app.call env
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# Returns the html content for the root path. Supports ERB
|
106
|
-
def html
|
107
|
-
source = if @index_path
|
108
|
-
raise "index does not exist: #{@index_path}" unless File.exist?(@index_path)
|
109
|
-
File.read @index_path
|
110
|
-
elsif File.exist? 'index.html'
|
111
|
-
File.read 'index.html'
|
112
|
-
elsif File.exist? 'index.html.erb'
|
113
|
-
File.read 'index.html.erb'
|
114
|
-
else
|
115
|
-
SOURCE
|
116
|
-
end
|
117
|
-
|
118
|
-
::ERB.new(source).result binding
|
119
|
-
end
|
120
|
-
|
121
|
-
def javascript_include_tag source
|
122
|
-
if @server.debug
|
123
|
-
assets = @server.sprockets[source].to_a
|
124
|
-
|
125
|
-
raise "Cannot find asset: #{source}" if assets.empty?
|
126
|
-
|
127
|
-
scripts = assets.map do |a|
|
128
|
-
%Q{<script src="/assets/#{ a.logical_path }?body=1"></script>}
|
129
|
-
end
|
130
|
-
|
131
|
-
scripts.join "\n"
|
132
|
-
else
|
133
|
-
"<script src=\"/assets/#{source}.js\"></script>"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
SOURCE = <<-HTML
|
138
|
-
<!DOCTYPE html>
|
139
|
-
<html>
|
140
|
-
<head>
|
141
|
-
<title>Opal Server</title>
|
142
|
-
</head>
|
143
|
-
<body>
|
144
|
-
<%= javascript_include_tag @server.main %>
|
145
|
-
</body>
|
146
|
-
</html>
|
147
|
-
HTML
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'opal/parser'
|
2
|
-
|
3
|
-
module Opal
|
4
|
-
class SprocketsParser < Parser
|
5
|
-
|
6
|
-
def self.parse source, options = {}
|
7
|
-
self.new.parse source, options
|
8
|
-
end
|
9
|
-
|
10
|
-
# Holds an array of paths which this file 'requires'.
|
11
|
-
# @return Array<String>
|
12
|
-
attr_reader :requires
|
13
|
-
|
14
|
-
def parse source, options = {}
|
15
|
-
@requires = []
|
16
|
-
@dynamic_require_severity = (options[:dynamic_require_severity] || :error)
|
17
|
-
super source, options
|
18
|
-
end
|
19
|
-
|
20
|
-
def process_call sexp, level
|
21
|
-
if sexp[1] == :require
|
22
|
-
return handle_require sexp[2][1]
|
23
|
-
end
|
24
|
-
|
25
|
-
super sexp, level
|
26
|
-
end
|
27
|
-
|
28
|
-
def handle_require(sexp)
|
29
|
-
str = handle_require_sexp sexp
|
30
|
-
@requires << str unless str.nil? if @requires
|
31
|
-
fragment("", sexp)
|
32
|
-
end
|
33
|
-
|
34
|
-
def handle_require_sexp(sexp)
|
35
|
-
type = sexp.shift
|
36
|
-
|
37
|
-
if type == :str
|
38
|
-
return sexp[0]
|
39
|
-
elsif type == :call
|
40
|
-
recv, meth, args = sexp
|
41
|
-
parts = args[1..-1].map { |s| handle_require_sexp s }
|
42
|
-
|
43
|
-
if recv == [:const, :File]
|
44
|
-
if meth == :expand_path
|
45
|
-
return handle_expand_path(*parts)
|
46
|
-
elsif meth == :join
|
47
|
-
return handle_expand_path parts.join("/")
|
48
|
-
elsif meth == :dirname
|
49
|
-
return handle_expand_path parts[0].split("/")[0...-1].join("/")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
case @dynamic_require_severity
|
56
|
-
when :error
|
57
|
-
error "Cannot handle dynamic require"
|
58
|
-
when :warning
|
59
|
-
warning "Cannot handle dynamic require"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def handle_expand_path(path, base = '')
|
64
|
-
"#{base}/#{path}".split("/").inject([]) do |p, part|
|
65
|
-
if part == ''
|
66
|
-
# we had '//', so ignore
|
67
|
-
elsif part == '..'
|
68
|
-
p.pop
|
69
|
-
else
|
70
|
-
p << part
|
71
|
-
end
|
72
|
-
|
73
|
-
p
|
74
|
-
end.join "/"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'sprockets/server'
|
2
|
-
|
3
|
-
module Sprockets
|
4
|
-
module Server
|
5
|
-
|
6
|
-
# Adds the source map header to all sprocket responses for assets
|
7
|
-
# with a .rb or .opal extension in the extension chain.
|
8
|
-
def headers_with_opal_source_maps(env, asset, length)
|
9
|
-
headers_without_opal_source_maps(env, asset, length).tap do |headers|
|
10
|
-
if asset.pathname.to_s =~ /\.(rb|opal)\b/
|
11
|
-
headers['X-SourceMap'] = '/__opal_source_maps__/'+asset.logical_path + '.map'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Poor man's alias_method_chain :)
|
17
|
-
alias headers_without_opal_source_maps headers
|
18
|
-
alias headers headers_with_opal_source_maps
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|