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 CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  Gemfile.lock
3
3
  /build
4
+ /*.gem
data/Gemfile CHANGED
@@ -2,4 +2,5 @@ source :rubygems
2
2
  gemspec
3
3
 
4
4
  gem 'rake'
5
+ gem 'opal', '~> 0.3.37'
5
6
  gem 'opal-spec'
data/README.md CHANGED
@@ -1 +1,14 @@
1
1
  # opal-erb: ERB for Opal
2
+
3
+ ## Usage
4
+
5
+ opal-erb will automatically compile erb files using the `.opalerb` extension.
6
+
7
+ ## Running specs
8
+
9
+ You must have phantomjs installed.
10
+
11
+ ```text
12
+ $ bundle
13
+ $ bundle exec rake
14
+ ```
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
- desc "Build example specs ready to run"
5
- task :build_specs do
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 => [:build_specs, :test]
9
+ task :default => ['opal:spec']
data/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+ require File.expand_path('../vendor/opal-spec-ext.rb', __FILE__)
4
+
5
+ run Opal::Spec::Server.new
@@ -1,20 +1,18 @@
1
- class ERB
2
- @_cache = {}
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
- ERB[name] = self
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
@@ -18,7 +18,7 @@ module Opal
18
18
  end
19
19
 
20
20
  def evaluate(scope, locals, &block)
21
- Opal::ERB.parse data, scope.logical_path
21
+ Opal::ERB.parse data, scope.logical_path.sub(/^templates\//, '')
22
22
  end
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module ERB
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
data/lib/opal/erb.rb CHANGED
@@ -13,7 +13,7 @@ module Opal
13
13
  end
14
14
 
15
15
  code = "ERB.new('#{name}') do\nout = []\nout.<<(\"#{ body }\")\nout.join\nend\n"
16
- "// #{ name } (erb)\n#{ Opal.parse(code) }\n"
16
+ Opal.parse code
17
17
  end
18
18
  end
19
19
  end
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
- ERB['simple'].should be_kind_of(ERB)
4
- ERB['quoted'].should be_kind_of(ERB)
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
- ERB['simple'].render(self).should == "<div>hello</div>\n"
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
- ERB['quoted'].render(self).should == "<div class=\"foo\">hello there adam</div>\n"
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,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>opal-spec: specs</title>
5
+
6
+ </head>
7
+ <body>
8
+ <script src="/assets/spec_helper.js"></script>
9
+ </body>
10
+ </html>
@@ -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.1
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-07 00:00:00.000000000 Z
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.23
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
data/spec/index.html DELETED
@@ -1,10 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>opal-erb specs</title>
5
-
6
- </head>
7
- <body>
8
- <script src="../build/specs.js"></script>
9
- </body>
10
- </html>