opal-erb 0.0.2 → 0.1.0
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.
- data/Gemfile +3 -2
- data/README.md +34 -6
- data/Rakefile +2 -6
- data/lib/opal/erb/version.rb +1 -1
- data/lib/opal/erb.rb +25 -4
- data/{lib/assets/javascripts/opal-erb.rb → opal/erb.rb} +2 -1
- data/opal-erb.gemspec +2 -2
- data/spec/{spec.rb → erb_spec.rb} +12 -4
- data/spec/simple_erb_template.opalerb +1 -0
- data/spec/templates/foo/bar.opalerb +1 -1
- data/spec/templates/prefixed.opalerb +1 -1
- metadata +11 -19
- data/lib/opal/erb/processor.rb +0 -28
- data/spec/quoted.opalerb +0 -1
- data/spec/simple.opalerb +0 -1
- data/spec/spec_helper.rb +0 -6
- data/vendor/opal-spec-ext.rb +0 -74
- data/vendor/opal-spec-runner.html +0 -10
- data/vendor/opal-spec-runner.js +0 -40
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,42 @@
|
|
1
1
|
# opal-erb: ERB for Opal
|
2
2
|
|
3
|
+
Provides an ERB compiler and runtime for opal.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'opal-erb'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then require anywhere in your code:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'opal-gem' # if you don't Bundler.require
|
17
|
+
```
|
18
|
+
|
3
19
|
## Usage
|
4
20
|
|
5
|
-
|
21
|
+
This gem adds support to sprockets to compile files with `.opalerb` extensions
|
22
|
+
automatically, so, if you have:
|
23
|
+
|
24
|
+
```erb
|
25
|
+
<!-- my_template.opalerb -->
|
26
|
+
Hello <%= @name %>!
|
27
|
+
```
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# my_app.rb
|
6
31
|
|
7
|
-
|
32
|
+
require "my_template"
|
8
33
|
|
9
|
-
|
34
|
+
@name = 'Adam'
|
10
35
|
|
11
|
-
|
12
|
-
|
13
|
-
$ bundle exec rake
|
36
|
+
Template["my_template"].render self
|
37
|
+
# => "Hello Adam!"
|
14
38
|
```
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
MIT
|
data/Rakefile
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require
|
3
|
-
require File.expand_path('../vendor/opal-spec-ext.rb', __FILE__)
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
task :default => ['opal:spec']
|
4
|
+
require 'opal/spec/rake_task'
|
5
|
+
Opal::Spec::RakeTask.new(:default)
|
data/lib/opal/erb/version.rb
CHANGED
data/lib/opal/erb.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'opal'
|
2
|
-
require 'opal/
|
3
|
-
require 'opal/erb/version'
|
2
|
+
require 'opal/parser'
|
4
3
|
|
5
4
|
module Opal
|
6
5
|
module ERB
|
@@ -15,8 +14,30 @@ module Opal
|
|
15
14
|
code = "ERB.new('#{name}') do\nout = []\nout.<<(\"#{ body }\")\nout.join\nend\n"
|
16
15
|
Opal.parse code
|
17
16
|
end
|
17
|
+
|
18
|
+
class Processor < Tilt::Template
|
19
|
+
self.default_mime_type = 'application/javascript'
|
20
|
+
|
21
|
+
def self.engine_initialized?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize_engine
|
26
|
+
require_template_library 'opal'
|
27
|
+
end
|
28
|
+
|
29
|
+
def prepare
|
30
|
+
# ...
|
31
|
+
end
|
32
|
+
|
33
|
+
def evaluate(scope, locals, &block)
|
34
|
+
Opal::ERB.parse data, scope.logical_path.sub(/^templates\//, '')
|
35
|
+
end
|
36
|
+
end
|
18
37
|
end
|
19
38
|
end
|
20
39
|
|
21
|
-
|
22
|
-
|
40
|
+
Opal.append_path File.expand_path('../../../opal', __FILE__)
|
41
|
+
|
42
|
+
Tilt.register 'opalerb', Opal::ERB::Processor
|
43
|
+
Sprockets.register_engine '.opalerb', Opal::ERB::Processor
|
data/opal-erb.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.version = Opal::ERB::VERSION
|
7
7
|
s.authors = ['Adam Beynon']
|
8
8
|
s.email = ['adam.beynon@gmail.com']
|
9
|
-
s.homepage = 'http://
|
9
|
+
s.homepage = 'http://github.com/adambeynon/opal-erb'
|
10
10
|
s.summary = %q{ERB for Opal}
|
11
11
|
s.description = %q{ERB for Opal}
|
12
12
|
s.license = 'MIT-LICENSE'
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ['lib']
|
18
18
|
|
19
|
-
s.add_runtime_dependency 'opal', '~> 0.3.
|
19
|
+
s.add_runtime_dependency 'opal', '~> 0.3.44'
|
20
20
|
end
|
@@ -1,7 +1,15 @@
|
|
1
|
+
require 'opal'
|
2
|
+
require 'erb'
|
3
|
+
#require 'opal-spec'
|
4
|
+
|
5
|
+
# Our 3 templates we use (we can require them as normal files)
|
6
|
+
require 'simple_erb_template'
|
7
|
+
require 'templates/prefixed'
|
8
|
+
require 'templates/foo/bar'
|
9
|
+
|
1
10
|
describe "Opal ERB files" do
|
2
11
|
it "should be defined by their filename on Template namespace" do
|
3
|
-
Template['
|
4
|
-
Template['quoted'].should be_kind_of(ERB)
|
12
|
+
Template['simple_erb_template'].should be_kind_of(ERB)
|
5
13
|
end
|
6
14
|
|
7
15
|
it "should remove 'templates/' path prefix" do
|
@@ -15,11 +23,11 @@ describe "Opal ERB files" do
|
|
15
23
|
|
16
24
|
it "calling the block with a context should render the block" do
|
17
25
|
@some_data = "hello"
|
18
|
-
Template['
|
26
|
+
Template['simple_erb_template'].render(self).should == "<div>hello</div>\n"
|
19
27
|
end
|
20
28
|
|
21
29
|
it "should accept quotes in strings" do
|
22
30
|
@name = "adam"
|
23
|
-
Template['
|
31
|
+
Template['foo/bar'].render(self).should == "<div class=\"foo\">hello there adam</div>\n"
|
24
32
|
end
|
25
33
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div><%= @some_data %></div>
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
<div class="foo">hello <%= "there " + @name %></div>
|
@@ -1 +1 @@
|
|
1
|
-
Prefixed content.
|
1
|
+
Prefixed content.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-erb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2013-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: opal
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.3.
|
21
|
+
version: 0.3.44
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.3.
|
29
|
+
version: 0.3.44
|
30
30
|
description: ERB for Opal
|
31
31
|
email:
|
32
32
|
- adam.beynon@gmail.com
|
@@ -39,22 +39,16 @@ files:
|
|
39
39
|
- README.md
|
40
40
|
- Rakefile
|
41
41
|
- config.ru
|
42
|
-
- lib/assets/javascripts/opal-erb.rb
|
43
42
|
- lib/opal-erb.rb
|
44
43
|
- lib/opal/erb.rb
|
45
|
-
- lib/opal/erb/processor.rb
|
46
44
|
- lib/opal/erb/version.rb
|
47
45
|
- opal-erb.gemspec
|
48
|
-
-
|
49
|
-
- spec/
|
50
|
-
- spec/
|
51
|
-
- spec/spec_helper.rb
|
46
|
+
- opal/erb.rb
|
47
|
+
- spec/erb_spec.rb
|
48
|
+
- spec/simple_erb_template.opalerb
|
52
49
|
- spec/templates/foo/bar.opalerb
|
53
50
|
- spec/templates/prefixed.opalerb
|
54
|
-
|
55
|
-
- vendor/opal-spec-runner.html
|
56
|
-
- vendor/opal-spec-runner.js
|
57
|
-
homepage: http://opal.github.com/opal-erb
|
51
|
+
homepage: http://github.com/adambeynon/opal-erb
|
58
52
|
licenses:
|
59
53
|
- MIT-LICENSE
|
60
54
|
post_install_message:
|
@@ -75,14 +69,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
69
|
version: '0'
|
76
70
|
requirements: []
|
77
71
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.23
|
79
73
|
signing_key:
|
80
74
|
specification_version: 3
|
81
75
|
summary: ERB for Opal
|
82
76
|
test_files:
|
83
|
-
- spec/
|
84
|
-
- spec/
|
85
|
-
- spec/spec.rb
|
86
|
-
- spec/spec_helper.rb
|
77
|
+
- spec/erb_spec.rb
|
78
|
+
- spec/simple_erb_template.opalerb
|
87
79
|
- spec/templates/foo/bar.opalerb
|
88
80
|
- spec/templates/prefixed.opalerb
|
data/lib/opal/erb/processor.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
|
3
|
-
module Opal
|
4
|
-
module ERB
|
5
|
-
class Processor < Tilt::Template
|
6
|
-
self.default_mime_type = 'application/javascript'
|
7
|
-
|
8
|
-
def self.engine_initialized?
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize_engine
|
13
|
-
require_template_library 'opal'
|
14
|
-
end
|
15
|
-
|
16
|
-
def prepare
|
17
|
-
# ...
|
18
|
-
end
|
19
|
-
|
20
|
-
def evaluate(scope, locals, &block)
|
21
|
-
Opal::ERB.parse data, scope.logical_path.sub(/^templates\//, '')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
Tilt.register 'opalerb', Opal::ERB::Processor
|
28
|
-
Sprockets.register_engine '.opalerb', Opal::ERB::Processor
|
data/spec/quoted.opalerb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<div class="foo">hello <%= "there " + @name %></div>
|
data/spec/simple.opalerb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<div><%= @some_data %></div>
|
data/spec/spec_helper.rb
DELETED
data/vendor/opal-spec-ext.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
module Opal
|
2
|
-
module Spec
|
3
|
-
class Server
|
4
|
-
class IndexHandler
|
5
|
-
def initialize(app)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
if env['PATH_INFO'] == '/'
|
11
|
-
[200, {'Content-Type' => 'text/html'}, [File.read('vendor/opal-spec-runner.html')]]
|
12
|
-
else
|
13
|
-
@app.call(env)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@app = Rack::Builder.app do
|
20
|
-
map '/assets' do
|
21
|
-
env = Sprockets::Environment.new
|
22
|
-
Opal.paths.each { |p| env.append_path p }
|
23
|
-
env.append_path 'spec'
|
24
|
-
run env
|
25
|
-
end
|
26
|
-
|
27
|
-
use IndexHandler
|
28
|
-
run Rack::Directory.new('.')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def call(env)
|
33
|
-
@app.call(env)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Opal
|
40
|
-
module Spec
|
41
|
-
class RakeTask
|
42
|
-
include Rake::DSL if defined? Rake::DSL
|
43
|
-
|
44
|
-
def initialize(name = "opal:spec")
|
45
|
-
@name = name
|
46
|
-
define
|
47
|
-
end
|
48
|
-
|
49
|
-
def define
|
50
|
-
desc "Run opal specs"
|
51
|
-
task @name do
|
52
|
-
require 'rack'
|
53
|
-
require 'webrick'
|
54
|
-
|
55
|
-
server = fork do
|
56
|
-
Rack::Server.start(:config => 'config.ru',
|
57
|
-
:Port => 9999,
|
58
|
-
:Logger => WEBrick::Log.new("/dev/null"),
|
59
|
-
:AccessLog => [])
|
60
|
-
end
|
61
|
-
|
62
|
-
system("phantomjs vendor/opal-spec-runner.js \"http://localhost:9999/\"")
|
63
|
-
|
64
|
-
success = $?.success?
|
65
|
-
|
66
|
-
Process.kill(:SIGINT, server)
|
67
|
-
Process.wait
|
68
|
-
|
69
|
-
exit(1) unless success
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/vendor/opal-spec-runner.js
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Test runner for phantomjs
|
3
|
-
*/
|
4
|
-
var args = phantom.args;
|
5
|
-
var page = require('webpage').create();
|
6
|
-
|
7
|
-
page.onConsoleMessage = function(msg) {
|
8
|
-
console.log(msg);
|
9
|
-
};
|
10
|
-
|
11
|
-
page.onInitialized = function() {
|
12
|
-
page.evaluate(function () {
|
13
|
-
window.OPAL_SPEC_PHANTOM = true;
|
14
|
-
});
|
15
|
-
};
|
16
|
-
|
17
|
-
page.open(args[0], function(status) {
|
18
|
-
if (status !== 'success') {
|
19
|
-
console.error("Cannot load: " + args[0]);
|
20
|
-
phantom.exit(1);
|
21
|
-
} else {
|
22
|
-
var timeout = parseInt(args[1] || 60000, 10);
|
23
|
-
var start = Date.now();
|
24
|
-
var interval = setInterval(function() {
|
25
|
-
if (Date.now() > start + timeout) {
|
26
|
-
console.error("Specs timed out");
|
27
|
-
phantom.exit(124);
|
28
|
-
} else {
|
29
|
-
var code = page.evaluate(function() {
|
30
|
-
return window.OPAL_SPEC_CODE;
|
31
|
-
});
|
32
|
-
|
33
|
-
if (code === 0 || code === 1) {
|
34
|
-
clearInterval(interval);
|
35
|
-
phantom.exit(code);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}, 500);
|
39
|
-
}
|
40
|
-
});
|