Class: Opal::BuilderProcessors::Processor
- Inherits:
-
Object
- Object
- Opal::BuilderProcessors::Processor
show all
- Defined in:
- opal/lib/opal/builder_processors.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
Returns the value of attribute filename
19
20
21
|
# File 'opal/lib/opal/builder_processors.rb', line 19
def filename
@filename
end
|
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
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
|
Returns the value of attribute requires
19
20
21
|
# File 'opal/lib/opal/builder_processors.rb', line 19
def requires
@requires
end
|
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
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)
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
|
21
22
23
|
# File 'opal/lib/opal/builder_processors.rb', line 21
def to_s
source.to_s
end
|