Class: Opal::BuilderProcessors::RubyProcessor

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

Direct Known Subclasses

OpalERBProcessor

Instance Attribute Summary

Attributes inherited from Processor

#filename, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Processor

extensions, handles, #initialize, #mark_as_required, match_regexp, #to_s

Constructor Details

This class inherits a constructor from Opal::BuilderProcessors::Processor

Class Method Details

.match?(other) ⇒ Boolean

Also catch a files with missing extensions and nil.

Returns:

  • (Boolean)


113
114
115
# File 'opal/lib/opal/builder_processors.rb', line 113

def self.match? other
  super or File.extname(other.to_s) == ''
end

Instance Method Details

#compiledObject



85
86
87
88
89
90
91
# File 'opal/lib/opal/builder_processors.rb', line 85

def compiled
  @compiled ||= begin
    compiler = compiler_for(@source, file: @filename.gsub(/\.(rb|js|opal)#{REGEXP_END}/, ''))
    compiler.compile
    compiler
  end
end

#compiler_classObject



108
109
110
# File 'opal/lib/opal/builder_processors.rb', line 108

def compiler_class
  ::Opal::Compiler
end

#compiler_for(source, options = {}) ⇒ Object



93
94
95
# File 'opal/lib/opal/builder_processors.rb', line 93

def compiler_for(source, options = {})
  compiler_class.new(source, @options.merge(options))
end

#required_treesObject



101
102
103
104
105
106
# File 'opal/lib/opal/builder_processors.rb', line 101

def required_trees
  compiled.required_trees.map do |tree|
    # Remove any leading ./ after joining to dirname
    File.join(File.dirname(@filename), tree).sub(%r{^(\./)*}, '')
  end
end

#requiresObject



97
98
99
# File 'opal/lib/opal/builder_processors.rb', line 97

def requires
  compiled.requires
end

#sourceObject



77
78
79
# File 'opal/lib/opal/builder_processors.rb', line 77

def source
  compiled.result
end

#source_mapObject



81
82
83
# File 'opal/lib/opal/builder_processors.rb', line 81

def source_map
  compiled.source_map.map
end