Class: Sprockets::CoffeeJsx

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

Overview

Preprocessor that runs CJSX source files through coffee-jsx-transform

Defined Under Namespace

Classes: Engine

Constant Summary collapse

CJSX_EXTENSION =
/\.(:?cjsx|coffee)[^\/]*?$/
CJSX_PRAGMA =
/^\s*#[ \t]*@cjsx/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(input) ⇒ Object



19
20
21
22
23
# File 'lib/sprockets/coffee-jsx.rb', line 19

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

.install(environment = ::Sprockets) ⇒ Object



33
34
35
# File 'lib/sprockets/coffee-jsx.rb', line 33

def self.install(environment = ::Sprockets)
  Sprockets::CoffeeJsx::Engine.install(environment)
end

.run(filename, source) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/sprockets/coffee-jsx.rb', line 25

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

Instance Method Details

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



15
16
17
# File 'lib/sprockets/coffee-jsx.rb', line 15

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

#prepareObject



12
13
# File 'lib/sprockets/coffee-jsx.rb', line 12

def prepare
end