Class: Opal::Builder
- Inherits:
-
Object
- Object
- Opal::Builder
- Includes:
- UseGem
- Defined in:
- opal/lib/opal/builder.rb
Defined Under Namespace
Classes: MissingRequire, ProcessorNotFound
Instance Attribute Summary collapse
-
#compiler_options ⇒ Object
Returns the value of attribute compiler_options.
-
#missing_require_severity ⇒ Object
Returns the value of attribute missing_require_severity.
-
#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
- .build(*args, &block) ⇒ Object
-
.extensions ⇒ Object
All the extensions supported by registered processors.
-
.processors ⇒ Object
The registered processors.
-
.register_processor(processor, processor_extensions) ⇒ Object
Register a builder processor and the supported extensions.
Instance Method Summary collapse
- #append_paths(*paths) ⇒ Object
- #build(path, options = {}) ⇒ Object
- #build_require(path, options = {}) ⇒ Object
- #build_str(source, rel_path, options = {}) ⇒ Object
-
#initialize(options = nil) ⇒ Builder
constructor
A new instance of Builder.
- #initialize_copy(other) ⇒ Object
-
#source_for(path) ⇒ Object
Retrieve the source for a given path the same way #build would do.
- #source_map ⇒ Object
- #to_s ⇒ Object
Methods included from UseGem
Constructor Details
#initialize(options = nil) ⇒ Builder
Returns a new instance of Builder.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'opal/lib/opal/builder.rb', line 61 def initialize( = nil) ( || {}).each_pair do |k, v| public_send("#{k}=", v) end @stubs ||= [] @preload ||= [] @processors ||= ::Opal::Builder.processors @path_reader ||= PathReader.new(Opal.paths, extensions.map { |e| [".#{e}", ".js.#{e}"] }.flatten) @prerequired ||= [] @compiler_options ||= Opal::Config. @missing_require_severity ||= Opal::Config.missing_require_severity @processed = [] end |
Instance Attribute Details
#compiler_options ⇒ Object
Returns the value of attribute compiler_options.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def @compiler_options end |
#missing_require_severity ⇒ Object
Returns the value of attribute missing_require_severity.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def missing_require_severity @missing_require_severity end |
#path_reader ⇒ Object
Returns the value of attribute path_reader.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def path_reader @path_reader end |
#preload ⇒ Object
Returns the value of attribute preload.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def preload @preload end |
#prerequired ⇒ Object
Returns the value of attribute prerequired.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def prerequired @prerequired end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
133 134 135 |
# File 'opal/lib/opal/builder.rb', line 133 def processed @processed end |
#processors ⇒ Object
Returns the value of attribute processors.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def processors @processors end |
#stubs ⇒ Object
Returns the value of attribute stubs.
135 136 137 |
# File 'opal/lib/opal/builder.rb', line 135 def stubs @stubs end |
Class Method Details
.build(*args, &block) ⇒ Object
77 78 79 |
# File 'opal/lib/opal/builder.rb', line 77 def self.build(*args, &block) new.build(*args, &block) end |
.extensions ⇒ Object
All the extensions supported by registered processors
16 17 18 |
# File 'opal/lib/opal/builder.rb', line 16 def self.extensions @extensions ||= [] end |
.processors ⇒ Object
The registered processors
11 12 13 |
# File 'opal/lib/opal/builder.rb', line 11 def self.processors @processors ||= [] end |
.register_processor(processor, processor_extensions) ⇒ Object
Register a builder processor and the supported extensions. A processor will respond to:
#requires
An array of string containing the logic paths of required assets
#required_trees
An array of string containing the logic paths of required directories
#to_s
The processed source
#source_map
An instance of ::Opal::SourceMap::File
representing the processd asset's source
map.
.new(source, filename, compiler_options)
The processor will be instantiated passing:
- the unprocessed source
- the asset's filename
- Opal's compiler options
.match?(path)
The processor is able to recognize paths suitable for its type of processing.
47 48 49 50 51 |
# File 'opal/lib/opal/builder.rb', line 47 def self.register_processor(processor, processor_extensions) return if processors.include?(processor) processors << processor processor_extensions.each { |ext| extensions << ext } end |
Instance Method Details
#append_paths(*paths) ⇒ Object
127 128 129 |
# File 'opal/lib/opal/builder.rb', line 127 def append_paths(*paths) path_reader.append_paths(*paths) end |
#build(path, options = {}) ⇒ Object
81 82 83 |
# File 'opal/lib/opal/builder.rb', line 81 def build(path, = {}) build_str(source_for(path), path, ) end |
#build_require(path, options = {}) ⇒ Object
103 104 105 |
# File 'opal/lib/opal/builder.rb', line 103 def build_require(path, = {}) process_require(path, ) end |
#build_str(source, rel_path, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'opal/lib/opal/builder.rb', line 90 def build_str(source, rel_path, = {}) return if source.nil? abs_path = (rel_path) rel_path = (rel_path) asset = processor_for(source, rel_path, abs_path, ) requires = preload + asset.requires + tree_requires(asset, abs_path) requires.map { |r| process_require(r, ) } processed << asset self rescue MissingRequire => error raise error, "A file required by #{rel_path.inspect} wasn't found.\n#{error.}", error.backtrace end |
#initialize_copy(other) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'opal/lib/opal/builder.rb', line 107 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..dup @missing_require_severity = other.missing_require_severity.to_sym @processed = other.processed.dup end |
#source_for(path) ⇒ Object
Retrieve the source for a given path the same way #build would do.
86 87 88 |
# File 'opal/lib/opal/builder.rb', line 86 def source_for(path) read(path) end |
#source_map ⇒ Object
123 124 125 |
# File 'opal/lib/opal/builder.rb', line 123 def source_map ::Opal::SourceMap::Index.new(processed.map(&:source_map), join: "\n") end |
#to_s ⇒ Object
119 120 121 |
# File 'opal/lib/opal/builder.rb', line 119 def to_s processed.map(&:to_s).join("\n") end |