opal-sprockets 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # opal-sprocets
1
+ # opal-sprockets
2
2
 
3
3
  Adds sprockets support for Opal
4
4
 
@@ -25,4 +25,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
25
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
26
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
27
  THE SOFTWARE.
28
-
data/example/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'opal', :github => 'opal/opal'
4
+ gem 'opal-sprockets', :path => '../'
@@ -0,0 +1,4 @@
1
+ require 'opal'
2
+ require 'foo'
3
+
4
+ puts "wow!"
@@ -0,0 +1,7 @@
1
+ class Adam
2
+ def bar
3
+ raise "foo"
4
+ end
5
+ end
6
+
7
+ Adam.new.bar
data/example/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ run Opal::Server.new { |s|
5
+ s.main = 'application'
6
+ s.append_path 'app'
7
+ }
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>opal-sprockets demo</title>
5
+
6
+ <%= javascript_include_tag 'application' %>
7
+ </head>
8
+ <body>
9
+ </body>
10
+ </html>
@@ -1,5 +1,4 @@
1
1
  require 'opal/sprockets/environment'
2
- require 'opal/sprockets/parser'
3
2
  require 'opal/sprockets/processor'
4
3
  require 'opal/sprockets/erb'
5
4
  require 'opal/sprockets/server'
@@ -20,4 +20,3 @@ module Opal
20
20
  end
21
21
  end
22
22
  end
23
-
@@ -1,5 +1,6 @@
1
1
  require 'sprockets'
2
- require 'opal/sprockets/parser'
2
+
3
+ $OPAL_SOURCE_MAPS = {}
3
4
 
4
5
  module Opal
5
6
 
@@ -65,18 +66,24 @@ module Opal
65
66
  :source_map_enabled => self.class.source_map_enabled,
66
67
  :irb => self.class.irb_enabled,
67
68
  :file => context.logical_path,
68
- :source_file => context.pathname.to_s,
69
+ :source_file => context.pathname.to_s
69
70
  }
70
71
 
71
- parser = Opal::SprocketsParser.new
72
+ parser = Opal::RequireParser.new
72
73
  result = parser.parse data, options
73
74
 
75
+
74
76
  parser.requires.each do |r|
75
77
  path = find_opal_require context.environment, r
76
78
  context.require_asset path
77
79
  end
78
80
 
79
- result
81
+ if self.class.source_map_enabled
82
+ $OPAL_SOURCE_MAPS[context.pathname] = Opal::SourceMap.new(parser.fragments, "file://#{context.pathname.to_s}").to_s
83
+ "#{result}\n//@ sourceMappingURL=/__opal_source_maps__/#{context.logical_path}.js.map\n"
84
+ else
85
+ result
86
+ end
80
87
  end
81
88
 
82
89
  def find_opal_require(environment, r)
@@ -30,10 +30,7 @@ module Opal
30
30
  asset = sprockets[path]
31
31
  return [404, {}, []] if asset.nil?
32
32
 
33
- source = asset.to_s
34
- map = Opal::SourceMap.new(source, asset.pathname.to_s)
35
-
36
- return [200, {"Content-Type" => "text/json"}, [map.to_s]]
33
+ return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
37
34
  end
38
35
  end
39
36
 
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Sprockets
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.require_paths = ['lib']
16
16
 
17
17
  s.add_dependency 'sprockets'
18
- s.add_dependency 'opal', '~> 0.4.0'
18
+ s.add_dependency 'opal', '~> 0.4.4'
19
19
 
20
20
  s.add_development_dependency 'rake'
21
21
  s.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.4.0
37
+ version: 0.4.4
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.4.0
45
+ version: 0.4.4
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -85,11 +85,15 @@ files:
85
85
  - Gemfile
86
86
  - README.md
87
87
  - Rakefile
88
+ - example/Gemfile
89
+ - example/app/application.rb
90
+ - example/app/foo.rb
91
+ - example/config.ru
92
+ - example/index.html
88
93
  - lib/opal-sprockets.rb
89
94
  - lib/opal/sprockets.rb
90
95
  - lib/opal/sprockets/environment.rb
91
96
  - lib/opal/sprockets/erb.rb
92
- - lib/opal/sprockets/parser.rb
93
97
  - lib/opal/sprockets/processor.rb
94
98
  - lib/opal/sprockets/server.rb
95
99
  - lib/opal/sprockets/source_map_header.rb
@@ -1,84 +0,0 @@
1
- require 'opal/parser'
2
-
3
- module Opal
4
-
5
- # A subclass of Opal::Parser used exclusively by opal-sprockets to handle
6
- # require statements automatically. We basically intercept any top level
7
- # require statement, remove it from the code generation, and then pass it
8
- # off to our sprockets context to handle it. This lets us use the ruby
9
- # require syntax instead of having to use sprockets style comments.
10
- class SprocketsParser < Parser
11
-
12
- def self.parse source, options = {}
13
- self.new.parse source, options
14
- end
15
-
16
- # Holds an array of paths which this file 'requires'.
17
- # @return Array<String>
18
- attr_reader :requires
19
-
20
- def parse source, options = {}
21
- @requires = []
22
- @dynamic_require_severity = (options[:dynamic_require_severity] || :error)
23
- super source, options
24
- end
25
-
26
- def process_call sexp, level
27
- if sexp[1] == :require
28
- return handle_require sexp[2][1]
29
- end
30
-
31
- super sexp, level
32
- end
33
-
34
- def handle_require(sexp)
35
- str = handle_require_sexp sexp
36
- @requires << str unless str.nil? if @requires
37
- fragment("", sexp)
38
- end
39
-
40
- def handle_require_sexp(sexp)
41
- type = sexp.shift
42
-
43
- if type == :str
44
- return sexp[0]
45
- elsif type == :call
46
- recv, meth, args = sexp
47
- parts = args[1..-1].map { |s| handle_require_sexp s }
48
-
49
- if recv == [:const, :File]
50
- if meth == :expand_path
51
- return handle_expand_path(*parts)
52
- elsif meth == :join
53
- return handle_expand_path parts.join("/")
54
- elsif meth == :dirname
55
- return handle_expand_path parts[0].split("/")[0...-1].join("/")
56
- end
57
- end
58
- end
59
-
60
-
61
- case @dynamic_require_severity
62
- when :error
63
- error "Cannot handle dynamic require"
64
- when :warning
65
- warning "Cannot handle dynamic require"
66
- end
67
- end
68
-
69
- def handle_expand_path(path, base = '')
70
- "#{base}/#{path}".split("/").inject([]) do |p, part|
71
- if part == ''
72
- # we had '//', so ignore
73
- elsif part == '..'
74
- p.pop
75
- else
76
- p << part
77
- end
78
-
79
- p
80
- end.join "/"
81
- end
82
- end
83
- end
84
-