Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 33de70d

Browse files
Make react path overridable both at usage and in subclasses
1 parent 988f0a9 commit 33de70d

File tree

4 files changed

+15
-64
lines changed

4 files changed

+15
-64
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ for jsx_path, js_path in my_paths:
3232

3333
# For a single file, you can use a shortcut method.
3434
jsx.transform('path/to/input/file.jsx', js_path='path/to/output/file.js')
35+
36+
# You can also define the path to react.
37+
transformer = jsx.JSXTransformer('path/to/react')
38+
jsx.transform('path/to/input/file.jsx', js_path='path/to/output/file.js', react_path='...')
3539
```
3640

3741
You can also use ``transform_string(jsx)`` method to transform strings:

react/jsx.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os
18+
1719
import execjs
18-
import react.source
1920

2021

2122
class JSXTransformer(object):
2223

2324
JSX_TRANSFORMER_JS_EXPR = '(global.JSXTransformer || module.exports)'
25+
react_path = os.path.abspath(os.path.join(__file__, 'js', 'react'))
2426

25-
def __init__(self):
26-
path = react.source.path_for('JSXTransformer.js')
27-
with open(path, 'rU') as f:
27+
def __init__(self, react_path=None):
28+
if react_path is not None:
29+
self.react_path = react_path
30+
with open(os.path.join(self.react_path, 'JSXTransformer.js'), 'rU') as f:
2831
self.context = execjs.compile(f.read())
2932

3033
def transform_string(self, jsx, harmony=False, strip_types=False):
@@ -62,8 +65,10 @@ class TransformError(Exception):
6265

6366

6467
def transform(jsx_path, **opts):
65-
return JSXTransformer().transform(jsx_path, **opts)
68+
react_path = opts.pop('react_path', None)
69+
return JSXTransformer(react_path=react_path).transform(jsx_path, **opts)
6670

6771

6872
def transform_string(jsx, **opts):
69-
return JSXTransformer().transform_string(jsx, **opts)
73+
react_path = opts.pop('react_path', None)
74+
return JSXTransformer(react_path=react_path).transform_string(jsx, **opts)

react/source.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

react/test/source.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)