Class: Opal::BuilderProcessors::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/opal/builder_processors.rb

Direct Known Subclasses

ERBProcessor, JsProcessor, RubyProcessor

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, filename, abs_path = nil, options = {}) ⇒ Processor

Returns a new instance of Processor.



9
10
11
12
13
14
15
16
17
18
# File 'lib/opal/builder_processors.rb', line 9

def initialize(source, filename, abs_path = nil, options = {})
  options = abs_path if abs_path.is_a? Hash

  source += "\n" unless source.end_with?("\n")
  @source, @filename, @abs_path, @options = source, filename, abs_path, options.dup
  @cache = @options.delete(:cache) { Opal.cache }
  @requires = []
  @required_trees = []
  @autoloads = []
end

Class Attribute Details

.extensionsObject (readonly)

Returns the value of attribute extensions.



26
27
28
# File 'lib/opal/builder_processors.rb', line 26

def extensions
  @extensions
end

Instance Attribute Details

#abs_pathObject (readonly)

Returns the value of attribute abs_path.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def abs_path
  @abs_path
end

#autoloadsObject (readonly)

Returns the value of attribute autoloads.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def autoloads
  @autoloads
end

#filenameObject (readonly)

Returns the value of attribute filename.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def options
  @options
end

#required_treesObject (readonly)

Returns the value of attribute required_trees.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def required_trees
  @required_trees
end

#requiresObject (readonly)

Returns the value of attribute requires.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def requires
  @requires
end

#sourceObject (readonly)

Returns the value of attribute source.



19
20
21
# File 'lib/opal/builder_processors.rb', line 19

def source
  @source
end

Class Method Details

.handles(*extensions) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/opal/builder_processors.rb', line 28

def handles(*extensions)
  @extensions = extensions
  matches = extensions.join('|')
  matches = "(#{matches})" unless extensions.size == 1
  @match_regexp = Regexp.new "\\.#{matches}#{REGEXP_END}"

  ::Opal::Builder.register_processor(self, extensions)
  nil
end

.match?(other) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/opal/builder_processors.rb', line 38

def match?(other)
  other.is_a?(String) && other.match(match_regexp)
end

.match_regexpObject



42
43
44
# File 'lib/opal/builder_processors.rb', line 42

def match_regexp
  @match_regexp || raise(NotImplementedError)
end

Instance Method Details

#mark_as_required(filename) ⇒ Object



47
48
49
# File 'lib/opal/builder_processors.rb', line 47

def mark_as_required(filename)
  "Opal.loaded([#{filename.to_s.inspect}]);"
end

#to_sObject



21
22
23
# File 'lib/opal/builder_processors.rb', line 21

def to_s
  source.to_s
end