class Opal::BuilderProcessors::Processor
def self.extensions
def self.extensions @extensions end
def self.handles(*extensions)
def self.handles(*extensions) @extensions = extensions matches = extensions.join('|') matches = "(#{matches})" if extensions.size == 1 @match_regexp = Regexp.new "\\.#{matches}#{REGEXP_END}" end
def self.inherited(processor)
def self.inherited(processor) DEFAULT_PROCESSORS << processor end
def self.match? other
def self.match? other (other.is_a?(String) and other.match(match_regexp)) end
def self.match_regexp
def self.match_regexp @match_regexp or raise NotImplementedError end
def initialize(source, filename, options = {})
def initialize(source, filename, options = {}) @source, @filename, @options = source, filename, options @requires = [] @required_trees = [] end
def mark_as_required(filename)
def mark_as_required(filename) "Opal.mark_as_loaded(Opal.normalize_loadable_path(#{filename.to_s.inspect}));" end
def source_map
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
def to_s
def to_s source.to_s end