opal-rails 0.0.1.a → 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/Gemfile +0 -2
- data/README.md +46 -0
- data/lib/assets/javascripts/opal.js +5146 -0
- data/lib/opal-rails.rb +5 -1
- data/lib/opal/rails/engine.rb +3 -6
- data/lib/opal/rails/processor.rb +31 -0
- data/lib/opal/rails/template_handler.rb +15 -0
- data/lib/opal/rails/version.rb +1 -1
- data/opal-rails.gemspec +5 -6
- data/spec/opal/rails/processor_spec.rb +18 -0
- data/spec/spec_helper.rb +2 -1
- metadata +27 -39
- data/lib/opal/rails.rb +0 -10
- data/lib/opal/rails/monkey_patches.rb +0 -36
- data/lib/opal/rails/railtie.rb +0 -46
- data/lib/opal/rails/template_handlers.rb +0 -34
- data/lib/tilt/opal.rb +0 -113
- data/spec/tilt/opal_spec.rb +0 -19
- data/vendor/assets/javascripts/opal.js +0 -6076
data/lib/opal-rails.rb
CHANGED
data/lib/opal/rails/engine.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
|
1
|
+
require 'rails/engine'
|
2
|
+
|
2
3
|
module Opal
|
3
4
|
module Rails
|
4
|
-
|
5
5
|
class Engine < ::Rails::Engine
|
6
|
-
|
7
|
-
# require "jquery/assert_select" if ::Rails.env.test?
|
8
|
-
# end
|
6
|
+
config.app_generators.javascript_engine :opal
|
9
7
|
end
|
10
|
-
|
11
8
|
end
|
12
9
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
|
3
|
+
module Opal
|
4
|
+
module Rails
|
5
|
+
# Opal template implementation. See:
|
6
|
+
# http://opalrb.org/
|
7
|
+
#
|
8
|
+
# Opal templates do not support object scopes, locals, or yield.
|
9
|
+
class Processor < Tilt::Template
|
10
|
+
self.default_mime_type = 'application/javascript'
|
11
|
+
|
12
|
+
def self.engine_initialized?
|
13
|
+
defined? ::Opal
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize_engine
|
17
|
+
require_template_library 'opal'
|
18
|
+
end
|
19
|
+
|
20
|
+
def prepare
|
21
|
+
end
|
22
|
+
|
23
|
+
def evaluate(scope, locals, &block)
|
24
|
+
Opal.parse(data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Tilt.register 'opal', Opal::Rails::Processor
|
31
|
+
Sprockets.register_engine '.opal', Opal::Rails::Processor
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Opal
|
2
|
+
module Rails
|
3
|
+
class TemplateHandler
|
4
|
+
def self.call(template)
|
5
|
+
escaped = template.source.gsub(':', '\:')
|
6
|
+
string = '%q:' + escaped + ':;'
|
7
|
+
"Opal.parse(#{string})"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveSupport.on_load(:action_view) do
|
14
|
+
ActionView::Template.register_template_handler :opal, Opal::Rails::TemplateHandler
|
15
|
+
end
|
data/lib/opal/rails/version.rb
CHANGED
data/opal-rails.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = 'opal-rails'
|
7
7
|
s.version = Opal::Rails::VERSION
|
8
8
|
s.authors = ['Elia Schito']
|
9
|
-
s.email = ['
|
9
|
+
s.email = ['elia@schito.me']
|
10
10
|
s.homepage = ''
|
11
11
|
s.summary = %q{Rails bindings for opal JS engine}
|
12
12
|
s.description = %q{Rails bindings for opal JS engine}
|
@@ -18,10 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.add_runtime_dependency 'opal'
|
22
|
-
s.add_runtime_dependency 'railties',
|
23
|
-
s.add_runtime_dependency '
|
24
|
-
s.add_runtime_dependency 'sprockets', '>= 2.0.0.beta.9'
|
21
|
+
s.add_runtime_dependency 'opal', '0.3.18'
|
22
|
+
s.add_runtime_dependency 'railties', '~> 3.2.0'
|
23
|
+
s.add_runtime_dependency 'sprockets', '~> 2.1'
|
25
24
|
|
26
|
-
s.add_development_dependency 'rspec',
|
25
|
+
s.add_development_dependency 'rspec', '~> 2.4'
|
27
26
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Opal::Rails::Processor do
|
4
|
+
|
5
|
+
it "is registered for '.opal' files" do
|
6
|
+
Tilt['test.opal'].should eq(Opal::Rails::Processor)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "compiles and evaluates the template on #render" do
|
10
|
+
template = Opal::Rails::Processor.new { |t| "puts 'Hello, World!'\n" }
|
11
|
+
template.render.should include('this.$puts("Hello, World!")')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can be rendered more than once" do
|
15
|
+
template = Opal::Rails::Processor.new { |t| "puts 'Hello, World!'\n" }
|
16
|
+
3.times { template.render.should include('this.$puts("Hello, World!")') }
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
$:.unshift File.expand_path('../../lib')
|
1
|
+
$:.unshift File.expand_path('../../lib')
|
2
|
+
require 'opal-rails'
|
metadata
CHANGED
@@ -1,63 +1,52 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Elia Schito
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: opal
|
16
|
-
requirement: &
|
16
|
+
requirement: &70300436008300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.3.18
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70300436008300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: railties
|
27
|
-
requirement: &
|
27
|
+
requirement: &70300436022500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 3.
|
32
|
+
version: 3.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: actionpack
|
38
|
-
requirement: &70164821946080 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 3.1.0.rc1
|
44
|
-
type: :runtime
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70164821946080
|
35
|
+
version_requirements: *70300436022500
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: sprockets
|
49
|
-
requirement: &
|
38
|
+
requirement: &70300436021280 !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
40
|
requirements:
|
52
|
-
- -
|
41
|
+
- - ~>
|
53
42
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
43
|
+
version: '2.1'
|
55
44
|
type: :runtime
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *70300436021280
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
48
|
name: rspec
|
60
|
-
requirement: &
|
49
|
+
requirement: &70300436019840 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
52
|
- - ~>
|
@@ -65,10 +54,10 @@ dependencies:
|
|
65
54
|
version: '2.4'
|
66
55
|
type: :development
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *70300436019840
|
69
58
|
description: Rails bindings for opal JS engine
|
70
59
|
email:
|
71
|
-
-
|
60
|
+
- elia@schito.me
|
72
61
|
executables: []
|
73
62
|
extensions: []
|
74
63
|
extra_rdoc_files: []
|
@@ -76,19 +65,17 @@ files:
|
|
76
65
|
- .gitignore
|
77
66
|
- .rspec
|
78
67
|
- Gemfile
|
68
|
+
- README.md
|
79
69
|
- Rakefile
|
70
|
+
- lib/assets/javascripts/opal.js
|
80
71
|
- lib/opal-rails.rb
|
81
|
-
- lib/opal/rails.rb
|
82
72
|
- lib/opal/rails/engine.rb
|
83
|
-
- lib/opal/rails/
|
84
|
-
- lib/opal/rails/
|
85
|
-
- lib/opal/rails/template_handlers.rb
|
73
|
+
- lib/opal/rails/processor.rb
|
74
|
+
- lib/opal/rails/template_handler.rb
|
86
75
|
- lib/opal/rails/version.rb
|
87
|
-
- lib/tilt/opal.rb
|
88
76
|
- opal-rails.gemspec
|
77
|
+
- spec/opal/rails/processor_spec.rb
|
89
78
|
- spec/spec_helper.rb
|
90
|
-
- spec/tilt/opal_spec.rb
|
91
|
-
- vendor/assets/javascripts/opal.js
|
92
79
|
homepage: ''
|
93
80
|
licenses: []
|
94
81
|
post_install_message:
|
@@ -104,15 +91,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
92
|
none: false
|
106
93
|
requirements:
|
107
|
-
- - ! '
|
94
|
+
- - ! '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
96
|
+
version: '0'
|
110
97
|
requirements: []
|
111
98
|
rubyforge_project: opal-rails
|
112
|
-
rubygems_version: 1.8.
|
99
|
+
rubygems_version: 1.8.17
|
113
100
|
signing_key:
|
114
101
|
specification_version: 3
|
115
102
|
summary: Rails bindings for opal JS engine
|
116
103
|
test_files:
|
104
|
+
- spec/opal/rails/processor_spec.rb
|
117
105
|
- spec/spec_helper.rb
|
118
|
-
|
106
|
+
has_rdoc:
|
data/lib/opal/rails.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# module Opal::Rails::OpalContext
|
2
|
-
# attr_accessor :opal_config
|
3
|
-
# end
|
4
|
-
#
|
5
|
-
# module Opal::Rails::SprocketsConfig
|
6
|
-
# def self.included(base)
|
7
|
-
# base.alias_method_chain :asset_environment, :opal_config
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# def asset_environment_with_opal_config(app, *args)
|
11
|
-
# env = asset_environment_without_opal_config(app, *args)
|
12
|
-
# env.context_class.extend(Opal::Rails::OpalContext)
|
13
|
-
# env.context_class.opal_config = app.config.opal
|
14
|
-
# env
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# begin
|
19
|
-
# # Before sprockets was extracted from rails
|
20
|
-
# require 'sprockets/railtie'
|
21
|
-
# module Sprockets
|
22
|
-
# class Railtie < ::Rails::Railtie
|
23
|
-
# include Opal::Rails::SprocketsConfig
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
# rescue LoadError
|
27
|
-
# # After sprockets was extracted into sprockets-rails
|
28
|
-
# require 'sprockets/rails/railtie'
|
29
|
-
# module Sprockets
|
30
|
-
# module Rails
|
31
|
-
# class Railtie < ::Rails::Railtie
|
32
|
-
# include Opal::Rails::SprocketsConfig
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
# end
|
data/lib/opal/rails/railtie.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module Opal::Rails
|
2
|
-
class Railtie < ::Rails::Railtie
|
3
|
-
config.opal = ActiveSupport::OrderedOptions.new
|
4
|
-
|
5
|
-
# # Establish static configuration defaults
|
6
|
-
# # Emit scss files during stylesheet generation of scaffold
|
7
|
-
# config.sass.preferred_syntax = :scss
|
8
|
-
# # Use expanded output instead of the sass default of :nested
|
9
|
-
# config.sass.style = :expanded
|
10
|
-
# # Write sass cache files to tmp/sass-cache for performance
|
11
|
-
# config.sass.cache = true
|
12
|
-
# # Read sass cache files from tmp/sass-cache for performance
|
13
|
-
# config.sass.read_cache = true
|
14
|
-
# # Display line comments above each selector as a debugging aid
|
15
|
-
# config.sass.line_comments = true
|
16
|
-
# # Initialize the load paths to an empty array
|
17
|
-
# config.sass.load_paths = []
|
18
|
-
# # Send Sass logs to Rails.logger
|
19
|
-
# config.sass.logger = Sass::Rails::Logger.new
|
20
|
-
#
|
21
|
-
# initializer :setup_sass do |app|
|
22
|
-
# # Set the stylesheet engine to the preferred syntax
|
23
|
-
# config.app_generators.stylesheet_engine syntax
|
24
|
-
#
|
25
|
-
# # Set the sass cache location to tmp/sass-cache
|
26
|
-
# config.sass.cache_location = File.join(Rails.root, "tmp/sass-cache")
|
27
|
-
#
|
28
|
-
# # Establish configuration defaults that are evironmental in nature
|
29
|
-
# if config.sass.full_exception.nil?
|
30
|
-
# # Display a stack trace in the css output when in development-like environments.
|
31
|
-
# config.sass.full_exception = app.config.consider_all_requests_local
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# initializer :setup_compression do |app|
|
36
|
-
# if app.config.assets.compress
|
37
|
-
# # Use sass's css_compressor
|
38
|
-
# app.config.assets.css_compressor = CssCompressor.new
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# config.after_initialize do |app|
|
43
|
-
# Sass::logger = app.config.sass.logger
|
44
|
-
# end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
require 'tilt/opal'
|
3
|
-
|
4
|
-
module Opal::Rails
|
5
|
-
|
6
|
-
class Resolver
|
7
|
-
|
8
|
-
attr_accessor :context
|
9
|
-
|
10
|
-
def initialize(context)
|
11
|
-
@context = context
|
12
|
-
end
|
13
|
-
|
14
|
-
def resolve(path, content_type = :self)
|
15
|
-
options = {}
|
16
|
-
options[:content_type] = content_type unless content_type.nil?
|
17
|
-
context.resolve(path, options)
|
18
|
-
rescue Sprockets::FileNotFound, Sprockets::ContentTypeMismatch
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def public_path(path, scope)
|
23
|
-
context.asset_paths.compute_public_path(path, scope)
|
24
|
-
end
|
25
|
-
|
26
|
-
def process(path)
|
27
|
-
context.environment[path].to_s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
Sprockets::Engines #invoke autoloading
|
34
|
-
Sprockets.register_engine '.opal', Tilt::OpalTemplate
|
data/lib/tilt/opal.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'opal'
|
2
|
-
require 'tilt/template'
|
3
|
-
require 'tilt'
|
4
|
-
|
5
|
-
module Tilt
|
6
|
-
# Opal templates do not support object scopes, locals, or yield.
|
7
|
-
class OpalTemplate < ::Tilt::Template
|
8
|
-
self.default_mime_type = 'application/javascript'
|
9
|
-
|
10
|
-
@@default_bare = false
|
11
|
-
|
12
|
-
def self.default_bare
|
13
|
-
@@default_bare
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.default_bare=(value)
|
17
|
-
@@default_bare = value
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.engine_initialized?
|
21
|
-
defined? ::Opal
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize_engine
|
25
|
-
require_template_library 'opal'
|
26
|
-
end
|
27
|
-
|
28
|
-
def prepare
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.opal_core
|
32
|
-
@opal_core ||= Opal::Builder.new.build_core
|
33
|
-
end
|
34
|
-
|
35
|
-
# def builder_evaluate
|
36
|
-
# # require 'stringio'
|
37
|
-
# # out = StringIO.new
|
38
|
-
# #
|
39
|
-
# # opts = options
|
40
|
-
# # builder = Opal::Builder.new
|
41
|
-
# # builder.build :files => path,
|
42
|
-
# # :out => opts["out"], :watch => opts["watch"], :main => opts["main"]
|
43
|
-
# #
|
44
|
-
# #
|
45
|
-
# # # build
|
46
|
-
# # files = options[:files] || []
|
47
|
-
# # files = [files] unless files.is_a? Array
|
48
|
-
# # options[:files] = files = Dir.[](*files)
|
49
|
-
# #
|
50
|
-
# # raise "Opal::Builder - No input files could be found" if files.empty?
|
51
|
-
# #
|
52
|
-
# # main = options[:main]
|
53
|
-
# #
|
54
|
-
# # if main == true
|
55
|
-
# # options[:main] = files.first
|
56
|
-
# # elsif main
|
57
|
-
# # raise "Opal::Builder - Main file does not exist!" unless File.exists? main
|
58
|
-
# # files << main unless files.include? main
|
59
|
-
# # elsif main == false
|
60
|
-
# # options[:main] = false
|
61
|
-
# # else
|
62
|
-
# # options[:main] = files.first
|
63
|
-
# # end
|
64
|
-
# #
|
65
|
-
# # main = options[:main]
|
66
|
-
# #
|
67
|
-
# # unless options[:out]
|
68
|
-
# # options[:out] = main.sub /\.rb$/, '.js'
|
69
|
-
# # end
|
70
|
-
# #
|
71
|
-
# # FileUtils.mkdir_p File.dirname(options[:out])
|
72
|
-
# #
|
73
|
-
# # rebuild options
|
74
|
-
# #
|
75
|
-
# #
|
76
|
-
# #
|
77
|
-
# # # rebuild
|
78
|
-
# #
|
79
|
-
# # puts "rebuilding to #{options[:out]}"
|
80
|
-
# # puts options[:files].inspect
|
81
|
-
# # File.open(options[:out], 'w') do |out|
|
82
|
-
# # # out.write @pre if @pre
|
83
|
-
# #
|
84
|
-
# # options[:files].each do |file|
|
85
|
-
# # out.write wrap_source file
|
86
|
-
# # end
|
87
|
-
# #
|
88
|
-
# # if options[:main]
|
89
|
-
# # main = options[:main].sub(/\.rb$/, '')
|
90
|
-
# # out.write "opal.require('#{main}');\n"
|
91
|
-
# # end
|
92
|
-
# #
|
93
|
-
# # # out.write @post if @post
|
94
|
-
# # end
|
95
|
-
# #
|
96
|
-
# #
|
97
|
-
# end
|
98
|
-
|
99
|
-
def evaluate(scope, locals, &block)
|
100
|
-
return @output if defined? @output
|
101
|
-
|
102
|
-
js_src = Opal::RubyParser.new(data).parse!.generate_top
|
103
|
-
@output = <<-OPAL
|
104
|
-
opal.register('try.rb', function($rb, self, __FILE__) {
|
105
|
-
#{js_src}
|
106
|
-
});
|
107
|
-
opal.require('try');
|
108
|
-
OPAL
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
register OpalTemplate, '.opal'
|
113
|
-
end
|