Class: Opal::Processor

Inherits:
Tilt::Template
  • Object
show all
Defined in:
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]
  • arity_check_enabled [false by default]
  • const_missing_enabled [true by default]
  • dynamic_require_severity [:error by default]
  • source_map_enabled [true by default]
  • irb_enabled [false by default]
  • inline_operators_enabled [false by default]

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.arity_check_enabledObject

Returns the value of attribute arity_check_enabled


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

def arity_check_enabled
  @arity_check_enabled
end

.const_missing_enabledObject

Returns the value of attribute const_missing_enabled


48
49
50
# File 'lib/opal/sprockets/processor.rb', line 48

def const_missing_enabled
  @const_missing_enabled
end

.dynamic_require_severityObject

Returns the value of attribute dynamic_require_severity


49
50
51
# File 'lib/opal/sprockets/processor.rb', line 49

def dynamic_require_severity
  @dynamic_require_severity
end

.inline_operators_enabledObject

Returns the value of attribute inline_operators_enabled


52
53
54
# File 'lib/opal/sprockets/processor.rb', line 52

def inline_operators_enabled
  @inline_operators_enabled
end

.irb_enabledObject

Returns the value of attribute irb_enabled


51
52
53
# File 'lib/opal/sprockets/processor.rb', line 51

def irb_enabled
  @irb_enabled
end

.method_missing_enabledObject

Returns the value of attribute method_missing_enabled


46
47
48
# File 'lib/opal/sprockets/processor.rb', line 46

def method_missing_enabled
  @method_missing_enabled
end

.source_map_enabledObject

Returns the value of attribute source_map_enabled


50
51
52
# File 'lib/opal/sprockets/processor.rb', line 50

def source_map_enabled
  @source_map_enabled
end

.source_map_registerObject

Returns the value of attribute source_map_register


54
55
56
# File 'lib/opal/sprockets/processor.rb', line 54

def source_map_register
  @source_map_register
end

Class Method Details

.engine_initialized?Boolean


28
29
30
# File 'lib/opal/sprockets/processor.rb', line 28

def self.engine_initialized?
  true
end

.new_builder(context) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/opal/sprockets/processor.rb', line 101

def self.new_builder(context)
  compiler_options = {
    :method_missing           => method_missing_enabled,
    :arity_check              => arity_check_enabled,
    :const_missing            => const_missing_enabled,
    :dynamic_require_severity => dynamic_require_severity,
    :irb                      => irb_enabled,
    :inline_operators         => inline_operators_enabled,
  }

  path_reader = ::Opal::Sprockets::PathReader.new(context.environment, context)
  return Builder.new(
    compiler_options: compiler_options,
    stubs:            stubbed_files,
    path_reader:      path_reader
  )
end

.stub_file(name) ⇒ Object


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

def self.stub_file(name)
  stubbed_files << name.to_s
end

.stubbed_filesObject


89
90
91
# File 'lib/opal/sprockets/processor.rb', line 89

def self.stubbed_files
  @stubbed_files ||= []
end

.versionObject


32
33
34
# File 'lib/opal/sprockets/processor.rb', line 32

def self.version
  ::Opal::VERSION
end

Instance Method Details

#evaluate(context, locals, &block) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/opal/sprockets/processor.rb', line 68

def evaluate(context, locals, &block)
  return Opal.compile data unless context.is_a? ::Sprockets::Context

  path = context.logical_path
  prerequired = []

  builder = self.class.new_builder(context)
  result = builder.build_str(data, path, :prerequired => prerequired)

  if self.class.source_map_enabled
    register_source_map(context.logical_path, result.source_map.to_s)
    "#{result.to_s}\n//# sourceMappingURL=#{File.basename(context.logical_path)}.map\n"
  else
    result.to_s
  end
end

#initialize_engineObject


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

def initialize_engine
  require_template_library 'opal'
end

#prepareObject


40
41
# File 'lib/opal/sprockets/processor.rb', line 40

def prepare
end

#register_source_map(path, map_contents) ⇒ Object


85
86
87
# File 'lib/opal/sprockets/processor.rb', line 85

def register_source_map path, map_contents
  self.class.source_map_register[path] = map_contents
end

#stubbed_filesObject


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

def stubbed_files
  self.class.stubbed_files
end