Class: Sprockets::CoffeeJsxScript

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/sprockets/coffee-jsx-script.rb

Overview

Preprocessor that runs CJSX source files through coffee-jsx-transform then compiles with coffee-script

Constant Summary collapse

COFFEE_CJSX_EXTENSION =
/\.coffee\.cjsx/
CJSX_EXTENSION =
/\.cjsx[^\/]*?$/
CJSX_PRAGMA =
/^\s*#[ \t]*@cjsx/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(input) ⇒ Object



21
22
23
24
25
# File 'lib/sprockets/coffee-jsx-script.rb', line 21

def self.call(input)
  filename  = input[:source_path] || input[:filename]
  source    = input[:data]
  run(filename, source)
end

.run(filename, source) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/sprockets/coffee-jsx-script.rb', line 27

def self.run(filename, source)
  if filename =~ COFFEE_CJSX_EXTENSION
    ::CoffeeReact.transform(source)
  elsif filename =~ CJSX_EXTENSION || source =~ CJSX_PRAGMA
    ::CoffeeScript.compile(::CoffeeReact.transform(source))
  else
    source
  end
end

Instance Method Details

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



17
18
19
# File 'lib/sprockets/coffee-jsx-script.rb', line 17

def evaluate(scope, locals, &block)
  self.class.run(scope.pathname.to_s, data)
end

#prepareObject



14
15
# File 'lib/sprockets/coffee-jsx-script.rb', line 14

def prepare
end