Class: Opal::BuilderProcessors::Processor
- Defined in:
- opal/lib/opal/builder_processors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#required_trees ⇒ Object
readonly
Returns the value of attribute required_trees.
-
#requires ⇒ Object
readonly
Returns the value of attribute requires.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
- .extensions ⇒ Object
- .handles(*extensions) ⇒ Object
- .inherited(processor) ⇒ Object
- .match?(other) ⇒ Boolean
- .match_regexp ⇒ Object
Instance Method Summary collapse
-
#initialize(source, filename, options = {}) ⇒ Processor
constructor
A new instance of Processor.
- #mark_as_required(filename) ⇒ Object
- #source_map ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(source, filename, options = {}) ⇒ Processor
Returns a new instance of Processor
14 15 16 17 18
# File 'opal/lib/opal/builder_processors.rb', line 14 def initialize(source, filename, options = {}) @source, @filename, @options = source, filename, options @requires = [] @required_trees = [] end
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename
19 20 21
# File 'opal/lib/opal/builder_processors.rb', line 19 def filename @filename end
#options ⇒ Object (readonly)
Returns the value of attribute options
19 20 21
# File 'opal/lib/opal/builder_processors.rb', line 19 def options @options end
#required_trees ⇒ Object (readonly)
Returns the value of attribute required_trees
19 20 21
# File 'opal/lib/opal/builder_processors.rb', line 19 def required_trees @required_trees end
#requires ⇒ Object (readonly)
Returns the value of attribute requires
19 20 21
# File 'opal/lib/opal/builder_processors.rb', line 19 def requires @requires end
#source ⇒ Object (readonly)
Returns the value of attribute source
19 20 21
# File 'opal/lib/opal/builder_processors.rb', line 19 def source @source end
Class Method Details
.extensions ⇒ Object
33 34 35
# File 'opal/lib/opal/builder_processors.rb', line 33 def self.extensions @extensions end
.handles(*extensions) ⇒ Object
25 26 27 28 29 30 31
# File 'opal/lib/opal/builder_processors.rb', line 25 def self.handles(*extensions) @extensions = extensions matches = extensions.join('|') matches = "(#{matches})" if extensions.size == 1 @match_regexp = Regexp.new "\\.#{matches}$" end
.inherited(processor) ⇒ Object
10 11 12
# File 'opal/lib/opal/builder_processors.rb', line 10 def self.inherited(processor) DEFAULT_PROCESSORS << processor end
.match?(other) ⇒ Boolean
Returns:
- (Boolean)
37 38 39
# File 'opal/lib/opal/builder_processors.rb', line 37 def self.match? other (other.is_a?(String) and other.match(match_regexp)) end
.match_regexp ⇒ Object
41 42 43
# File 'opal/lib/opal/builder_processors.rb', line 41 def self.match_regexp @match_regexp or raise NotImplementedError end
Instance Method Details
#mark_as_required(filename) ⇒ Object
64 65 66
# File 'opal/lib/opal/builder_processors.rb', line 64 def mark_as_required(filename) "Opal.mark_as_loaded(Opal.normalize_loadable_path(#{filename.to_s.inspect}));" end
#source_map ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
# File 'opal/lib/opal/builder_processors.rb', line 45 def source_map @source_map ||= begin mappings = [] source_file = filename+'.js' line = source.count("\n") column = source.scan("\n[^\n]*$").size offset = ::SourceMap::Offset.new(line, column) mappings << ::SourceMap::Mapping.new(source_file, offset, offset) # Ensure mappings isn't empty: https://github.com/maccman/sourcemap/issues/11 unless mappings.any? zero_offset = ::SourceMap::Offset.new(0,0) mappings = [::SourceMap::Mapping.new(source_file,zero_offset,zero_offset)] end ::SourceMap::Map.new(mappings) end end
#to_s ⇒ Object
21 22 23
# File 'opal/lib/opal/builder_processors.rb', line 21 def to_s source.to_s end