Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c168eba5665a^
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ff5c9280d414
Choose a head ref
  • 10 commits
  • 10 files changed
  • 1 contributor

Commits on Apr 9, 2015

  1. Make sprockets ERB processor subclass Processor

    This adds sourcemaps support and other goodies.
    elia committed Apr 9, 2015
    Copy the full SHA
    c168eba View commit details
  2. Copy the full SHA
    97840e7 View commit details

Commits on Apr 12, 2015

  1. Add mspec_phantom to the default task

    Has been broken for a while for good reasons, should never happen again.
    elia committed Apr 12, 2015
    Copy the full SHA
    ccdbdb5 View commit details
  2. Copy the full SHA
    5910a81 View commit details
  3. Copy the full SHA
    751db54 View commit details
  4. Copy the full SHA
    93124ba View commit details
  5. Remove spurious comment

    elia committed Apr 12, 2015
    Copy the full SHA
    e461bde View commit details
  6. Copy the full SHA
    d9805a7 View commit details
  7. Copy the full SHA
    94ba848 View commit details
  8. Copy the full SHA
    ff5c928 View commit details
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -10,4 +10,4 @@ import 'tasks/documenting.rake'
import 'tasks/testing.rake'
import 'tasks/building.rake'

task :default => [:rspec, :mspec_node, :cruby_tests]
task :default => [:rspec, :mspec_node, :cruby_tests, :mspec_phantom]
41 changes: 12 additions & 29 deletions lib/mspec/opal/rake_task.rb
Original file line number Diff line number Diff line change
@@ -37,7 +37,16 @@ def initialize(name, &task_block)

class Runner
def initialize &block
@app = RackApp.new(&block).to_app
@app = Rack::Builder.new do
::Opal::Processor.arity_check_enabled = true
::Opal::Processor.dynamic_require_severity = :raise

use Rack::ShowExceptions
use Rack::ShowStatus
use MSpec::Opal::Index
run MSpec::Opal::Environment.new
end

@port = 9999
end

@@ -86,20 +95,14 @@ def start_phantomjs
end

def start_server
@server = Thread.new do
Rack::Server.start(:app => app, :Port => port, :AccessLog => [],
:Logger => WEBrick::Log.new("/dev/null"))
end
@server = Thread.new { Rack::Server.start(:app => app, :Port => port) }
end
end

class Environment < ::Sprockets::Environment
attr_reader :basedir, :pattern

def initialize(basedir = nil, pattern = nil)
::Opal::Processor.arity_check_enabled = true
::Opal::Processor.dynamic_require_severity = :error

@pattern = pattern
@basedir = basedir = File.expand_path(basedir || DEFAULT_BASEDIR)

@@ -205,27 +208,6 @@ def build_specs file = "#{basedir}/build/specs.js"
end
end

class RackApp < Rack::Builder
attr_accessor :pattern, :basedir

def initialize
self.pattern = nil
self.basedir = DEFAULT_BASEDIR

yield(self) if block_given?
super()

use Rack::ShowExceptions
use Rack::ShowStatus
use Index
run environment
end

def environment
@environment ||= Environment.new(basedir, pattern)
end
end

class Index
HTML = <<-HTML
<!DOCTYPE html>
@@ -236,6 +218,7 @@ class Index
</head>
<body>
<script src="/mspec/opal/main.js"></script>
<script>Opal.load('mspec/opal/main');</script>
</body>
</html>
HTML
6 changes: 6 additions & 0 deletions lib/mspec/opal/special_calls.rb
Original file line number Diff line number Diff line change
@@ -22,6 +22,12 @@ class Opal::Nodes::CallNode
end
end

add_special :not_compliant_on do
unless arglist.flatten.include? :opal
compile_default!
end
end

add_special :platform_is_not do
unless arglist.flatten.include? :opal
compile_default!
1 change: 1 addition & 0 deletions lib/opal/builder.rb
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ def read(path)
end

def process_require(filename, options)
filename.gsub(/\.(rb|js|opal)$/, '')
return if prerequired.include?(filename)
return if already_processed.include?(filename)
already_processed << filename
2 changes: 1 addition & 1 deletion lib/opal/builder_processors.rb
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ def source_map

def compiled
@compiled ||= begin
compiler = compiler_for(@source, file: @filename)
compiler = compiler_for(@source, file: @filename.gsub(/\.(rb|js|opal)$/, ''))
compiler.compile
compiler
end
26 changes: 6 additions & 20 deletions lib/opal/sprockets/erb.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
require 'tilt'
require 'sprockets'
require 'opal/sprockets/processor'

module Opal
module ERB
class Processor < Tilt::Template
# vvv BOILERPLATE vvv
self.default_mime_type = 'application/javascript'

def self.engine_initialized?
true
end

def self.version
::Opal::VERSION
end

class Processor < ::Opal::Processor
def initialize_engine
require_template_library 'opal'
super
require_template_library 'opal/erb'
end

def prepare
end
# ^^^ BOILERPLATE ^^^


def evaluate(context, locals, &block)
context.require_asset 'erb'
Opal::ERB.compile data, context.logical_path.sub(/^templates\//, '')
compiler = Opal::ERB::Compiler.new(@data, context.logical_path.sub(/^templates\//, ''))
@data = compiler.prepared_source
super
end
end
end
51 changes: 48 additions & 3 deletions lib/opal/sprockets/processor.rb
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ def prepare
end
# ^^^ BOILERPLATE ^^^

def self.inherited(subclass)
subclass.default_mime_type = 'application/javascript'
end


class << self
attr_accessor :method_missing_enabled
@@ -80,9 +84,8 @@ def evaluate(context, locals, &block)
compiler = Compiler.new(data, compiler_options)
result = compiler.compile

compiler.requires.each do |required|
context.require_asset required unless stubbed_files.include? required
end
process_requires(compiler.requires, context)
process_required_trees(compiler.required_trees, context)

if self.class.source_map_enabled
map_contents = compiler.source_map.as_json.to_json
@@ -98,6 +101,48 @@ def compiler_options
::Opal::Processor.compiler_options
end

def process_requires(requires, context)
requires.each do |required|
context.require_asset required unless stubbed_files.include? required
end
end

# Mimics (v2) Sprockets::DirectiveProcessor#process_require_tree_directive
def process_required_trees(required_trees, context)
return if required_trees.empty?

# This is the root dir of the logical path, we need this because
# the compiler gives us the path relative to the file's logical path.
dirname = File.dirname(file).gsub(/#{Regexp.escape File.dirname(context.logical_path)}$/, '')
dirname = Pathname(dirname)

required_trees.each do |original_required_tree|
required_tree = Pathname(original_required_tree)

unless required_tree.relative?
raise ArgumentError, "require_tree argument must be a relative path: #{required_tree.inspect}"
end

required_tree = dirname.join(required_tree)

unless required_tree.directory?
raise ArgumentError, "require_tree argument must be a directory: #{[original_required_tree, required_tree].inspect}"
end

context.depend_on required_tree

context.environment.each_entry(required_tree) do |pathname|
if pathname.to_s == file
next
elsif pathname.directory?
context.depend_on(pathname)
elsif context.asset_requirable?(pathname)
context.require_asset(pathname)
end
end
end
end

def self.load_asset_code(sprockets, name)
asset = sprockets[name.sub(/(\.js)?$/, '.js')]
return '' if asset.nil?
7 changes: 4 additions & 3 deletions opal/corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -1194,7 +1194,7 @@
obj = arguments[0];
for (key in obj) {
khash = key.$hash();
map[khash] = obj[khash];
smap[khash] = obj[khash];
keys.push(key);
}
}
@@ -1260,8 +1260,8 @@
// Require system
// --------------
(function(Opal) {
var loaded_features = ['corelib/runtime.js'],
require_table = {'corelib/runtime.js': true},
var loaded_features = ['corelib/runtime'],
require_table = {'corelib/runtime': true},
modules = {};

var current_dir = '.';
@@ -1284,6 +1284,7 @@
path = current_dir.replace(/\/*$/, '/') + path;
}

path = path.replace(/\.(rb|opal|js)$/, '');
parts = path.split(SEPARATOR);

for (var i = 0, ii = parts.length; i < ii; i++) {
12 changes: 11 additions & 1 deletion spec/lib/sprockets/erb_spec.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,17 @@

describe Opal::ERB::Processor do
let(:pathname) { Pathname("/Code/app/mylib/opal/foo.#{ext}") }
let(:_context) { double('_context', :logical_path => "foo.#{ext}", :pathname => pathname) }
let(:environment) { double('environment',
cache: nil,
:[] => nil,
resolve: pathname.expand_path.to_s,
) }
let(:_context) { double('context',
logical_path: "foo.#{ext}",
environment: environment,
pathname: pathname,
is_a?: true,
) }
let(:required_assets) { [] }
let(:template) { described_class.new { |t| %Q{<a href="<%= url %>"><%= name %></a>} } }
before { _context.stub(:require_asset) {|asset| required_assets << asset } }
7 changes: 7 additions & 0 deletions spec/opal/core/runtime_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe '`Opal.hash`' do
it 'converts object literals to hashes' do
`Opal.hash({a: 1, b: 2})`.should == {a: 1, b: 2}
end
end