Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,25 @@ transformer = jsx.JSXTransformer()
js = transformer.transform_string(jsx)
```

**Django**: PyReact includes a JSX compiler for [django-pipeline](https://github.com/cyberdelia/django-pipeline). It has been tested with django-pipeline 1.3.20, but may work with other versions too. Add it to your project's pipeline settings like this:
**Django**: PyReact includes JSX compilers for [django-pipeline](https://github.com/cyberdelia/django-pipeline) and [django-compressor](https://github.com/django-compressor/django-compressor/).

**django-pipeline**: It has been tested with django-pipeline 1.3.20, but may work with other versions too. Add it to your project's pipeline settings like this:

```python
PIPELINE_COMPILERS = (
'react.utils.pipeline.JSXCompiler',
)
```

**django-compressor**: Compiler was tested with `django-compressor` 1.5. Add this to your Django settings to enable it:

```python
COMPRESS_PRECOMPILERS = (
('text/jsx', 'react.utils.compressor.JSXCompiler'),
)

```


## License

Expand Down
34 changes: 34 additions & 0 deletions react/utils/compressor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2013 Facebook, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import absolute_import


from compressor.filters.base import FilterBase
from react.jsx import JSXTransformer


class JSXCompiler(FilterBase):

def __init__(self, content, attrs=None, filter_type=None, charset=None,
filename=None):
super(JSXCompiler, self).__init__(content, filter_type, filename)
self.transformer = JSXTransformer()

def input(self, **kwargs):
if self.filename:
return self.transformer.transform(self.filename)
else:
return self.transformer.transform_string(self.content)