Class: Opal::Builder
- 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
-
#compiler_options ⇒ Object
Returns the value of attribute compiler_options.
-
#default_processor ⇒ Object
Returns the value of attribute default_processor.
-
#path_reader ⇒ Object
Returns the value of attribute path_reader.
-
#preload ⇒ Object
Returns the value of attribute preload.
-
#prerequired ⇒ Object
Returns the value of attribute prerequired.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
-
#processors ⇒ Object
Returns the value of attribute processors.
-
#stubs ⇒ Object
Returns the value of attribute stubs.
Class Method Summary collapse
Instance Method Summary collapse
- #build(path, options = {}) ⇒ Object
- #build_require(path, options = {}) ⇒ Object
- #build_str(source, filename, options = {}) ⇒ Object
-
#initialize(options = nil) ⇒ Builder
constructor
A new instance of Builder.
- #source_map ⇒ Object
- #to_s ⇒ Object
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( = nil) ( || {}).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_options ⇒ Object
Returns the value of attribute compiler_options
62 63 64 |
# File 'opal/lib/opal/builder.rb', line 62 def @compiler_options end |
#default_processor ⇒ Object
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_reader ⇒ Object
Returns the value of attribute path_reader
62 63 64 |
# File 'opal/lib/opal/builder.rb', line 62 def path_reader @path_reader end |
#preload ⇒ Object
Returns the value of attribute preload
62 63 64 |
# File 'opal/lib/opal/builder.rb', line 62 def preload @preload end |
#prerequired ⇒ Object
Returns the value of attribute prerequired
62 63 64 |
# File 'opal/lib/opal/builder.rb', line 62 def prerequired @prerequired end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed
60 61 62 |
# File 'opal/lib/opal/builder.rb', line 60 def processed @processed end |
#processors ⇒ Object
Returns the value of attribute processors
62 63 64 |
# File 'opal/lib/opal/builder.rb', line 62 def processors @processors end |
#stubs ⇒ Object
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, = {}) source = read(path) build_str(source, path, ) end |
#build_require(path, options = {}) ⇒ Object
48 49 50 |
# File 'opal/lib/opal/builder.rb', line 48 def build_require(path, = {}) process_require(path, ) 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, = {} path = path_reader.(filename).to_s unless stub?(filename) asset = processor_for(source, filename, path, ) requires = preload + asset.requires + tree_requires(asset, path) requires.map { |r| process_require(r, ) } processed << asset self rescue MissingRequire => error raise error, "A file required by #{filename.inspect} wasn't found.\n#{error.}" end |
#source_map ⇒ Object
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_s ⇒ Object
52 53 54 |
# File 'opal/lib/opal/builder.rb', line 52 def to_s processed.map(&:to_s).join("\n") end |