From 2bfbd28de259f76255f904fe4ab10c0c0fb6f9b6 Mon Sep 17 00:00:00 2001 From: Ramast Magdy Date: Thu, 9 Jul 2015 21:27:22 +0800 Subject: [PATCH 1/5] Added doc to explain using compressor with facebook react --- docs/index.txt | 1 + docs/reactjs.txt | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 docs/reactjs.txt diff --git a/docs/index.txt b/docs/index.txt index f1adfa4..7cb58f2 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -43,5 +43,6 @@ Contents behind-the-scenes jinja2 django-sekizai + reactjs contributing changelog diff --git a/docs/reactjs.txt b/docs/reactjs.txt new file mode 100644 index 0000000..384e2e6 --- /dev/null +++ b/docs/reactjs.txt @@ -0,0 +1,57 @@ +.. _reactjs_support: + +Facebook React Support +====================== + +Compiling React's jsx files can be done by creating a custom precompressor + +Requirements +------------ +* PyReact>=0.5.2 for compiling jsx files +* PyExecJS>=1.1.0 required by PyReact (automatically installed when using pip) +* A Javascript runtime : options include PyV8, Node.js, PhantomJS among others + + +Full list of supported javascript engines found here https://github.com/doloopwhile/PyExecJS + + +Installation +------------ +1. Place the following code in a python file (ex: third_party/react_compressor.py) also make sure third_party/__init__.py exists + +.. code-block:: django + + from compressor.filters import FilterBase + from react import jsx + + + class ReactFilter(FilterBase): + + def __init__(self, content, *args, **kwargs): + self.content = content + kwargs.pop('filter_type') + super(ReactFilter, self).__init__(content, *args, **kwargs) + + def input(self, **kwargs): + return jsx.transform_string(self.content) + + +2. In your django settings file add the following line + +.. code-block:: django + + COMPRESS_PRECOMPILERS = ( + ('text/jsx', 'third_party.react_compressor.ReactFilter'), + ) + +Where ``third_party.react_compressor.ReactFilter`` is the full name of your ``ReactFilter`` class + + +Troubleshooting +-------------- +If you get file not found errors open your python command line and make sure +you are able to import your ``ReactFilter`` class + +.. code-block:: django + + __import__('third_party.react_compressor.ReactFilter') From b1edac349647a16ddb8fadfe920e69744f48e8e6 Mon Sep 17 00:00:00 2001 From: Ramast Magdy Date: Thu, 9 Jul 2015 22:18:08 +0800 Subject: [PATCH 2/5] added punctuation and other minor changes [ by rfleschenberg ] --- docs/reactjs.txt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/reactjs.txt b/docs/reactjs.txt index 384e2e6..085aabe 100644 --- a/docs/reactjs.txt +++ b/docs/reactjs.txt @@ -3,7 +3,7 @@ Facebook React Support ====================== -Compiling React's jsx files can be done by creating a custom precompressor +Compiling React's jsx files can be done by creating a custom precompressor. Requirements ------------ @@ -12,12 +12,15 @@ Requirements * A Javascript runtime : options include PyV8, Node.js, PhantomJS among others -Full list of supported javascript engines found here https://github.com/doloopwhile/PyExecJS +The full list of supported javascript engines can be found here: https://github.com/doloopwhile/PyExecJS Installation ------------ -1. Place the following code in a python file (ex: third_party/react_compressor.py) also make sure third_party/__init__.py exists +1. Place the following code in a Python file (e.g. + ``third_party/react_compressor.py``). Also make sure that + ``third_party/__init__.py`` exists so the directory is recognized as a + Python package. .. code-block:: django @@ -36,7 +39,7 @@ Installation return jsx.transform_string(self.content) -2. In your django settings file add the following line +2. In your Django settings, add the following line: .. code-block:: django @@ -44,14 +47,15 @@ Installation ('text/jsx', 'third_party.react_compressor.ReactFilter'), ) -Where ``third_party.react_compressor.ReactFilter`` is the full name of your ``ReactFilter`` class +Where ``third_party.react_compressor.ReactFilter`` is the full name of your ``ReactFilter`` class. Troubleshooting --------------- -If you get file not found errors open your python command line and make sure -you are able to import your ``ReactFilter`` class +--------------- +If you get "file not found" errors, open your Python command line and make sure +you are able to import your ``ReactFilter`` class: .. code-block:: django __import__('third_party.react_compressor.ReactFilter') + From 6b7b6aa0a96aab79a342e52cbbb00e710a5716e3 Mon Sep 17 00:00:00 2001 From: Ramast Magdy Date: Thu, 9 Jul 2015 22:26:37 +0800 Subject: [PATCH 3/5] Make supported JS engines link in a seperate line --- docs/reactjs.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reactjs.txt b/docs/reactjs.txt index 085aabe..eeb59e1 100644 --- a/docs/reactjs.txt +++ b/docs/reactjs.txt @@ -12,7 +12,8 @@ Requirements * A Javascript runtime : options include PyV8, Node.js, PhantomJS among others -The full list of supported javascript engines can be found here: https://github.com/doloopwhile/PyExecJS +The full list of supported javascript engines can be found here: + https://github.com/doloopwhile/PyExecJS Installation From 75aff516616785bef11a6be7d91189f1d750832e Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 10 Jul 2015 14:53:59 +0200 Subject: [PATCH 4/5] Add npm/react-tools COMPRESS_PRECOMPILERS example --- docs/reactjs.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/reactjs.txt b/docs/reactjs.txt index eeb59e1..287172e 100644 --- a/docs/reactjs.txt +++ b/docs/reactjs.txt @@ -3,7 +3,20 @@ Facebook React Support ====================== -Compiling React's jsx files can be done by creating a custom precompressor. +Assuming you have `npm` available by following the `react-tools installation instructions`_ and +adding an appropriate ``COMPRESS_PRECOMPILERS`` setting: + +.. code-block:: django + + COMPRESS_PRECOMPILERS = ( + ('text/jsx', 'cat {infile} | jsx > {outfile}'), + ) + + +.. _react-tools installation instructions: http://facebook.github.io/react/docs/tooling-integration.html#productionizing-precompiled-jsx + +If the above approach is not suitable for you, compiling React's jsx files can be done by creating +a custom precompressor. Requirements ------------ @@ -57,6 +70,6 @@ If you get "file not found" errors, open your Python command line and make sure you are able to import your ``ReactFilter`` class: .. code-block:: django - + __import__('third_party.react_compressor.ReactFilter') From 8ae9c0f43b707e99a1011329b9ea5d4918066ab7 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 10 Jul 2015 14:56:51 +0200 Subject: [PATCH 5/5] Add missing sub-sentential fragment. --- docs/reactjs.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/reactjs.txt b/docs/reactjs.txt index 287172e..9a5f6f7 100644 --- a/docs/reactjs.txt +++ b/docs/reactjs.txt @@ -3,8 +3,9 @@ Facebook React Support ====================== -Assuming you have `npm` available by following the `react-tools installation instructions`_ and -adding an appropriate ``COMPRESS_PRECOMPILERS`` setting: +Assuming you have `npm` available, you can integrate React with Django Compressor by following the +`react-tools installation instructions`_ and adding an appropriate ``COMPRESS_PRECOMPILERS`` +setting: .. code-block:: django