Skip to content

Commit

Permalink
Update docs to match new extensions import by Flask
Browse files Browse the repository at this point in the history
  • Loading branch information
TROUVERIE Joachim committed Oct 9, 2018
1 parent dbbf38a commit ab3aa66
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 53 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2018-09-10 TROUVERIE Joachim <joachim.trouverie@linoame.fr>
* V 1.1
* Update Doc
2016-02-28 TROUVERIE Joachim <joachim.trouverie@linoame.fr>
* V 1.0
* Wheel support
Expand Down
25 changes: 12 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ Example
A simple example of how to use this module

.. code:: python
from flask.ext.wtf import Form
from flask.ext.codemirror.fields import CodeMirrorField
from flask_wtf import FlaskForm
from flask_codemirror.fields import CodeMirrorField
from wtforms.fields import SubmitField
class MyForm(Form):
source_code = CodeMirrorField(language='python', config={'lineNumbers' : 'true'})
class MyForm(FlaskForm):
source_code = CodeMirrorField(language='python', config={'lineNumbers': 'true'})
submit = SubmitField('Submit')
The `CodeMirrorField` works exactly like a `TextAreaField`

.. code:: python
@app.route('/', methods = ['GET', 'POST'])
def index():
form = MyForm()
if form.validate_on_submit():
text = form.source_code.data
return render_template('index.html', form = form)
return render_template('index.html', form=form)
The module needs to be initialized in the usual way and can be configured using app.config keys

.. code:: python
from flask import Flask
from flask.ext.codemirror import CodeMirror
from flask import Flask
from flask_codemirror import CodeMirror
# mandatory
CODEMIRROR_LANGUAGES = ['python', 'html']
WTF_CSRF_ENABLED = True
SECRET_KEY = 'secret'
# optional
CODEMIRROR_THEME = '3024-day'
CODEMIRROR_ADDONS = (
('ADDON_DIR','ADDON_NAME'),
('ADDON_DIR','ADDON_NAME'),
)
app = Flask(__name__)
app.config.from_object(__name__)
Expand Down Expand Up @@ -74,4 +74,3 @@ Finally, the template needs the support Javascript code added, by calling `codem


The Javascript classes are imported from a CDN, there are no static files that need to be served by the application.

78 changes: 39 additions & 39 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
Welcome to Flask-CodeMirror's documentation
Welcome to Flask-CodeMirror's documentation
===========================================

Implementation of source code editor for **Flask** and **Flask-WTF**
using **CodeMirror** Javascript library
Implementation of source code editor for **Flask** and **Flask-WTF**
using **CodeMirror** Javascript library

Installation
Installation
------------

.. code-block:: bash
$ pip install flask-codemirror
Basic Example
-------------
$ pip install flask-codemirror
Basic Example
-------------

A simple example of how to use this module::

from flask.ext.wtf import Form
from flask.ext.codemirror.fields import CodeMirrorField
from flask_wtf import FlaskForm
from flask_codemirror.fields import CodeMirrorField
from wtforms.fields import SubmitField


class MyForm(Form):
class MyForm(FlaskForm):
source_code = CodeMirrorField(language='python',
config={'lineNumbers' : 'true'})
submit = SubmitField('Submit')
submit = SubmitField('Submit')

The ``CodeMirrorField`` works exactly like a ``TextAreaField``::

@app.route('/', methods = ['GET', 'POST'])
def index():
form = MyForm()
if form.validate_on_submit():
text = form.source_code.data
return render_template('index.html', form=form)
return render_template('index.html', form=form)

The module needs to be initialized in the usual way and can be configured using ``app.config`` keys::
from flask.ext.codemirror import CodeMirror

from flask_codemirror import CodeMirror

SECRET_KEY = 'secret!'
# mandatory
CODEMIRROR_LANGUAGES = ['python', 'html']
# optional
CODEMIRROR_THEME = '3024-day'
CODEMIRROR_ADDONS = (
('display','placeholder'),
('display','placeholder'),
)

app = Flask(__name__)
app.config.from_object(__name__)
codemirror = CodeMirror(app)
codemirror = CodeMirror(app)

The config ``CODEMIRROR_LANGUAGES`` needs to be initialized to load JavaScript. It defined all the languages you want to edit with your fields. If the field is not defined a ``CodeMirrorConfigException`` will be raised.
The config ``CODEMIRROR_LANGUAGES`` needs to be initialized to load JavaScript. It defined all the languages you want to edit with your fields. If the field is not defined a ``CodeMirrorConfigException`` will be raised.

The config ``CODEMIRROR_THEME`` is optional and is used to style your TextArea
using css from `CodeMirror website`_.
The config ``CODEMIRROR_THEME`` is optional and is used to style your TextArea
using css from `CodeMirror website`_.

The config ``CODEMIRROR_ADDONS`` is optional and can enable many cool options see `Codemirror Addons`_ for available addons.
The config ``CODEMIRROR_ADDONS`` is optional and can enable many cool options see `Codemirror Addons`_ for available addons.

Finally, the template needs the support Javascript code added, by calling ``codemirror.include_codemirror()``

.. code-block:: html

<html>
<head>
{{ codemirror.include_codemirror() }}
Expand All @@ -72,32 +72,32 @@ Finally, the template needs the support Javascript code added, by calling ``code
{{ form.source_code }}
</form>
</body>
</html>
</html>

The Javascript classes are imported from a CDN, there are no static files that need to be served by the application.
The Javascript classes are imported from a CDN, there are no static files that need to be served by the application.

API
---
API
---

.. automodule:: flask.ext.codemirror
.. automodule:: flask_codemirror

.. autoclass:: CodeMirror

.. automethod:: init_app

.. autoclass:: CodeMirrorHeaders

.. automethod:: include_codemirror
.. automodule:: flask.ext.codemirror.fields

.. automodule:: flask_codemirror.fields

.. autoclass:: CodeMirrorField
.. automodule:: flask.ext.codemirror.widgets

.. automodule:: flask_codemirror.widgets

.. autoclass:: CodeMirrorWidget
.. automethod:: _generate_content

.. automethod:: _generate_content

.. _CodeMirror website: http://codemirror.net/theme/
.. _Codemirror Addons: http://codemirror.net/addon/
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
from setuptools import setup

__version__ = '1.0'
__version__ = '1.1'
__author__ = 'TROUVERIE Joachim'
__contact__ = 'joachim.trouverie@linoame.fr'

Expand Down

0 comments on commit ab3aa66

Please sign in to comment.