opal-erb 0.0.1
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 +3 -0
- data/Gemfile +5 -0
- data/README.md +1 -0
- data/Rakefile +18 -0
- data/lib/assets/javascripts/opal-erb.rb +20 -0
- data/lib/opal/erb/processor.rb +28 -0
- data/lib/opal/erb/version.rb +5 -0
- data/lib/opal/erb.rb +22 -0
- data/lib/opal-erb.rb +1 -0
- data/opal-erb.gemspec +20 -0
- data/spec/index.html +10 -0
- data/spec/quoted.opalerb +1 -0
- data/spec/simple.opalerb +1 -0
- data/spec/spec.rb +16 -0
- data/spec/spec_helper.rb +6 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# opal-erb: ERB for Opal
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
3
|
+
|
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
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => [:build_specs, :test]
|
@@ -0,0 +1,20 @@
|
|
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
|
10
|
+
|
11
|
+
def initialize(name, &body)
|
12
|
+
@body = body
|
13
|
+
@name = name
|
14
|
+
ERB[name] = self
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(ctx=self)
|
18
|
+
ctx.instance_eval(&@body)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
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/lib/opal/erb.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'opal'
|
2
|
+
require 'opal/erb/processor'
|
3
|
+
require 'opal/erb/version'
|
4
|
+
|
5
|
+
module Opal
|
6
|
+
module ERB
|
7
|
+
def self.parse(str, name='(erb)')
|
8
|
+
body = str.gsub('"', '\\"').gsub(/<%=([\s\S]+?)%>/) do
|
9
|
+
inner = $1.gsub(/\\'/, "'").gsub(/\\"/, '"')
|
10
|
+
"\")\nout.<<(#{ inner })\nout.<<(\""
|
11
|
+
end.gsub(/<%([\s\S]+?)%>/) do
|
12
|
+
"\")\n#{ $1 }\nout.<<(\""
|
13
|
+
end
|
14
|
+
|
15
|
+
code = "ERB.new('#{name}') do\nout = []\nout.<<(\"#{ body }\")\nout.join\nend\n"
|
16
|
+
"// #{ name } (erb)\n#{ Opal.parse(code) }\n"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Just register our opal code path with opal build tools
|
22
|
+
Opal.append_path File.join(File.dirname(__FILE__), '..', 'assets', 'javascripts')
|
data/lib/opal-erb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'opal/erb'
|
data/opal-erb.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/opal/erb/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'opal-erb'
|
6
|
+
s.version = Opal::ERB::VERSION
|
7
|
+
s.authors = ['Adam Beynon']
|
8
|
+
s.email = ['adam.beynon@gmail.com']
|
9
|
+
s.homepage = 'http://opal.github.com/opal-erb'
|
10
|
+
s.summary = %q{ERB for Opal}
|
11
|
+
s.description = %q{ERB for Opal}
|
12
|
+
s.license = 'MIT-LICENSE'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'opal', '~> 0.3.35'
|
20
|
+
end
|
data/spec/index.html
ADDED
data/spec/quoted.opalerb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<div class="foo">hello <%= "there " + @name %></div>
|
data/spec/simple.opalerb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<div><%= @some_data %></div>
|
data/spec/spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
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)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "calling the block with a context should render the block" do
|
8
|
+
@some_data = "hello"
|
9
|
+
ERB['simple'].render(self).should == "<div>hello</div>\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should accept quotes in strings" do
|
13
|
+
@name = "adam"
|
14
|
+
ERB['quoted'].render(self).should == "<div class=\"foo\">hello there adam</div>\n"
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal-erb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Beynon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: opal
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.35
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.35
|
30
|
+
description: ERB for Opal
|
31
|
+
email:
|
32
|
+
- adam.beynon@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/assets/javascripts/opal-erb.rb
|
42
|
+
- lib/opal-erb.rb
|
43
|
+
- lib/opal/erb.rb
|
44
|
+
- lib/opal/erb/processor.rb
|
45
|
+
- lib/opal/erb/version.rb
|
46
|
+
- opal-erb.gemspec
|
47
|
+
- spec/index.html
|
48
|
+
- spec/quoted.opalerb
|
49
|
+
- spec/simple.opalerb
|
50
|
+
- spec/spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
homepage: http://opal.github.com/opal-erb
|
53
|
+
licenses:
|
54
|
+
- MIT-LICENSE
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.23
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: ERB for Opal
|
77
|
+
test_files:
|
78
|
+
- spec/index.html
|
79
|
+
- spec/quoted.opalerb
|
80
|
+
- spec/simple.opalerb
|
81
|
+
- spec/spec.rb
|
82
|
+
- spec/spec_helper.rb
|