Module: Opal

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

Overview

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

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'0.7.0.beta4'

Class Method Summary collapse

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 'lib/opal/paths.rb', line 18

def self.append_path(path)
  paths << path
end

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

Compile a string of ruby code into javascript.

Examples:


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

See Also:

  • for compiler options

20
21
22
# File 'lib/opal/compiler.rb', line 20

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

.core_dirObject


6
7
8
# File 'lib/opal/paths.rb', line 6

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

.gem_dirObject


2
3
4
# File 'lib/opal/paths.rb', line 2

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

.pathsObject

Private, don't add to these directly (use .append_path instead).


45
46
47
# File 'lib/opal/paths.rb', line 45

def self.paths
  @paths ||= [core_dir.untaint, std_dir.untaint, gem_dir.untaint]
end

.process(asset) ⇒ Object

Deprecated.

7
8
9
# File 'lib/opal/sprockets/environment.rb', line 7

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

.require_paths_for_gem(gem_name, include_dependecies) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/opal/paths.rb', line 28

def self.require_paths_for_gem(gem_name, include_dependecies)
  paths = []
  spec = Gem::Specification.find_by_name(gem_name)

  spec.runtime_dependencies.each do |dependency|
    paths += require_paths_for_gem(dependency.name, include_dependecies)
  end if include_dependecies

  gem_dir = spec.gem_dir
  spec.require_paths.map do |path|
    paths << File.join(gem_dir, path)
  end

  paths
end

.std_dirObject


10
11
12
# File 'lib/opal/paths.rb', line 10

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

.use_gem(gem_name, include_dependecies = true) ⇒ Object


22
23
24
25
26
# File 'lib/opal/paths.rb', line 22

def self.use_gem(gem_name, include_dependecies = true)
  require_paths_for_gem(gem_name, include_dependecies).each do |path|
    append_path path
  end
end