Class: Opal::Builder

Inherits:
Object show all
Includes:
BuilderProcessors, UseGem
Defined in:
opal/lib/opal/builder.rb

Defined Under Namespace

Classes: MissingRequire

Constant Summary

Constants included from BuilderProcessors

Opal::BuilderProcessors::DEFAULT_PROCESSORS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UseGem

#use_gem

Constructor Details

#initialize(options = nil) ⇒ Builder

Returns a new instance of Builder



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'opal/lib/opal/builder.rb', line 13

def initialize(options = nil)
  (options || {}).each_pair do |k,v|
    public_send("#{k}=", v)
  end

  @stubs             ||= []
  @preload           ||= []
  @processors        ||= DEFAULT_PROCESSORS
  @path_reader       ||= PathReader.new
  @prerequired       ||= []
  @compiler_options  ||= {}
  @default_processor ||= RubyProcessor

  @processed = []
end

Instance Attribute Details

#compiler_optionsObject

Returns the value of attribute compiler_options



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def compiler_options
  @compiler_options
end

#default_processorObject

Returns the value of attribute default_processor



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def default_processor
  @default_processor
end

#path_readerObject

Returns the value of attribute path_reader



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def path_reader
  @path_reader
end

#preloadObject

Returns the value of attribute preload



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def preload
  @preload
end

#prerequiredObject

Returns the value of attribute prerequired



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def prerequired
  @prerequired
end

#processedObject (readonly)

Returns the value of attribute processed



78
79
80
# File 'opal/lib/opal/builder.rb', line 78

def processed
  @processed
end

#processorsObject

Returns the value of attribute processors



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def processors
  @processors
end

#stubsObject

Returns the value of attribute stubs



80
81
82
# File 'opal/lib/opal/builder.rb', line 80

def stubs
  @stubs
end

Class Method Details

.build(*args, &block) ⇒ Object



29
30
31
# File 'opal/lib/opal/builder.rb', line 29

def self.build(*args, &block)
  new.build(*args, &block)
end

Instance Method Details

#append_paths(*paths) ⇒ Object



72
73
74
# File 'opal/lib/opal/builder.rb', line 72

def append_paths(*paths)
  path_reader.append_paths(*paths)
end

#build(path, options = {}) ⇒ Object



33
34
35
36
# File 'opal/lib/opal/builder.rb', line 33

def build(path, options = {})
  source = read(path)
  build_str(source, path, options)
end

#build_require(path, options = {}) ⇒ Object



49
50
51
# File 'opal/lib/opal/builder.rb', line 49

def build_require(path, options = {})
  process_require(path, options)
end

#build_str(source, filename, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'opal/lib/opal/builder.rb', line 38

def build_str source, filename, options = {}
  path = path_reader.expand(filename).to_s unless stub?(filename)
  asset = processor_for(source, filename, path, options)
  requires = preload + asset.requires + tree_requires(asset, path)
  requires.map { |r| process_require(r, options) }
  processed << asset
  self
rescue MissingRequire => error
  raise error, "A file required by #{filename.inspect} wasn't found.\n#{error.message}", error.backtrace
end

#initialize_copy(other) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'opal/lib/opal/builder.rb', line 53

def initialize_copy(other)
  super
  @stubs = other.stubs.dup
  @preload = other.preload.dup
  @processors = other.processors.dup
  @path_reader = other.path_reader.dup
  @prerequired = other.prerequired.dup
  @compiler_options = other.compiler_options.dup
  @processed = other.processed.dup
end

#source_mapObject



68
69
70
# File 'opal/lib/opal/builder.rb', line 68

def source_map
  processed.map(&:source_map).reduce(:+).as_json.to_json
end

#to_sObject



64
65
66
# File 'opal/lib/opal/builder.rb', line 64

def to_s
  processed.map(&:to_s).join("\n")
end