Class: Opal::Builder

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

Constant Summary

Constants included from BuilderProcessors

Opal::BuilderProcessors::DEFAULT_PROCESSORS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Builder


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/opal/builder.rb', line 9

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

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

  @processed = []
end

Instance Attribute Details

#compiler_optionsObject

Returns the value of attribute compiler_options


57
58
59
# File 'lib/opal/builder.rb', line 57

def compiler_options
  @compiler_options
end

#default_processorObject

Returns the value of attribute default_processor


57
58
59
# File 'lib/opal/builder.rb', line 57

def default_processor
  @default_processor
end

#path_readerObject

Returns the value of attribute path_reader


57
58
59
# File 'lib/opal/builder.rb', line 57

def path_reader
  @path_reader
end

#preloadObject

Returns the value of attribute preload


57
58
59
# File 'lib/opal/builder.rb', line 57

def preload
  @preload
end

#prerequiredObject

Returns the value of attribute prerequired


57
58
59
# File 'lib/opal/builder.rb', line 57

def prerequired
  @prerequired
end

#processedObject (readonly)

Returns the value of attribute processed


55
56
57
# File 'lib/opal/builder.rb', line 55

def processed
  @processed
end

#processorsObject

Returns the value of attribute processors


57
58
59
# File 'lib/opal/builder.rb', line 57

def processors
  @processors
end

#stubsObject

Returns the value of attribute stubs


57
58
59
# File 'lib/opal/builder.rb', line 57

def stubs
  @stubs
end

Class Method Details

.build(*args, &block) ⇒ Object


25
26
27
# File 'lib/opal/builder.rb', line 25

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

Instance Method Details

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


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

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

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


43
44
45
# File 'lib/opal/builder.rb', line 43

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

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


34
35
36
37
38
39
40
41
# File 'lib/opal/builder.rb', line 34

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
end

#source_mapObject


51
52
53
# File 'lib/opal/builder.rb', line 51

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

#to_sObject


47
48
49
# File 'lib/opal/builder.rb', line 47

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