Module: Opal

Extended by:
UseGem
Defined in:
/Users/elia/Code/opal-docs/opal/lib/opal.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/erb.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/util.rb,
/Users/elia/Code/opal-docs/opal/lib/tilt/opal.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/config.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/parser.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/version.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/builder.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/compiler.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/fragment.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/if.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/top.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/for.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/def.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/call.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/iter.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/case.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/hash.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/source_map.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/base.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/super.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/parser/sexp.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/path_reader.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/class.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/yield.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_options.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/array.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/while.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/logic.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/masgn.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/scope.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_runners.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/rescue.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/module.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/parser/lexer.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/defined.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/arglist.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/literal.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/erb.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/helpers.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/regexp_anchors.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/parser/grammar.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/constants.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/variables.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/parser/keywords.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/server.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/hike_path_finder.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/definitions.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_runners/server.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/call_special.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_runners/nodejs.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/builder_processors.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/parser/parser_scope.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_runners/nashorn.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/processor.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/environment.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/singleton_class.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/nodes/runtime_helpers.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_runners/phantomjs.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/cli_runners/apple_script.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/source_map_server.rb,
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/source_map_header_patch.rb

Overview

Opal is a ruby to javascript compiler, with a runtime for running in any JavaScript environment.

Defined Under Namespace

Modules: BuilderProcessors, CliRunners, Config, ERB, Keywords, Nodes, Sprockets, UseGem, Util Classes: Builder, CLI, CLIOptions, Compiler, Environment, Fragment, HikePathFinder, Lexer, Parser, ParserScope, PathReader, Processor, Server, Sexp, SourceMap, SourceMapServer, TiltTemplate

Constant Summary

VERSION =

WHEN RELEASING: Remember to update RUBY_ENGINE_VERSION in opal/corelib/constants.rb too!

'0.9.0.rc1'
REGEXP_START =
RUBY_ENGINE == 'opal' ? '^' : '\A'.freeze
REGEXP_END =
RUBY_ENGINE == 'opal' ? '$' : '\z'.freeze

Class Method Summary collapse

Methods included from UseGem

use_gem

Class Method Details

.append_path(path) ⇒ Object

Add a file path to opals load path. Any gem containing ruby code that Opal has access to should add a load path through this method. Load paths added here should only be paths which contain code targeted at being compiled by Opal.


18
19
20
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 18

def self.append_path(path)
  append_paths(path)
end

.append_paths(*paths) ⇒ Object

Same as #append_path but can take multiple paths.


23
24
25
26
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 23

def self.append_paths(*paths)
  @paths.concat(paths)
  nil
end

.compile(source, options = {}) ⇒ String

Compile a string of ruby code into javascript.

Examples:


Opal.compile "ruby_code"
# => "string of javascript code"

Parameters:

  • source (String)

    ruby source

  • options (Hash) (defaults to: {})

    compiler options

Returns:

  • (String)

    javascript code

See Also:

  • for compiler options

20
21
22
# File '/Users/elia/Code/opal-docs/opal/lib/opal/compiler.rb', line 20

def self.compile(source, options = {})
  Compiler.new(source, options).compile
end

.core_dirObject


6
7
8
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 6

def self.core_dir
  File.expand_path('../../../opal', __FILE__.untaint)
end

.gem_dirObject


2
3
4
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 2

def self.gem_dir
  File.expand_path('../..', __FILE__.untaint)
end

.pathsObject


61
62
63
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 61

def self.paths
  @paths.dup.freeze
end

.process(asset) ⇒ Object

Deprecated.

7
8
9
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/environment.rb', line 7

def self.process asset
  Environment.new[asset].to_s
end

.reset_paths!Object

Resets Opal.paths to the default value (includes corelib, stdlib, opal/lib)


66
67
68
69
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 66

def self.reset_paths!
  @paths = [core_dir.untaint, std_dir.untaint, gem_dir.untaint]
  nil
end

.std_dirObject


10
11
12
# File '/Users/elia/Code/opal-docs/opal/lib/opal/paths.rb', line 10

def self.std_dir
  File.expand_path('../../../stdlib', __FILE__.untaint)
end