Class: Opal::Builder

Inherits:
Object show all
Includes:
BuilderProcessors
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

Constructor Details

#initialize(options = nil) ⇒ Builder

Returns a new instance of Builder



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

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



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def compiler_options
  @compiler_options
end

#default_processorObject

Returns the value of attribute default_processor



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def default_processor
  @default_processor
end

#path_readerObject

Returns the value of attribute path_reader



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def path_reader
  @path_reader
end

#preloadObject

Returns the value of attribute preload



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def preload
  @preload
end

#prerequiredObject

Returns the value of attribute prerequired



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def prerequired
  @prerequired
end

#processedObject (readonly)

Returns the value of attribute processed



60
61
62
# File 'opal/lib/opal/builder.rb', line 60

def processed
  @processed
end

#processorsObject

Returns the value of attribute processors



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def processors
  @processors
end

#stubsObject

Returns the value of attribute stubs



62
63
64
# File 'opal/lib/opal/builder.rb', line 62

def stubs
  @stubs
end

Class Method Details

.build(*args, &block) ⇒ Object



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

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

Instance Method Details

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



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

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

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



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

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

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



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

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}"
end

#source_mapObject



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

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

#to_sObject



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

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