Sha256: 5e14cfbf90a5c9615edcabdd5e9f21ec90d39c43da93190541bfc197dd7cf908

Contents?: true

Size: 981 Bytes

Versions: 11

Compression:

Stored size: 981 Bytes

Contents

module React
  module JSX
    class JSXTransformer
      DEFAULT_ASSET_PATH = 'JSXTransformer.js'

      def initialize(options)
        @transform_options = {
          stripTypes: options.fetch(:strip_types, false),
          harmony:    options.fetch(:harmony, false),
        }

        @asset_path = options.fetch(:asset_path, DEFAULT_ASSET_PATH)

        # If execjs uses therubyracer, there is no 'global'. Make sure
        # we have it so JSX script can work properly.
        js_code = 'var global = global || this;' + jsx_transform_code
        @context = ExecJS.compile(js_code)
      end


      def transform(code)
        result = @context.call('JSXTransformer.transform', code, @transform_options)
        result["code"]
      end

      def jsx_transform_code
        # search for transformer file using sprockets - allows user to override
        # this file in his own application
        ::Rails.application.assets[@asset_path].to_s
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
react-rails-1.6.0 lib/react/jsx/jsx_transformer.rb
react-rails-1.5.0 lib/react/jsx/jsx_transformer.rb
react-rails-1.4.2 lib/react/jsx/jsx_transformer.rb
react-rails-1.4.1 lib/react/jsx/jsx_transformer.rb
react-rails-1.4.0 lib/react/jsx/jsx_transformer.rb
react-rails-1.3.3 lib/react/jsx/jsx_transformer.rb
react-rails-1.3.2 lib/react/jsx/jsx_transformer.rb
react-rails-1.3.1 lib/react/jsx/jsx_transformer.rb
react-rails-1.3.0 lib/react/jsx/jsx_transformer.rb
react-rails-1.2.0 lib/react/jsx/jsx_transformer.rb
react-rails-1.1.0 lib/react/jsx/jsx_transformer.rb