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
9
10
11
12
13
|
# File 'opal/lib/opal/builder_processors.rb', line 9
def initialize(source, filename, options = {})
@source, @filename, @options = source, filename, options
@requires = []
@required_trees = []
end
|
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename
14
15
16
|
# File 'opal/lib/opal/builder_processors.rb', line 14
def filename
@filename
end
|
#options ⇒ Object
Returns the value of attribute options
14
15
16
|
# File 'opal/lib/opal/builder_processors.rb', line 14
def options
@options
end
|
#required_trees ⇒ Object
Returns the value of attribute required_trees
14
15
16
|
# File 'opal/lib/opal/builder_processors.rb', line 14
def required_trees
@required_trees
end
|
#requires ⇒ Object
Returns the value of attribute requires
14
15
16
|
# File 'opal/lib/opal/builder_processors.rb', line 14
def requires
@requires
end
|
#source ⇒ Object
Returns the value of attribute source
14
15
16
|
# File 'opal/lib/opal/builder_processors.rb', line 14
def source
@source
end
|
Class Method Details
.extensions ⇒ Object
30
31
32
|
# File 'opal/lib/opal/builder_processors.rb', line 30
def self.extensions
@extensions
end
|
.handles(*extensions) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'opal/lib/opal/builder_processors.rb', line 20
def self.handles(*extensions)
@extensions = extensions
matches = extensions.join('|')
matches = "(#{matches})" if extensions.size == 1
@match_regexp = Regexp.new "\\.#{matches}#{REGEXP_END}"
::Opal::Builder.register_processor(self, extensions)
nil
end
|
.match?(other) ⇒ Boolean
34
35
36
|
# File 'opal/lib/opal/builder_processors.rb', line 34
def self.match? other
(other.is_a?(String) and other.match(match_regexp))
end
|
.match_regexp ⇒ Object
38
39
40
|
# File 'opal/lib/opal/builder_processors.rb', line 38
def self.match_regexp
@match_regexp or raise NotImplementedError
end
|
Instance Method Details
#mark_as_required(filename) ⇒ Object
61
62
63
|
# File 'opal/lib/opal/builder_processors.rb', line 61
def mark_as_required(filename)
"Opal.loaded([#{filename.to_s.inspect}]);"
end
|
#source_map ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'opal/lib/opal/builder_processors.rb', line 42
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
|
#to_s ⇒ Object
16
17
18
|
# File 'opal/lib/opal/builder_processors.rb', line 16
def to_s
source.to_s
end
|