Class: Opal::Processor
- Defined in:
- opal/lib/opal/sprockets/processor.rb
Overview
The Processor class is used to make ruby files (with rb or opal extensions) available to any sprockets based server. Processor will then get passed any ruby source file to build. There are some options you can override globally which effect how certain ruby features are handled:
- method_missing_enabled [true by default]
- optimized_operators_enabled [true by default]
- arity_check_enabled [false by default]
- const_missing_enabled [true by default]
- dynamic_require_severity [true by default]
- source_map_enabled [true by default]
- irb_enabled [false by default]
Class Attribute Summary collapse
- 
  
    
      .arity_check_enabled  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute arity_check_enabled. 
- 
  
    
      .const_missing_enabled  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute const_missing_enabled. 
- 
  
    
      .dynamic_require_severity  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute dynamic_require_severity. 
- 
  
    
      .irb_enabled  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute irb_enabled. 
- 
  
    
      .method_missing_enabled  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute method_missing_enabled. 
- 
  
    
      .source_map_enabled  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute source_map_enabled. 
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(context, locals, &block) ⇒ Object
- #find_opal_require(environment, r) ⇒ Object
- #initialize_engine ⇒ Object
- #prefix ⇒ Object
- #prepare ⇒ Object
- #source_file_url(context) ⇒ Object
- #source_map_url(context) ⇒ Object
- #stubbed_file?(name) ⇒ Boolean
Class Attribute Details
.arity_check_enabled ⇒ Object
Returns the value of attribute arity_check_enabled
| 44 45 46 | # File 'opal/lib/opal/sprockets/processor.rb', line 44 def arity_check_enabled @arity_check_enabled end | 
.const_missing_enabled ⇒ Object
Returns the value of attribute const_missing_enabled
| 45 46 47 | # File 'opal/lib/opal/sprockets/processor.rb', line 45 def const_missing_enabled @const_missing_enabled end | 
.dynamic_require_severity ⇒ Object
Returns the value of attribute dynamic_require_severity
| 46 47 48 | # File 'opal/lib/opal/sprockets/processor.rb', line 46 def dynamic_require_severity @dynamic_require_severity end | 
.irb_enabled ⇒ Object
Returns the value of attribute irb_enabled
| 48 49 50 | # File 'opal/lib/opal/sprockets/processor.rb', line 48 def irb_enabled @irb_enabled end | 
.method_missing_enabled ⇒ Object
Returns the value of attribute method_missing_enabled
| 43 44 45 | # File 'opal/lib/opal/sprockets/processor.rb', line 43 def method_missing_enabled @method_missing_enabled end | 
.source_map_enabled ⇒ Object
Returns the value of attribute source_map_enabled
| 47 48 49 | # File 'opal/lib/opal/sprockets/processor.rb', line 47 def source_map_enabled @source_map_enabled end | 
Class Method Details
.engine_initialized? ⇒ Boolean
| 25 26 27 | # File 'opal/lib/opal/sprockets/processor.rb', line 25 def self.engine_initialized? true end | 
.stub_file(name) ⇒ Object
| 58 59 60 | # File 'opal/lib/opal/sprockets/processor.rb', line 58 def self.stub_file(name) stubbed_files << name.to_s end | 
.stubbed_files ⇒ Object
| 62 63 64 | # File 'opal/lib/opal/sprockets/processor.rb', line 62 def self.stubbed_files @stubbed_files ||= Set.new end | 
Instance Method Details
#evaluate(context, locals, &block) ⇒ Object
| 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | # File 'opal/lib/opal/sprockets/processor.rb', line 66 def evaluate(context, locals, &block) = { :method_missing => self.class.method_missing_enabled, :arity_check => self.class.arity_check_enabled, :const_missing => self.class.const_missing_enabled, :dynamic_require_severity => self.class.dynamic_require_severity, :irb => self.class.irb_enabled, :file => context.logical_path, } compiler = Opal::Compiler.new result = compiler.compile data, compiler.requires.each do |r| next if stubbed_file? r path = find_opal_require context.environment, r context.require_asset path end if self.class.source_map_enabled $OPAL_SOURCE_MAPS[context.pathname] = compiler.source_map(source_file_url(context)).to_s "#{result}\n//# sourceMappingURL=#{source_map_url(context)}\n" else result end end | 
#find_opal_require(environment, r) ⇒ Object
| 109 110 111 112 113 114 115 | # File 'opal/lib/opal/sprockets/processor.rb', line 109 def find_opal_require(environment, r) path = environment.paths.find do |p| File.exist?(File.join(p, "#{r}.rb")) end path ? File.join(path, "#{r}.rb") : r end | 
#initialize_engine ⇒ Object
| 33 34 35 | # File 'opal/lib/opal/sprockets/processor.rb', line 33 def initialize_engine require_template_library 'opal' end | 
#prefix ⇒ Object
| 101 102 103 | # File 'opal/lib/opal/sprockets/processor.rb', line 101 def prefix "/__opal_source_maps__" end | 
#prepare ⇒ Object
| 37 38 | # File 'opal/lib/opal/sprockets/processor.rb', line 37 def prepare end | 
#source_file_url(context) ⇒ Object
| 97 98 99 | # File 'opal/lib/opal/sprockets/processor.rb', line 97 def source_file_url(context) "#{prefix}/#{context.logical_path.to_s}" end | 
#source_map_url(context) ⇒ Object
| 93 94 95 | # File 'opal/lib/opal/sprockets/processor.rb', line 93 def source_map_url(context) "#{prefix}/#{context.logical_path}.js.map" end | 
#stubbed_file?(name) ⇒ Boolean
| 105 106 107 | # File 'opal/lib/opal/sprockets/processor.rb', line 105 def stubbed_file?(name) self.class.stubbed_files.include? name end |