Skip to content

Commit

Permalink
Fix multiple typos and spelling mistakes. (#35)
Browse files Browse the repository at this point in the history
* Fix multiple typos and spelling mistakes.

* Fix URL scheme.

* Add dependency, since in tox 4 this will throw an error.

* Add flask_wtf dependency. Flask-CKEditor does not depend on it, but the unittest does.

* Remove whitespace from lines 249 and 277. It causes Travis builds to fail ('W293 blank line contains whitespace').
  • Loading branch information
remyzandwijk authored Apr 16, 2020
1 parent c762c79 commit 086eb0c
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Flask-CKEditor

CKEditor integration for Flask, including image upload, code syntax highlight and more.
CKEditor integration for Flask, including image upload, code syntax highlighting and more.

## Links

Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/sidebarintro.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h3>About</h3>
<p>
CKEditor integration for Flask, add support to image upload, code syntax
highlight and more.
highlighting and more.
</p>
<h3>Useful Links</h3>
<ul>
Expand Down
8 changes: 4 additions & 4 deletions docs/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ a CKEditor object and then separately initialize it for an app:
Include CKEditor Resources
--------------------------

In the template which you want to put a CKEditor textarea, call ``ckeditor.load()``
In the template in which you want to put a CKEditor textarea, call ``ckeditor.load()``
in ``<head></head>`` or before ``</body>``:

.. code-block:: jinja
Expand All @@ -51,15 +51,15 @@ in ``<head></head>`` or before ``</body>``:
{{ ckeditor.load() }}
</body>
In default, it will load the CKEditor resources from CND (cdn.ckeditor.com), you can set ``CKEDITOR_SERVE_LOCAL``
By default, it will load the CKEditor resources from CND (cdn.ckeditor.com), you can set ``CKEDITOR_SERVE_LOCAL``
to True to use built-in resources. You can use ``custom_url`` to load your custom CKEditor build:

.. code-block:: jinja
{{ ckeditor.load(custom_url=url_for('static', filename='ckeditor/ckeditor.js')) }}
CKEditor provide three type of preset (i.e. ``basic``, ``standard`` and ``full``), this method default to load ``standard``.
CKEditor provides three types of preset (i.e. ``basic``, ``standard`` and ``full``), this method defaults to load ``standard``.
You can use `pkg_type` parameter or ``CKEDITOR_PKG_TYPE`` configuration variable to set the package type. For example:

.. code-block:: jinja
Expand Down Expand Up @@ -96,7 +96,7 @@ It's quite simple, just call ``ckeditor.create()`` in the template:
Get the Data
------------

Since the CKEditor textarea is just a normal ``<textarea>`` element, so you can get the data
Since the CKEditor textarea is just a normal ``<textarea>`` element, you can get the data
from ``request.form`` by passing ``ckeditor`` as key:

.. code-block:: python
Expand Down
31 changes: 15 additions & 16 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Configuration
Register Configuration
-----------------------

Except ``CKEDITOR_SERVE_LOCAL`` and ``CKEDITOR_PKG_TYPE``, when you use other configuration variable,
you have to call ``ckeditor.config()`` in template to make them register with CKEditor:
Except for ``CKEDITOR_SERVE_LOCAL`` and ``CKEDITOR_PKG_TYPE``, when you use other configuration variables,
you have to call ``ckeditor.config()`` in the template to make them register with CKEditor:

.. code-block:: jinja
Expand All @@ -24,22 +24,22 @@ you have to call ``ckeditor.config()`` in template to make them register with CK
Available Configuration
------------------------

The configuration options available were listed below:
The configuration options available are listed below:

=============================== ======================= =========================================================================================================================================================================
Name Default Value Info
=============================== ======================= =========================================================================================================================================================================
CKEDITOR_SERVE_LOCAL ``False`` Flag used to set serve resources from local when use ``ckeditor.load()``, default to retrieve from CDN.
CKEDITOR_PKG_TYPE ``'standard'`` The package type of CKEditor, one of ``basic``, ``standard`` and ``full``.
CKEDITOR_SERVE_LOCAL ``False`` Flag used to enable serving resources from local when use ``ckeditor.load()``, default is to retrieve from CDN.
CKEDITOR_PKG_TYPE ``'standard'`` The package type of CKEditor, one of ``basic``, ``standard`` or ``full``.
CKEDITOR_LANGUAGE ``None`` The lang code string to set UI language in ISO 639 format, for example: ``zh``, ``en``, ``jp`` etc. Leave it unset to enable auto detection by user's browser setting.
CKEDITOR_HEIGHT CKEditor default The height of CKEditor textarea, in pixel.
CKEDITOR_WIDTH CKEditor default The width of CKEditor textarea, in pixel.
CKEDITOR_FILE_UPLOADER ``None`` The URL or endpoint that handle file upload.
CKEDITOR_FILE_BROWSER ``None`` The URL or endpoint that handle file browser.
CKEDITOR_FILE_UPLOADER ``None`` The URL or endpoint that handles file upload.
CKEDITOR_FILE_BROWSER ``None`` The URL or endpoint that handles file browser.
CKEDITOR_ENABLE_CODESNIPPET ``False`` Flag used to enable codesnippet plugin, the plugin must be installed (included in built-in resources).
CKEDITOR_CODE_THEME ``'monokai_sublime'`` Set code snippet highlight theme when codesnippet plugin was enabled.
CKEDITOR_EXTRA_PLUGINS ``[]`` A list of extra plugins used in CKEditor, the plugins must be installed.
CKEDITOR_ENABLE_CSRF ``False`` Flag used to enable CSRF protect for image uploading, see :doc:`/plugins` for more details.
CKEDITOR_ENABLE_CSRF ``False`` Flag used to enable CSRF protection for image uploading, see :doc:`/plugins` for more details.
CKEDITOR_UPLOAD_ERROR_MESSAGE ``'Upload failed.'`` Default error message for failed upload.
=============================== ======================= =========================================================================================================================================================================

Expand All @@ -58,18 +58,18 @@ Keep it mind that the proper syntax for each option is
``configuration name : configuration value``. You can use comma to
separate multiple key-value pairs. See the list of available
configuration settings on `CKEditor
documentation <https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config%3E>`_.
documentation <https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html>`_.


Configuring Multiple Text Area
--------------------------------

If you need create multiple text area in one page, here are some tips:
If you need to create multiple text areas in one page, here are some tips:

Without Flask-WTF/WTForms
##########################

Create two text area with different name and configure it with the name:
Create two text areas with different name and configure them with a unique name:

.. code-block:: jinja
Expand All @@ -88,8 +88,8 @@ Create two text area with different name and configure it with the name:
With Flask-WTF/WTForms
#######################

When create multiple form with Flask-WTF/WTForms, you just need to create
multiple ``CKEditorField`` field:
When creating multiple forms with Flask-WTF/WTForms, you just need to create
multiple ``CKEditorField`` fields:

.. code-block:: python
Expand Down Expand Up @@ -119,10 +119,9 @@ In the template, you render them and configure them with the right name:
Overwriting Global Configurations
----------------------------------
Sometimes you may want to use different configuration for multiple text area, in this case, you can
pass the specific keyword arguments into ``ckeditor.config()`` directly.
Sometimes you may want to use a different configuration for multiple text areas, in this case, you can pass the specific keyword arguments into ``ckeditor.config()`` directly.

The keyword arguments should mapping the corresponding configration variable in this way:
The keyword arguments should map the corresponding configuration variables in this way:

- CKEDITOR_LANGUAGE --> language
- CKEDITOR_WIDTH --> width
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Flask-CKEditor
==============

CKEditor integration for Flask, add support to image upload, code syntax
highlight and more.
highlighting and more.

Contents
---------
Expand Down
60 changes: 24 additions & 36 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Image Upload
CKEditor >= 4.5
################

The bulit-in CKEditor package include a `File
The built-in CKEditor package includes a `File
Browser <https://ckeditor.com/addon/filebrowser>`__ plugin. With this plugin,
you can upload and insert image with image widget. You need set
``CKEDITOR_FILE_UPLOADER`` to the URL or endpoint which handle upload
you can upload and insert images with the image widget. You need to set
``CKEDITOR_FILE_UPLOADER`` to the URL or endpoint which handles uploading
files, and the upload view must return ``upload_success()`` call with
the uploaded image's url. Usually, you also need to validate uploaded
the url of the uploaded image. Usually, you also need to validate the uploaded
image, then you can use ``upload_fail()`` to return an error message
with ``message`` argument. If ``message`` was ``None``, the value in
configuration variable ``CKEDITOR_UPLOAD_ERROR_MESSAGE`` will be used,
default to ``Upload failed.``. Here is the full example:
with the ``message`` argument. If ``message`` was ``None``, the value in
the configuration variable ``CKEDITOR_UPLOAD_ERROR_MESSAGE`` will be used,
defaults to ``Upload failed.``. Here is the full example:

.. code-block:: python
Expand All @@ -33,17 +33,17 @@ default to ``Upload failed.``. Here is the full example:
def upload():
f = request.files.get('upload')
# Add more validations here
extension = f.filename.split('.')[1].lower()
extension = f.filename.split('.')[-1].lower()
if extension not in ['jpg', 'gif', 'png', 'jpeg']:
return upload_fail(message='Image only!')
f.save(os.path.join('/the/uploaded/directory', f.filename))
url = url_for('uploaded_files', filename=f.filename)
return upload_success(url=url) # return upload_success call
.. note:: The key pass to ``request.files.get()`` must be ``'upload'``,
.. note:: The key passed to ``request.files.get()`` must be ``'upload'``,
it's defined by CKEditor and it's not the name of the view function.

In the template, you have to call ``ckeditor.config()`` to make configuration work:
In the template, you have to call ``ckeditor.config()`` to make the configuration work:

.. code-block:: jinja
Expand All @@ -55,8 +55,8 @@ In the template, you have to call ``ckeditor.config()`` to make configuration wo
If you create the CKEditor through ``ckeditor.create()``, the default value (``ckeditor``)
will be used.

Now you will find the ``Upload`` tab appear in image widget. Besides,
you can drag and drop image directly into the editor area or copy and
Now you will find the ``Upload`` tab appear in the image widget. Besides,
you can drag and drop the image directly into the editor area or copy and
paste the image (CKEditor >= 4.5).

.. tip:: Check the demo application at ``examples/image-upload/``.
Expand All @@ -65,9 +65,7 @@ paste the image (CKEditor >= 4.5).
CKEditor < 4.5
###############

If the CKEditor version you use was under 4.5, you will need to use ``@ckeditor.uploader``
to decorated the view function that handle the file upload. The upload view must return the
uploaded image's url. For example:
If the CKEditor version you use is below 4.5, you will need to use ``@ckeditor.uploader`` to decorate the view function that handles the file upload. The upload view must return the url of the uploaded image. For example:

.. code-block:: python
Expand All @@ -88,13 +86,12 @@ uploaded image's url. For example:
url = url_for('uploaded_files', filename=f.filename)
return url
You can use configuration variable ``CKEDITOR_UPLOAD_ERROR_MESSAGE`` to customize the error
message when upload failed, default to ``Upload failed.``
You can use the configuration variable ``CKEDITOR_UPLOAD_ERROR_MESSAGE`` to customize the error message when the upload failed, it defaults to ``Upload failed.``

.. note:: The key pass to ``request.files.get()`` must be ``'upload'``,
.. note:: The key passed to ``request.files.get()`` must be ``'upload'``,
it's defined by CKEditor and it's not the name of the view function.

In the template, you have to call ``ckeditor.config()`` to make configuration work:
In the template, you have to call ``ckeditor.config()`` to make the configuration work:

.. code-block:: jinja
Expand All @@ -103,18 +100,17 @@ In the template, you have to call ``ckeditor.config()`` to make configuration wo
.. tip::
When using Flask-WTF/WTForms, you have to pass the field name as
``name`` in ``ckeditor.config()``, for example ``ckeditor.config(name='description')``.
If you create the CKEditor through ``ckeditor.create()``, the default value (``ckeditor``)
will be used.
If you create the CKEditor through ``ckeditor.create()``, the default value (``ckeditor``) will be used.

Now you will find the ``Upload`` tab appear in image widget.
Now you will find the ``Upload`` tab appear in the image widget.


CSRF Protect for Image Upload
------------------------------
CSRF Protection for Image Upload
--------------------------------

Required version: CKEditor >= 4.9.0

The CSRF Protect feature was provided by Flask-WTF's ``CSRFProtect``
The CSRF Protection feature was provided by Flask-WTF's ``CSRFProtect``
extension, so you have to install Flask-WTF first:

.. code-block:: bash
Expand All @@ -137,23 +133,15 @@ Then initialize the CSRFProtect extension:
csrf = CSRFProtect(app)
Make sure to set the secret key and set ``CKEDITOR_ENABLE_CSRF`` to
True. Now all the image upload request will be protected!
Make sure to set the secret key and set ``CKEDITOR_ENABLE_CSRF`` to True. Now all the image upload requests will be protected!


Code Snippet Highlight
------------------------

The bulit-in CKEditor package include a `Code
Snippet <https://ckeditor.com/addon/codesnippet>`__ plugin. You need to set
``CKEDITOR_ENABLE_CODESNIPPET`` to ``True`` to enable it. You can set
the code theme through configuration option ``CKEDITOR_CODE_THEME``. The
default theme was ``monokai_sublime``. See all available themes and the
list of valid theme string on `this
page <https://sdk.ckeditor.com/samples/codesnippet.html>`__.
The built-in CKEditor package includes a `Code Snippet <https://ckeditor.com/addon/codesnippet>`__ plugin. You need to set ``CKEDITOR_ENABLE_CODESNIPPET`` to ``True`` to enable it. You can set the code theme through the configuration option ``CKEDITOR_CODE_THEME``. The default theme is ``monokai_sublime``. See all available themes and the list of valid theme strings on `this page <https://sdk.ckeditor.com/samples/codesnippet.html>`__.

Another step was load code theme resources in the page you want to
display the text:
Another step is to load code theme resources on the page you want to display the text in:

.. code-block:: jinja
Expand Down
8 changes: 4 additions & 4 deletions examples/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Then go to http://127.0.0.1:5000 with your favourite browser.

Aside from the basic example, there are four additional examples:

- examples/image-upload: This example demonstrate how to support image upload in Flaks-CKEditor.
- examples/codesnippet: This example demonstrate how to use Code Snippet plugin.
- examples/without-flask-wtf: This example demonstrate how to use CKEditor without Flask-WTF.
- examples/flask-admin: This example demonstrate how to use CKEditor for Flask-Admin.
- examples/image-upload: This example demonstrates how to support image upload in Flaks-CKEditor.
- examples/codesnippet: This example demonstrates how to use the Code Snippet plugin.
- examples/without-flask-wtf: This example demonstrates how to use CKEditor without Flask-WTF.
- examples/flask-admin: This example demonstrates how to use CKEditor for Flask-Admin.
4 changes: 2 additions & 2 deletions flask_ckeditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def upload_success(url, filename=''):
from flask_ckeditor import upload_success
app.config['CKEDITOR_FILE_UPLOADER'] = 'upload' # this value can be endpoint or url
@app.route('/files/<path:filename>')
def uploaded_files(filename):
Expand Down Expand Up @@ -274,7 +274,7 @@ def upload_fail(message=None):
from flask import send_from_directory
from flask_ckeditor import upload_success, upload_fail
app.config['CKEDITOR_FILE_UPLOADER'] = 'upload' # this value can be endpoint or url
Expand Down
10 changes: 5 additions & 5 deletions test_flask_ckeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def test_extension_init(self):

def test_load(self):
rv = self.ckeditor.load()
self.assertIn('//cdn.ckeditor.com', rv)
self.assertIn('https://cdn.ckeditor.com', rv)
self.assertIn('standard/ckeditor.js', rv)

current_app.config['CKEDITOR_PKG_TYPE'] = 'basic'
rv = self.ckeditor.load()
self.assertIn('//cdn.ckeditor.com', rv)
self.assertIn('https://cdn.ckeditor.com', rv)
self.assertIn('basic/ckeditor.js', rv)

def test_local_resources(self):
Expand All @@ -83,7 +83,7 @@ def test_local_resources(self):

rv = self.ckeditor.load()
self.assertIn('/ckeditor/static/standard/ckeditor.js', rv)
self.assertNotIn('//cdn.ckeditor.com', rv)
self.assertNotIn('https://cdn.ckeditor.com', rv)

current_app.config['CKEDITOR_PKG_TYPE'] = 'full'
rv = self.ckeditor.load()
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_config_overwrite(self):
def test_ckeditor_field(self):
response = self.client.get('/field')
data = response.get_data(as_text=True)
self.assertIn('//cdn.ckeditor.com', data)
self.assertIn('https://cdn.ckeditor.com', data)
self.assertIn('CKEDITOR.replace', data)
self.assertIn('<textarea class="ckeditor', data)
self.assertIn('name="body"', data)
Expand All @@ -161,7 +161,7 @@ def test_create(self):
def test_render_template(self):
response = self.client.get('/')
data = response.get_data(as_text=True)
self.assertIn('//cdn.ckeditor.com', data)
self.assertIn('https://cdn.ckeditor.com', data)
self.assertIn('CKEDITOR.replace', data)
self.assertIn('<textarea class="ckeditor"', data)

Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ skipsdist = true
[testenv]
commands =
coverage run --source=flask_ckeditor setup.py test
deps =
coverage
flask_wtf

[testenv:coverage]
basepython = python2.7
Expand All @@ -19,4 +22,4 @@ basepython = python2.7
commands =
flake8 flask_ckeditor test_flask_ckeditor.py
deps =
flake8
flake8

0 comments on commit 086eb0c

Please sign in to comment.