diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-09-20 18:22:16 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-09-20 18:22:16 -0700 |
commit | b282967a992acc693d95b7f64a254b5fad9fed82 (patch) | |
tree | c2cfdf11ea5330962e8a53c6c9508b8177083eba | |
parent | 60fb1da3088242649f863a2afee5ba3c2d0c7946 (diff) | |
download | pyscss-b282967a992acc693d95b7f64a254b5fad9fed82.tar.gz |
Sphinx documentation! #183
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | docs/Makefile | 153 | ||||
-rw-r--r-- | docs/back-matter.rst | 192 | ||||
-rw-r--r-- | docs/conf.py | 242 | ||||
-rw-r--r-- | docs/index.rst | 45 | ||||
-rw-r--r-- | docs/make.bat | 190 | ||||
-rw-r--r-- | docs/python-api.rst | 147 | ||||
-rw-r--r-- | docs/syntax.rst | 429 | ||||
-rw-r--r-- | docs/usage.rst | 78 |
9 files changed, 1477 insertions, 0 deletions
@@ -8,3 +8,4 @@ *.egg-info/ build/ dist/ +docs/_build/ diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..0e2cd5c --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build2 +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pyScss.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pyScss.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/pyScss" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pyScss" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/back-matter.rst b/docs/back-matter.rst new file mode 100644 index 0000000..1fcdb8d --- /dev/null +++ b/docs/back-matter.rst @@ -0,0 +1,192 @@ +Back matter +=========== + +Reporting bugs +-------------- + +If you have any suggestions, bug reports, or minor annoyances, please report +them to the issue tracker on GitHub: http://github.com/Kronuz/pyScss/issues + + +Contributing +------------ + +Please send us pull requests on GitHub! https://github.com/Kronuz/pyScss + + +Running the test suite +---------------------- + +The test suite is built atop the excellent `py.test`_ library, and can be run with:: + + py.test + +from the root of a source checkout. + +.. _py.test: http://pytest.org/latest/ + +Most of the tests are pairs of input/output files in ``scss/tests/files``; the +test suite scans for these, compiles all the ``.scss`` files, and compares the +output with the ``.css`` file of the same name. You can limit which file tests +run:: + + py.test --test-file-filter=REGEX,REGEX,REGEX... + +There are also several tests borrowed from the Ruby and C implementations. +Many of these don't work (due to missing features, different error messages, +slightly different formatting, etc.), so to reduce the useless noise produced +by a test run, you must explicitly opt into them with ``--include-ruby``, even +when using a file filter. These files are in the ``from-ruby/`` and +``from-sassc/`` subdirectories. + +Additionally, test files in the ``xfail/`` subdirectory are assumed to fail. +Other than these cases, the directory names are arbitrary. + + +License and copyright +--------------------- + +Copyright © 2012 German M. Bravo (Kronuz). Licensed under the `MIT license`_. + +.. _MIT license: http://www.opensource.org/licenses/mit-license.php + +pyScss is inspired by and partially derived from various projects: + +* `Compass`_ © 2009 Christopher M. Eppstein +* `Sass`_ © 2006-2009 Hampton Catlin and Nathan Weizenbaum +* `xCSS`_ © 2010 Anton Pawlik + +.. _Compass: http://compass-style.org/ +.. _Sass: http://sass-lang.com/ +.. _xCSS: http://xcss.antpaw.org/docs/ + + +Changelog +--------- + +1.2.0 (not yet released) +^^^^^^^^^^^^^^^^^^^^^^^^ + +This is a significant release that greatly increases compatibility with the +reference compiler; in particular, the Sass port of Bootstrap now compiles. + +There are a lot of changes here, so please feel free to report any bugs you +see! The goal is 100% compatibility with the Ruby project. + +Missing Sass features +""""""""""""""""""""" + +* Dashes and underscores are treated as interchangeable in variable, function, and mixin names. +* Rule blocks in the form ``background: red { ... }`` are now supported. +* Colors are output as their shortest representation, and never as ``hsl()``. The separate compiler options for compressing colors have been removed. +* The color modification functions (``adjust-color``, etc.) now work reliably. +* ``transparent`` is recognized as a color. +* Unrecognized units are now supported and treated as opaque. +* Arbitrary combinations of units (e.g., ``px * px``) are supported for intermediate values. Unit cancellation now works reliably. +* Comparison and addition are now more in line with the Ruby behavior. +* ``/`` is now left untouched when it appears between literals, as in ``font: 0 / 0``. +* ``null`` is supported. +* ``zip()`` is supported. +* ``grayscale()`` now knows it's also a CSS3 filter function, and won't be evaluated if its argument is a number. +* Slurpy arguments (``some-function($args...)``) are supported. +* ``@extend`` has been greatly improved: it eliminates common ancestors and works in many complex cases that used to produce strange results. +* Several Compass functions now adhere more closely to Compass's behavior. ``linear-gradient()`` is less likely to wreck valid CSS3 syntax. +* Compass's ``e()``, ``pow()``, ``log()``, and ``sqrt()`` are now supported. + +Bug fixes +""""""""" + +* Interactive mode works. Again. +* Color names in strings and selectors are no longer replaced with hex equivalents. +* Unrecognized ``@``-rule blocks such as ``@keyframes`` are left alone, rather than being treated like selectors. +* ``@media`` blocks aren't repeated for every rule inside. +* Pound-interpolation always drops quotes on strings. +* Single quoted strings no longer lose their quotes when rendered. +* ``+ foo { ... }`` is now recognized as a nested block, not an include. +* ``color-stop()`` and several proposed CSS4 functions no longer produce "unrecognized function" warnings. +* Several obscure bugs with variable scoping have been fixed, though a couple others remain. +* Several bugfixes to the C speedups module to bring it in line with the behavior of the pure-Python scanner. + +New features +"""""""""""" + +* Python 3 support. As a result, Python 2.5 no longer works; whether this is a bug or a feature is not yet clear. +* It's possible to write custom Sass functions in Python, though the API for this is not final. +* Experimental support for the map type and destructuring ``@each``, both unreleased additions to the Ruby project. +* Added ``background-brushed``. + +Backwards-incompatible changes +"""""""""""""""""""""""""""""" + +* Configuration via monkeypatching the ``scss`` module no longer works. Monkeypatch ``scss.config`` instead. +* ``em`` and ``px`` are no longer compatible. +* Unrecognized variable names are now a fatal error. + +Internals +""""""""" + +* No longer a single 5000-line file! +* Vastly expanded test suite, including some experimental tests borrowed from the Ruby and C implementations. +* Parser now produces an AST rather than evaluating expressions during the parse, which allows for heavier caching and fixes some existing cache bugs. +* The type system has been virtually rewritten; types now act much less like Python types, and compilation uses Sass types throughout rather than mixing Python types with Sass types. + +1.1.5 (Feb 15, 2013) +^^^^^^^^^^^^^^^^^^^^ + +* ``debug_info`` now properly produces rules that can be used by FireSass and Google Chrome SASS Source Maps. +* Improved memory usage for large sets of files to be used as sprites. +* Warns about IE 4095 maximum number of selectors. +* ``debug_info`` prints info as comments if specified as ``comments``. +* Better handling of undefined variables. +* Added CSS filter functions and ``skewX`` ``skewY``. +* Command line tool and entry point fixed. +* Fix cache buster URLs when paths already include queries or fragments. +* Hashable Values. + +1.1.4 (Aug 8, 2012) +^^^^^^^^^^^^^^^^^^^ + +* Added ``--debug-info`` command line option (for *FireSass* output). +* Added compass helper function ``reject()``. +* Added ``undefined`` keyword for undefined variables. + +1.1.3 (Jan 9, 2012) +^^^^^^^^^^^^^^^^^^^ + +* Support for the new Sass 3.2.0 features (``@content`` and placeholder selectors) +* Fixed bug with line numbers throwing an exception. + +1.1.2 (Jan 3, 2012) +^^^^^^^^^^^^^^^^^^^ + +* Regression bug fixed from 1.1.1 + +1.1.1 (Jan 2, 2012) +^^^^^^^^^^^^^^^^^^^ + +* Added optional C speedup module for an amazing boost in scanning speed! +* Added ``headings``, ``stylesheet-url``, ``font-url``, ``font-files``, ``inline-font-files`` and ``sprite-names``. + +1.1.0 (Dec 22, 2011) +^^^^^^^^^^^^^^^^^^^^ + +* Added ``min()`` and ``max()`` for lists. +* Removed exception raise. + +1.0.9 (Dec 22, 2011) +^^^^^^^^^^^^^^^^^^^^ + +* Optimizations in the scanner. +* Added ``background-noise()`` for compass-recipes support. +* ``enumerate()`` and ``range()`` can go backwards. Ex.: ``range(3, 0)`` goes from 3 to 0. +* Added line numbers and files for errors. +* Added support for *Firebug* with *FireSass*. +* ``nth(n)`` is round (returns the ``nth mod len`` item of the list). +* ``--watch`` added to the command line. +* Several bugs fixed. + +1.0.8 (May 13, 2011) +^^^^^^^^^^^^^^^^^^^^ + +* Changed source color (``$src-color``) default to black. +* Moved the module filename to ``__init__.py`` and module renamed back to scss. diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..237487e --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,242 @@ +# -*- coding: utf-8 -*- +# +# pyScss documentation build configuration file, created by +# sphinx-quickstart2 on Thu Sep 19 18:03:51 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'pyScss' +copyright = u'2013, German M. Bravo (Kronuz)' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.2' +# The full version, including alpha/beta/rc tags. +release = '1.2pre' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'pyScssdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'pyScss.tex', u'pyScss Documentation', + u'German M. Bravo (Kronuz)', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'pyscss', u'pyScss Documentation', + [u'German M. Bravo (Kronuz)'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'pyScss', u'pyScss Documentation', + u'German M. Bravo (Kronuz)', 'pyScss', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..50e90c7 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,45 @@ +.. pyScss documentation master file, created by + sphinx-quickstart2 on Thu Sep 19 18:03:51 2013. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +pyScss, a Sass compiler for Python +================================== + +pyScss compiles Scss (Sass), a superset of CSS that is more powerful, elegant +and easier to maintain than plain-vanilla CSS. The library acts as a CSS source +code preprocesor which allows you to use variables, nested rules, mixins, and +have inheritance of rules, all with a CSS-compatible syntax which the +preprocessor then compiles to standard CSS. + +Scss, as an extension of CSS, helps keep large stylesheets well-organized. It +borrows concepts and functionality from projects such as OOCSS and other similar +frameworks like as Sass. It's build on top of the original PHP xCSS codebase +structure but it's been completely rewritten, many bugs have been fixed and it +has been extensively extended to support almost the full range of Sass' Scss +syntax and functionality. + +.. image:: http://pledgie.com/campaigns/16513.png?skin_name=chrome + :alt: Click here to lend your support to pyScss and make a donation at pledgie.com! + :target: http://pledgie.com/campaigns/16513 + + +Contents: + +.. toctree:: + :maxdepth: 2 + + usage + python-api + syntax + back-matter + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..225da6d --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,190 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build2 +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^<target^>` where ^<target^> is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\pyScss.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\pyScss.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/docs/python-api.rst b/docs/python-api.rst new file mode 100644 index 0000000..a22ed2a --- /dev/null +++ b/docs/python-api.rst @@ -0,0 +1,147 @@ +Python API +========== + +Compiling files +--------------- + +Very basic usage is simple enough:: + + from scss import Scss + css = Scss() + css.compile("a { color: red + green; }") + + +Configuration +------------- + +There are several configuration variables in the ``scss.config`` module that +you may wish to change. + +``PROJECT_ROOT``: Root of your entire project. Used only to construct defaults +for other variables. Defaults to the root of the pyScss installation, which is +probably not what you want. + +``LOAD_PATHS``: An iterable of paths to search when using``@import``. + +``STATIC_ROOT``: Used for finding sprite files. Defaults to +``$PROJECT_ROOT/static``. + +``ASSETS_ROOT``: Generated sprites are saved here. Defaults to +``$STATIC_ROOT/assets``. + +``CACHE_ROOT``: Used for storing cached sprite information. Defaults to +``ASSETS_ROOT``. + +``STATIC_URL``: URL equivalent to ``STATIC_ROOT``. Defaults to ``static/``. + +``ASSETS_URL``: URL equivalent to ``ASSETS_ROOT``. Defaults to ``static/assets/``. + +``SPRTE_MAP_DIRECTION``: Direction in which to arrange sprites in a +spritesheet. Defaults to ``vertical``; may be changed to ``horizontal``, +``diagonal``, or ``smart``. + +``VERBOSITY``: Increase spew from the compiler. Defaults to ``1``. + +``DEBUG``: Set to true to make parse errors fatal. Defaults to false. + +.. warning:: + + Configuration via monkeypatching is fraught with issues. If you don't need + the Compass sprite functionality, stick with passing ``search_paths`` to + the ``Scss`` constructor, and don't touch these variables at all. + + The current plan is to introduce a new mechanism for Compass configuration + in 1.3 with deprecation warnings, and remove ``scss.config`` entirely in + 2.0. + + +Django example +-------------- + +A rough example of using pyScss with Django:: + + import os + import fnmatch + + import scss + + from django.conf import settings + from django.utils.datastructures import SortedDict + from django.contrib.staticfiles import finders + + + def finder(glob): + """ + Finds all files in the django finders for a given glob, + returns the file path, if available, and the django storage object. + storage objects must implement the File storage API: + https://docs.djangoproject.com/en/dev/ref/files/storage/ + """ + for finder in finders.get_finders(): + for path, storage in finder.list([]): + if fnmatch.fnmatchcase(path, glob): + yield path, storage + + + # STATIC_ROOT is where pyScss looks for images and static data. + # STATIC_ROOT can be either a fully qualified path name or a "finder" + # iterable function that receives a filename or glob and returns a tuple + # of the file found and its file storage object for each matching file. + # (https://docs.djangoproject.com/en/dev/ref/files/storage/) + scss.config.STATIC_ROOT = finder + scss.config.STATIC_URL = settings.STATIC_URL + + # ASSETS_ROOT is where the pyScss outputs the generated files such as spritemaps + # and compile cache: + scss.config.ASSETS_ROOT = os.path.join(settings.MEDIA_ROOT, 'assets/') + scss.config.ASSETS_URL = settings.MEDIA_URL + 'assets/' + + # These are the paths pyScss will look ".scss" files on. This can be the path to + # the compass framework or blueprint or compass-recepies, etc. + scss.config.LOAD_PATHS = [ + '/usr/local/www/sass/frameworks/', + '/Library/Ruby/Gems/1.8/gems/compass-0.11.5/frameworks/compass/stylesheets/', + '/Library/Ruby/Gems/1.8/gems/compass-0.11.5/frameworks/blueprint/stylesheets/', + ] + + # This creates the Scss object used to compile SCSS code. In this example, + # _scss_vars will hold the context variables: + _scss_vars = {} + _scss = scss.Scss( + scss_vars=_scss_vars, + scss_opts={ + 'compress': True, + 'debug_info': True, + } + ) + + # 1. Compile from a string: + compiled_css_from_string = _scss.compile('@import "file2"; a {color: red + green; }') + + # 2. Compile from a file: + compiled_css_from_file = _scss.compile(scss_file='file1.scss') + + # 3. Compile from a set of files (use SortedDict or collections.OrderedDict to + # maintain the compile order): + _scss._scss_files = SortedDict(( + ('file2.scss', open('file2.scss').read()), + ('file3.scss', open('file3.scss').read()), + ('file4.scss', open('file4.scss').read()), + )) + compiled_css_from_files = _scss.compile() + +.. note:: + + The API here is likely to be improved in 1.3, to avoid the need for calling + underscored functions. + + +Extending pyScss +---------------- + +There is some support for adding custom functions from Python, but the API is +explicitly undocumented and subject to change. Watch this space. + +.. todo:: + + Document the extension API once it's final. diff --git a/docs/syntax.rst b/docs/syntax.rst new file mode 100644 index 0000000..6030324 --- /dev/null +++ b/docs/syntax.rst @@ -0,0 +1,429 @@ +.. highlight:: scss + +============= +pyScss syntax +============= + +Supported Sass features +======================= + +pyScss is mostly compatible with Sass 3.2. + + +Both syntaxes +------------- + +SCSS (CSS3 superset) is the primary syntax, but there's experimental support +for the SASS (YAML-like) syntax. + + +Built-in functions +------------------ + +All of the functions described in `the Sass documentation`_ are supported. + +.. _the Sass documentation: <http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html + + +Rule nesting +------------ + +Rule/selector nesting and the ``&`` parent-reference selector are both +supported. + +Example:: + + .selector { + a { + display: block; + } + strong { + color: blue; + } + } + +Produces:: + + .selector a { + display: block; + } + .selector strong { + color: blue; + } + + +Variables, data types +--------------------- + +Variables are supported. All of the Sass data types—strings, numbers, +booleans, colors, lists, maps, and null—are supported. + +Example:: + + $main-color: #ce4dd6; + $style: solid; + $side: bottom; + #navbar { + border-#{$side}: { + color: $main-color; + style: $style; + } + } + +Produces:: + + #navbar { + border-bottom-color: #ce4dd6; + border-bottom-style: solid; + } + + +Functions and mixins +-------------------- + +``@function``, ``@mixin``, and ``@include`` (optionally with ``@content``) are +supported. + +Named arguments (``foo($name: value)``) and slurpy arguments +(``foo($args...)``) are also supported. + +Example:: + + @mixin rounded($side, $radius: 10px) { + border-#{$side}-radius: $radius; + -moz-border-radius-#{$side}: $radius; + -webkit-border-#{$side}-radius: $radius; + } + #navbar li { @include rounded(top); } + #footer { @include rounded(top, 5px); } + #sidebar { @include rounded(left, 8px); } + +Produces:: + + #navbar li { + border-top-radius: 10px; + -moz-border-radius-top: 10px; + -webkit-border-top-radius: 10px; + } + #footer { + border-top-radius: 5px; + -moz-border-radius-top: 5px; + -webkit-border-top-radius: 5px; + } + #sidebar { + border-left-radius: 8px; + -moz-border-radius-left: 8px; + -webkit-border-left-radius: 8px; + } + + +Rule extension +-------------- + +``@extend`` is supported, though some particularly thorny edge cases may not +produce output identical to the reference compiler. + +Example:: + + .error { + border: 1px #f00; + background-color: #fdd; + } + .error.intrusion { + background-image: url("/image/hacked.png"); + } + .seriousError { + @extend .error; + border-width: 3px; + } + +Produces:: + + .error, + .seriousError { + border: 1px red; + background-color: #fdd; + } + .error.intrusion, + .seriousError.intrusion { + background-image: url("/image/hacked.png"); + } + .seriousError { + border-width: 3px; + } + + +Conditions +---------- + +``@if``, ``@else if``, and ``@else`` are supported. + + +Loops +----- + +Both types of iteration are supported:: + + @for $n from 1 through 9 { + .span-#{$n} { width: $n * 10%; } + } + + @each $color in red, blue, yellow { + .button-#{$color} { + background-color: $color; + } + } + +Additionally, the unpacking-iteration syntax in Sass trunk is supposed; see +:ref:`maps`. + + +.. _maps: + +Maps +---- + +pyScss has experimental support for maps, a data type recently added to Sass +trunk. Maps are defined with colons inside parentheses:: + + $colors: ( + text: black, + background: white + ); + +Keys may be any Sass expression, not just strings. + +Maps are manipulated with a handful of map functions:: + + a { + color: map-get($colors, text); + background-color: map-get($colors, background); + } + +A map is semantically equivalent to a list of 2-lists, stored in the order they +appeared when the map was defined. Any list operation will work on a map:: + + div { + // I don't know why you'd do this :) + margin: nth($colors, 1); // => text, black + } + +Maps may be iterated over with ``@each``, of course, but each item will be a +somewhat clumsy 2-list. Instead, you can give multiple variables to do an +unpacking iteration:: + + @each $key, $value in $colors { + // I don't know why you'd do this either! + [data-style=$key] { + color: $value; + } + } + +This syntax works on any list-of-lists. + + +Everything is a list +-------------------- + +Another change borrowed from Sass trunk: any scalar type (string, number, +boolean, etc.) will also act as a list of one element when used where a list is +expected. This is most useful when writing Python extensions, but may also +save you from checking ``type-of`` in a complex API. + + +Compass support +=============== + +An arbitrary cross-section of Compass 0.11 is supported: + + * **Math functions**: ``sin``, ``cos``, ``tan``, ``round``, ``ceil``, ``floor``, ``pi``, ``e`` + * **Images**: ``image-url``, ``image-width``, ``image-height``... + * **Embedded (inline) images**: ``inline-image`` + + +.. todo:: + + Document exactly what's supported, how it works, and what's missing. + +.. note:: + + Currently, Compass support is provided by default, which has led to some + surprising behavior since parts of Compass conflict with parts of CSS3. In + the future, Compass will become an extension like it is for Ruby, and you + will have to opt in. + + +Sprites +------- + +Example:: + + $icons: sprite-map("sociable/*.png"); // contains sociable/facebook.png among others. + div { + background: $icons; + } + @each $icon in sprites($icons) { + div .#{$icon} { + width: image-width(sprite-file($icons, $icon)); + height: image-height(sprite-file($icons, $icon)); + background-position: sprite-position($icons, $icon); + } + } + +...generates a new sprite file and produces something like:: + + div { + background: url("/static/assets/u8Y7yEQL0UffAVw5rX7yhw.png?_=1298240989") 0px 0px no-repeat; + } + div .facebook { + width: 32px; + height: 32px; + background-position: 0px 0px; + } + div .twitter { + width: 32px; + height: 32px; + background-position: 0px -32px; + } + ... + + +pyScss-specific extensions +========================== + +pyScss supports some constructs that upstream Sass does not, for various +reasons. Listed here are "blessed" features in no danger of being removed, +though you should avoid them if you're at all interested in working with the +reference compiler. + +There are also some deviations that only exist for backwards compatibility; you +should **not** rely on them, they will start spewing warnings at some point in +the future, and eventually they will disappear. They are listed separately in +:ref:`deprecated-features`. + + +``@option`` +----------- + +Compiler options may be toggled at runtime with ``@option``. At the moment the +only supported option is ``compress``, to control whether the output is +compressed:: + + @option compress: true; + + +Multiplying strings by numbers +------------------------------ + +Much like in Python, this works:: + + content: "foo" * 3; // => "foofoofoo" + +This is a runtime error in the reference compiler. + + +.. _deprecated-features: + +Deprecated features +=================== + +Brackets to delimit expressions +------------------------------- + +In an expression, square brackets are equivalent to parentheses:: + + margin-top: [1px + 2px] * 3; // => 9px + +This is a holdover from xCSS and will be removed in the future. + + +``extends`` +----------- + +There's an alternative syntax for ``@extend``:: + + a extends b { + ... + } + +This is identical to:: + + a { + @extend b; + ... + } + +This is a holdover from xCSS and will be removed in the future. + + +``self`` selector +----------------- + +``self`` is an alias for ``&``:: + + a { + self:hover { + text-decoration: underline; + } + } + +This is a holdover from xCSS and will be removed in the future. + + +``@variables`` block +-------------------- + +Variables may be declared in a dedicated block:: + + @variables { + $color: red; + } + +``@vars`` is an alias for ``@variables``. + +This is a holdover from xCSS and will be removed in the future. + + +``+foo`` to include a mixin +--------------------------- + +This:: + + div { + +border-radius 3px; + } + +Is equivalent to this:: + + div { + @include border-radius(3px); + } + +This is the same as the Sass syntax, but causes some parsing ambiguity, since +``+foo`` with a block could be either a nested CSS block with a sibling +selector or a mixin call. Its future is uncertain, but you should probably +avoid using it in SCSS files. + +Soft errors +----------- + +pyScss is much more liberal in what it accepts than the reference compiler; for +example, rules at the top level and missing closing braces are accepted without +complaint, and attempting to use a non-existent mixin only results in a +warning. + +pyScss 2.0 is likely to be much stricter; don't rely on any particular abuse of +syntax to work in the future. + + +Unsupported Sass features +========================= + +Some Sass features are not supported or have some gaps. Each of these may be +considered a bug. + +``@while`` +---------- + +The ``@while`` construct doesn't work at all and will be left intact in the +output, like any other unrecognized ``@``-rule. diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 0000000..364770a --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,78 @@ +Installation and usage +====================== + +Installation +------------ + +pyScss requires only Python 2.5 or later, including Python 3.x. Install with +pip:: + + pip install pyScss + +Its lone dependency is the ``six`` library, which pip should install for you. + + +Usage +----- + +Run from the command line by using ``-m``:: + + python -mscss < file.scss + +Specify directories to search for imports with ``-I``. See ``python -mscss +--help`` for more options. + +.. note:: + + ``-mscss`` will only work in Python 2.7 and above. For Python 2.5 and 2.6, + ``-m`` doesn't work with packages, and you need to invoke:: + + python -mscss.tool + + + +Interactive mode +---------------- + +To get a REPL:: + + python -mscss --interactive + +Example session:: + + $ python scss.py --interactive + >>> @import "compass/css3" + >>> show() + ['functions', 'mixins', 'options', 'vars'] + >>> show(mixins) + ['apply-origin', + 'apply-transform', + ... + 'transparent'] + >>> show(mixins, transparent) + @mixin transparent() { + @include opacity(0); + } + >>> 1px + 5px + 6px + >>> _ + + +Compass example +--------------- + +With ``--load-path`` or ``scss.config.LOAD_PATHS`` set to Compass and Blueprint +roots, you can compile with Compass like with the following:: + + @option compress: no; + + $blueprint-grid-columns : 24; + $blueprint-grid-width : 30px; + $blueprint-grid-margin : 10px; + $font-color : #333; + + @import "compass/reset"; + @import "compass/utilities"; + @import "blueprint"; + + // your code... |