opal-erb 0.0.1 → 0.0.2
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/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.md +13 -0
- data/Rakefile +4 -13
- data/config.ru +5 -0
- data/lib/assets/javascripts/opal-erb.rb +9 -11
- data/lib/opal/erb/processor.rb +1 -1
- data/lib/opal/erb/version.rb +1 -1
- data/lib/opal/erb.rb +1 -1
- data/spec/spec.rb +14 -5
- data/spec/templates/foo/bar.opalerb +1 -0
- data/spec/templates/prefixed.opalerb +1 -0
- data/vendor/opal-spec-ext.rb +74 -0
- data/vendor/opal-spec-runner.html +10 -0
- data/vendor/opal-spec-runner.js +40 -0
- metadata +11 -5
- data/spec/index.html +0 -10
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require
|
3
|
+
require File.expand_path('../vendor/opal-spec-ext.rb', __FILE__)
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
FileUtils.mkdir_p 'build'
|
7
|
-
Opal.append_path File.join(File.dirname(__FILE__), 'spec')
|
8
|
-
|
9
|
-
File.open('build/specs.js', 'w+') do |file|
|
10
|
-
file << Opal.process('spec_helper')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
task :test do
|
15
|
-
Opal::Spec.runner
|
5
|
+
Opal::Spec::RakeTask.new do |t|
|
6
|
+
# t.port = 9999
|
16
7
|
end
|
17
8
|
|
18
|
-
task :default => [:
|
9
|
+
task :default => ['opal:spec']
|
data/config.ru
ADDED
@@ -1,20 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def self.[](name)
|
4
|
-
@_cache[name]
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.[]=(name, instance)
|
8
|
-
@_cache[name] = instance
|
9
|
-
end
|
1
|
+
# Provides Template module for registering erb templates
|
2
|
+
require 'opal/template'
|
10
3
|
|
4
|
+
class ERB
|
11
5
|
def initialize(name, &body)
|
12
6
|
@body = body
|
13
7
|
@name = name
|
14
|
-
|
8
|
+
Template[name] = self
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
"#<ERB: name=#{@name.inspect}>"
|
15
13
|
end
|
16
14
|
|
17
|
-
def render(ctx=self)
|
15
|
+
def render(ctx = self)
|
18
16
|
ctx.instance_eval(&@body)
|
19
17
|
end
|
20
18
|
end
|
data/lib/opal/erb/processor.rb
CHANGED
data/lib/opal/erb/version.rb
CHANGED
data/lib/opal/erb.rb
CHANGED
data/spec/spec.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
describe "Opal ERB files" do
|
2
|
-
it "should be defined by their filename" do
|
3
|
-
|
4
|
-
|
2
|
+
it "should be defined by their filename on Template namespace" do
|
3
|
+
Template['simple'].should be_kind_of(ERB)
|
4
|
+
Template['quoted'].should be_kind_of(ERB)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should remove 'templates/' path prefix" do
|
8
|
+
Template['templates/prefixed'].should be_nil
|
9
|
+
Template['prefixed'].should be_kind_of(ERB)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should maintain '/' in template paths" do
|
13
|
+
Template['foo/bar'].should be_kind_of(ERB)
|
5
14
|
end
|
6
15
|
|
7
16
|
it "calling the block with a context should render the block" do
|
8
17
|
@some_data = "hello"
|
9
|
-
|
18
|
+
Template['simple'].render(self).should == "<div>hello</div>\n"
|
10
19
|
end
|
11
20
|
|
12
21
|
it "should accept quotes in strings" do
|
13
22
|
@name = "adam"
|
14
|
-
|
23
|
+
Template['quoted'].render(self).should == "<div class=\"foo\">hello there adam</div>\n"
|
15
24
|
end
|
16
25
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Deeply nested!
|
@@ -0,0 +1 @@
|
|
1
|
+
Prefixed content.
|
@@ -0,0 +1,74 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
+
});
|
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.0.2
|
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-02-
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: opal
|
@@ -38,17 +38,22 @@ files:
|
|
38
38
|
- Gemfile
|
39
39
|
- README.md
|
40
40
|
- Rakefile
|
41
|
+
- config.ru
|
41
42
|
- lib/assets/javascripts/opal-erb.rb
|
42
43
|
- lib/opal-erb.rb
|
43
44
|
- lib/opal/erb.rb
|
44
45
|
- lib/opal/erb/processor.rb
|
45
46
|
- lib/opal/erb/version.rb
|
46
47
|
- opal-erb.gemspec
|
47
|
-
- spec/index.html
|
48
48
|
- spec/quoted.opalerb
|
49
49
|
- spec/simple.opalerb
|
50
50
|
- spec/spec.rb
|
51
51
|
- spec/spec_helper.rb
|
52
|
+
- spec/templates/foo/bar.opalerb
|
53
|
+
- spec/templates/prefixed.opalerb
|
54
|
+
- vendor/opal-spec-ext.rb
|
55
|
+
- vendor/opal-spec-runner.html
|
56
|
+
- vendor/opal-spec-runner.js
|
52
57
|
homepage: http://opal.github.com/opal-erb
|
53
58
|
licenses:
|
54
59
|
- MIT-LICENSE
|
@@ -70,13 +75,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
75
|
version: '0'
|
71
76
|
requirements: []
|
72
77
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
78
|
+
rubygems_version: 1.8.24
|
74
79
|
signing_key:
|
75
80
|
specification_version: 3
|
76
81
|
summary: ERB for Opal
|
77
82
|
test_files:
|
78
|
-
- spec/index.html
|
79
83
|
- spec/quoted.opalerb
|
80
84
|
- spec/simple.opalerb
|
81
85
|
- spec/spec.rb
|
82
86
|
- spec/spec_helper.rb
|
87
|
+
- spec/templates/foo/bar.opalerb
|
88
|
+
- spec/templates/prefixed.opalerb
|