opal-sprockets 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ require 'opal'
2
+ require 'opal/parser'
3
+ require 'sprockets'
4
+
5
+ module Opal
6
+ module ERB
7
+ class Processor < Tilt::Template
8
+ self.default_mime_type = 'application/javascript'
9
+
10
+ def self.engine_initialized?
11
+ true
12
+ end
13
+
14
+ def initialize_engine
15
+ require_template_library 'opal'
16
+ end
17
+
18
+ def prepare
19
+ # ...
20
+ end
21
+
22
+ def evaluate(scope, locals, &block)
23
+ Opal::ERB.parse data, scope.logical_path.sub(/^templates\//, '')
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Tilt.register 'opalerb', Opal::ERB::Processor
30
+ Sprockets.register_engine '.opalerb', Opal::ERB::Processor
@@ -71,9 +71,21 @@ module Opal
71
71
  parser = Opal::SprocketsParser.new
72
72
  result = parser.parse data, options
73
73
 
74
- parser.requires.each { |r| context.require_asset r }
74
+ parser.requires.each do |r|
75
+ path = find_opal_require context.environment, r
76
+ context.require_asset path
77
+ end
78
+
75
79
  result
76
80
  end
81
+
82
+ def find_opal_require(environment, r)
83
+ path = environment.paths.find do |p|
84
+ File.exist?(File.join(p, "#{r}.rb"))
85
+ end
86
+
87
+ path ? File.join(path, "#{r}.rb") : r
88
+ end
77
89
  end
78
90
  end
79
91
 
@@ -1,3 +1,5 @@
1
+ require 'rack/builder'
2
+ require 'rack/directory'
1
3
  require 'rack/showexceptions'
2
4
  require 'opal/source_map'
3
5
  require 'opal/sprockets/source_map_header'
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Sprockets
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'opal/sprockets/environment'
2
2
  require 'opal/sprockets/parser'
3
3
  require 'opal/sprockets/processor'
4
+ require 'opal/sprockets/erb'
4
5
  require 'opal/sprockets/server'
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency 'opal', '~> 0.4.0'
19
19
 
20
20
  s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'rspec'
21
22
  end
File without changes
File without changes
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Opal::Processor do
4
+ let(:processor) do
5
+ Opal::Processor.new(File.expand_path('spec/fixtures/app/foo.rb'))
6
+ end
7
+
8
+ let(:sprockets) do
9
+ Sprockets::Environment.new.tap do |s|
10
+ s.append_path 'spec/fixtures/app'
11
+ s.append_path 'spec/fixtures/app2'
12
+ end
13
+ end
14
+
15
+ describe "#find_opal_require" do
16
+ it "returns the full path of a matching ruby file" do
17
+ processor.find_opal_require(sprockets, 'foo').should eq(File.expand_path('spec/fixtures/app/foo.rb'))
18
+ end
19
+
20
+ it "returns original asset name if no matching ruby file" do
21
+ processor.find_opal_require(sprockets, 'doesnt_exist').should eq("doesnt_exist")
22
+ end
23
+
24
+ it "only matches ruby files (not js files)" do
25
+ processor.find_opal_require(sprockets, "bar").should eq("bar")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler.require
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.0
4
+ version: 0.1.1
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-06-16 00:00:00.000000000 Z
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: Sprockets suppoer for opal.
63
79
  email: adam.beynon@gmail.com
64
80
  executables: []
@@ -68,15 +84,21 @@ files:
68
84
  - .gitignore
69
85
  - Gemfile
70
86
  - README.md
87
+ - Rakefile
71
88
  - lib/opal-sprockets.rb
72
89
  - lib/opal/sprockets.rb
73
90
  - lib/opal/sprockets/environment.rb
91
+ - lib/opal/sprockets/erb.rb
74
92
  - lib/opal/sprockets/parser.rb
75
93
  - lib/opal/sprockets/processor.rb
76
94
  - lib/opal/sprockets/server.rb
77
95
  - lib/opal/sprockets/source_map_header.rb
78
96
  - lib/opal/sprockets/version.rb
79
97
  - opal-sprockets.gemspec
98
+ - spec/fixtures/app/foo.rb
99
+ - spec/fixtures/app2/bar.js
100
+ - spec/processor_spec.rb
101
+ - spec/spec_helper.rb
80
102
  homepage: http://opalrb.org
81
103
  licenses: []
82
104
  post_install_message:
@@ -101,4 +123,8 @@ rubygems_version: 1.8.23
101
123
  signing_key:
102
124
  specification_version: 3
103
125
  summary: Sprockets support for opal
104
- test_files: []
126
+ test_files:
127
+ - spec/fixtures/app/foo.rb
128
+ - spec/fixtures/app2/bar.js
129
+ - spec/processor_spec.rb
130
+ - spec/spec_helper.rb