Class: Opal::BuilderProcessors::Processor

Inherits:
Object
  • Object
show all
Defined in:
opal/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, options = {}) ⇒ Processor

Returns a new instance of Processor.



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

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

Class Attribute Details

.extensionsObject (readonly)

Returns the value of attribute extensions.



24
25
26
# File 'opal/lib/opal/builder_processors.rb', line 24

def extensions
  @extensions
end

Instance Attribute Details

#autoloadsObject (readonly)

Returns the value of attribute autoloads.



17
18
19
# File 'opal/lib/opal/builder_processors.rb', line 17

def autoloads
  @autoloads
end

#filenameObject (readonly)

Returns the value of attribute filename.



17
18
19
# File 'opal/lib/opal/builder_processors.rb', line 17

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'opal/lib/opal/builder_processors.rb', line 17

def options
  @options
end

#required_treesObject (readonly)

Returns the value of attribute required_trees.



17
18
19
# File 'opal/lib/opal/builder_processors.rb', line 17

def required_trees
  @required_trees
end

#requiresObject (readonly)

Returns the value of attribute requires.



17
18
19
# File 'opal/lib/opal/builder_processors.rb', line 17

def requires
  @requires
end

#sourceObject (readonly)

Returns the value of attribute source.



17
18
19
# File 'opal/lib/opal/builder_processors.rb', line 17

def source
  @source
end

Class Method Details

.handles(*extensions) ⇒ Object



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

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)


36
37
38
# File 'opal/lib/opal/builder_processors.rb', line 36

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

.match_regexpObject



40
41
42
# File 'opal/lib/opal/builder_processors.rb', line 40

def match_regexp
  @match_regexp || raise(NotImplementedError)
end

Instance Method Details

#mark_as_required(filename) ⇒ Object



45
46
47
# File 'opal/lib/opal/builder_processors.rb', line 45

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

#to_sObject



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

def to_s
  source.to_s
end