Permalink
Browse files

use doctree hook for positionning

  • Loading branch information...
1 parent 3ce99fe commit 3219cc30ea0d28a3c49cb10e4ce3d6f933a7f036 @gawel committed Oct 7, 2012
Showing with 68 additions and 50 deletions.
  1. +4 −0 docs/default.rst
  2. +13 −2 docs/index.rst
  3. +1 −0 docs/linear.rst
  4. +5 −6 docs/mymodule.py
  5. +2 −0 docs/sample.rst
  6. +1 −2 docs/spiral.rst
  7. +2 −0 docs/static/custom.css
  8. +32 −22 impress/directives.py
  9. +7 −13 impress/funcs.py
  10. +1 −5 impress/layout.html
View
@@ -1,3 +1,7 @@
+.. impress::
+ :func:default
+
+========================
Default positioning demo
========================
View
@@ -1,5 +1,6 @@
.. impress::
+===================================
impress's documentation!
===================================
@@ -14,6 +15,15 @@ Use space/left/right keys to navigate.
http://github.com/impress/
+.. toctree::
+ :maxdepth: 1
+ :titlesonly:
+
+ sample
+ default
+ linear
+ spiral
+
Installation
============
@@ -31,6 +41,7 @@ Quick start
===========
.. slide::
+ :class: dense
Write a ``index.rst`` file like this:
@@ -178,5 +189,5 @@ EOS
.. step::
:data-scale: 6
- :data-x: 900
- :data-y: 200
+ :data-x: 1300
+ :data-y: -1200
View
@@ -1,6 +1,7 @@
.. impress::
:func: linear
+=======================
Linear positioning demo
=======================
View
@@ -1,7 +1,6 @@
-from impress.funcs import defaults
-
-
-def awesome_positioning(directive, i, coord):
- coord.update(defaults)
- coord['x'] += 1000
+def awesome_positioning(slide, i, coord, slides):
+ if i > 0:
+ coord['x'] += 1000
+ coord['y'] += 1000
+ coord['rotate_y'] += 45
return coord
View
@@ -1,7 +1,9 @@
+==============
My fisrt slide
==============
.. slide::
+ :class: first
My second slide
===============
View
@@ -1,8 +1,7 @@
.. impress::
:func: spiral
-.. _spiral:
-
+========================
Spiral positionning demo
========================
View
@@ -1 +1,3 @@
.black {color: black;}
+.toctree-wrapper {display:none;}
+.dense pre {line-height: 0.9em;}
View
@@ -84,21 +84,14 @@ class Step(rst.Directive):
'data-rotate-z': directives.unchanged,
}
- def resolve_func(self, name):
- if hasattr(funcs, name):
- return getattr(funcs, name)
- else:
- mod, func = name.split('.')
- mod = __import__(mod, globals(), locals(), [''])
- return getattr(mod, func)
-
def run(self):
if 'reset' in os.environ:
del os.environ['reset']
Step.amounts = {}
Step.last_coord = {}
parent = self.state.parent
+
source = parent.document.attributes['source']
global_options = Impress.opts.setdefault(source, {})
for k, v in global_options.items():
@@ -114,20 +107,6 @@ def run(self):
if self.options.get('hide-title', 'false') == 'true':
title = parent.next_node()
title.attributes['classes'].insert(0, 'hidden')
- if 'data-x' not in self.options:
- func = self.resolve_func(self.options.get('func', 'default'))
- amount = Step.amounts.setdefault(source, 0)
- last_coord = Step.last_coord.setdefault(source, {})
- new_attrs = func(self, amount, last_coord)
- for k, v in new_attrs.items():
- last_coord[k] = v
- if k in ('x', 'y', 'z',
- 'rotate_x', 'rotate_y', 'rotate_z',
- 'scale'):
- k = 'data-%s' % k.replace('_', '-')
- if k not in self.options:
- attrs[k] = [str(v)]
- Step.amounts[source] += 1
else:
print('%s:: WARNING: %s found out of section are ignored' % (
source, self.__class__.__name__.lower()))
@@ -145,9 +124,40 @@ def run(self):
return super(Slide, self).run()
+def resolve_func(name):
+ if hasattr(funcs, name):
+ return getattr(funcs, name)
+ else:
+ mod, func = name.split('.')
+ mod = __import__(mod, globals(), locals(), [''])
+ return getattr(mod, func)
+
+
+def slides_position(app, doctree, docname):
+ slides = [s for s in doctree.children if s.tagname == 'section']
+ for slide in slides:
+ slides.extend([s for s in slide.children if s.tagname == 'section'])
+ slide.children = [s for s in slide.children if s.tagname != 'section']
+ doctree.children = [s for s in doctree.children if s.tagname != 'section']
+ doctree.children.extend(slides)
+ slides = [s for s in doctree.children if s.tagname == 'section']
+ coord = funcs.defaults.copy()
+ for i, slide in enumerate(slides):
+ func = resolve_func(slide.attributes.get('func', 'default'))
+ coord = func(slide, i, coord.copy(), slides)
+ for k, v in coord.items():
+ if k in ('x', 'y', 'z',
+ 'rotate_x', 'rotate_y', 'rotate_z',
+ 'scale'):
+ k = 'data-%s' % k.replace('_', '-')
+ if k not in slide.attributes:
+ slide.attributes[k] = [str(v)]
+
+
def setup(app):
app.add_directive('impress', Impress)
app.add_directive('step', Step)
app.add_directive('slide', Slide)
app.connect('html-page-context', change_pathto)
+ app.connect('doctree-resolved', slides_position)
app.connect('build-finished', move_private_folders)
View
@@ -4,30 +4,26 @@
defaults = dict(x=0, y=0, rotate_x=0, rotate_y=0, rotate_z=0, scale=1)
-def default(directive, i, coord):
+def default(slide, i, coord, slides):
""":doc:`default`"""
- if coord:
+ if i > 0:
coord['x'] += 1000
coord['y'] += 500
coord['rotate_x'] += (1000 / 180. * math.pi)
- else:
- coord.update(defaults)
return coord
-def linear(directive, i, coord):
+def linear(slide, i, coord, slides):
""":doc:`linear`"""
- if coord:
+ if i > 0:
coord['x'] += 1000
- else:
- coord.update(defaults)
return coord
-def spiral(directive, i, coord):
+def spiral(slide, i, coord, slides):
""":doc:`spiral`"""
- if coord:
- r = 1200
+ r = 1200
+ if i > 0:
if coord['x'] > 0:
incr = 100 * i / 3.
else:
@@ -38,6 +34,4 @@ def spiral(directive, i, coord):
coord['rotate_x'] += ((r + incr) / 180. * math.pi)
coord['rotate_y'] += ((r + incr) / 180. * math.pi)
coord['rotate_y'] += ((r + incr) / 180. * math.pi)
- else:
- coord = defaults.copy()
return coord
View
@@ -12,11 +12,7 @@
</head>
<body>
<div id="impress">
- {%- block content %}
- {%- block document %}
- {% block body %} {% endblock %}
- {%- endblock %}
- {%- endblock %}
+ {% block body %} {% endblock %}
</div>
<script src="{{ pathto('_static/impress/js/impress.js', 1) }}"></script>
<script src="{{ pathto('_static/jquery.js', 1) }}"></script>

0 comments on commit 3219cc3

Please sign in to comment.