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
# 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
  @requires = []
  @required_trees = []
end

Class Attribute Details

.extensionsObject (readonly)

Returns the value of attribute extensions.


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

def extensions
  @extensions
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.


15
16
17
# File 'opal/lib/opal/builder_processors.rb', line 15

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.


15
16
17
# File 'opal/lib/opal/builder_processors.rb', line 15

def options
  @options
end

#required_treesObject (readonly)

Returns the value of attribute required_trees.


15
16
17
# File 'opal/lib/opal/builder_processors.rb', line 15

def required_trees
  @required_trees
end

#requiresObject (readonly)

Returns the value of attribute requires.


15
16
17
# File 'opal/lib/opal/builder_processors.rb', line 15

def requires
  @requires
end

#sourceObject (readonly)

Returns the value of attribute source.


15
16
17
# File 'opal/lib/opal/builder_processors.rb', line 15

def source
  @source
end

Class Method Details

.handles(*extensions) ⇒ Object


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

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)

34
35
36
# File 'opal/lib/opal/builder_processors.rb', line 34

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

.match_regexpObject


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

def match_regexp
  @match_regexp || raise(NotImplementedError)
end

Instance Method Details

#mark_as_required(filename) ⇒ Object


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

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

#to_sObject


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

def to_s
  source.to_s
end