[sphinx-dev] secondary windows or hidden sections in html output

2010-09-14 Thread Alastair Dent
I'm used to working with raw html and adding sections of info or
graphics that are only displayed when the user clicks a link or button.
Sometimes it's text that is expanded inline, sometimes a large version
of a graphic.
 
Is there a way of doing this with rst and Sphinx, or do I need to write
an extension?

-- 
You received this message because you are subscribed to the Google Groups 
sphinx-dev group.
To post to this group, send email to sphinx-...@googlegroups.com.
To unsubscribe from this group, send email to 
sphinx-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.



[sphinx-dev] Re: Dynamic file order

2010-09-14 Thread Lllama
Wow.

Okay - I think I now know a lot more about Sphinx that I wanted to but
I seem to have found a solution to my problem.

The original problem:
  I'm currently building a collection of scripts for my team to use when
  writing reports. The plan is that they will create a bunch of rst
  files and Sphinx will turn them into a shiny PDF, or similar. Each rst
  file will have a priority associated with it and I was wondering what
  would be the best way to ensure the final document is ordered by this
  field. I.e. High first, then medium, etc.



  I've written a custom directive (not as scary as I thought) which can
  be used to specify the file's priority.

Here's the directive (trimmed out some error checking for clarity):

class RatingsDirective(rst.Directive):
optional_arguments = 2 ## Ideally I'd like required args...

def run(self):
env = self.state.document.settings.env
if not hasattr(env, ratings_list):
env.ratings_list = []

## RISK and DIFF are two dicts that contain mappings from
## high, med and low to appropriate numerical values
## for easy sorting
risk = RISK[self.arguments[0].split(:)[1].lower()]
diff = DIFF[self.arguments[1].split(:)[1].lower()]

env.ratings_list.append(
(
risk,
diff,
env.docname,
)
)
return []


  So far I think the following are my best options:

  1. Have a pre-build script that greps the files, extracts the
  priorities and updates the index. (not ideal, as the directive won't
  be used)

Didn't go with this in the end.

  2. Hijack the toctree processing to do something similar to 1.

This is what I ended up doing. My reports will be generated as both
html and PDF (using latex). After much (much) digging I found that the
two builders use different methods for determining sort order. The
Latex
builder will pull in the pickled toctree from the index and the HTML
builder
will use cached toctree in the build environment. (I'm hoping these
are the only
two methods used).

In the end I hooked onto the env-updated event and rewrote the
indices there. I
used the env-updated event rather than doctree-read or doctree-
resolved as
this ensured all of my files had been read and that the sort order was
accurate.

Here's what I came up with:


def purge_ratings(app, env, docname):
if not hasattr(env, ratings_list):
return
env.ratings_list = [rating for rating in env.ratings_list
if rating[-1] != docname]

def do_env_update(app, env):
if not hasattr(env, ratings_list):
return

## The following is required for the latex builder.
## Its sort order seems to be based on the index files rather
## than anything else

findings_doctree = env.get_doctree(index)
for toc in findings_doctree.traverse(addnodes.toctree):
toc[entries] = [(None, unicode(entry[-1])) for entry in
sorted(env.ratings_list)]
toc[includefiles] = [unicode(entry[-1]) for entry in
sorted(env.ratings_list)]

## Need to write the pickle back to disk, so copied this
## from the topickle method. Possible API addition...?
findings_doctree.reporter = None
findings_doctree.transformer = None
findings_doctree.settings.warning_stream = None
findings_doctree.settings.env = None
findings_doctree.settings.record_dependencies = None

for metanode in findings_doctree.traverse(MetaBody.meta):
# docutils' meta nodes aren't picklable because the class is
nested
metanode.__class__ = addnodes.meta

file_name = env.doc2path(index, env.doctreedir, .doctree)
with open(file_name, 'wb') as f:
pickle.dump(findings_doctree, f, pickle.HIGHEST_PROTOCOL)

## Need to do this for the html versions
## All we're doing is changing the cached toc in the environment.
for toc in env.tocs[findings].traverse(addnodes.toctree):
toc[entries] = [(None, unicode(entry[-1])) for entry in
sorted(env.ratings_list)]
toc[includefiles] = [unicode(entry[-1]) for entry in
sorted(env.ratings_list)]

## Register everything...
def setup(app):
app.add_directive('rating', RatingsDirective)
app.connect('env-updated', do_env_update)
app.connect('env-purge-doc', purge_ratings)


So there you have it. Users can document their findings like this:


My important report finding
===

.. rating:: rating:high diff:low

These are the details...


The directive will pick up the rating, store it in the environment and
then
overwrite the tocs once all files have been read and before the writer
kicks
off.

Thought this might be useful for someone. If anyone can provide a
sanity check then
that'd be gratefully received but it seems to be working so I'm
leaving it as is until
it breaks.

Felix

-- 
You received this message because you are subscribed to the Google Groups 
sphinx-dev group.
To 

Re: [sphinx-dev] rst2pdf and 1.0.3 Sphinx issues, was - Finally got around to upgrade to 1.x

2010-09-14 Thread Roberto Alsina
On Sunday 12 September 2010 05:47:20 werner wrote:
 I looked through the changes for 0.6.5 to 1.0.3 but don't see anything 
 in relation to modules - rst2pdf with 0.6.5 worked for me, so I guess I 
 have just overlooked a change I need to make to my setup.

Sorry about the late reply!

Sphinx has changed something internally, and rst2pdf has not been able to 
follow it. Specifically, what was before the module index is now something 
else, and there's no code in rst2pdf to handle it.

rst2pdf from SVN will work, but you will get no module index.

-- 
You received this message because you are subscribed to the Google Groups 
sphinx-dev group.
To post to this group, send email to sphinx-...@googlegroups.com.
To unsubscribe from this group, send email to 
sphinx-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.



Re: [sphinx-dev] rst2pdf and 1.0.3 Sphinx issues, was - Finally got around to upgrade to 1.x

2010-09-14 Thread Michael P. Soulier
On 14/09/10 Roberto Alsina said:

 Sorry about the late reply!
 
 Sphinx has changed something internally, and rst2pdf has not been able to 
 follow it. Specifically, what was before the module index is now something 
 else, and there's no code in rst2pdf to handle it.
 
 rst2pdf from SVN will work, but you will get no module index.

When do you plan to align with the latest sphinx? I'll try to keep using
sphinx 0.6.5 until then.

Mike
-- 
Michael P. Soulier msoul...@digitaltorque.ca
Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction.
--Albert Einstein


signature.asc
Description: Digital signature


Re: [sphinx-dev] rst2pdf and 1.0.3 Sphinx issues, was - Finally got around to upgrade to 1.x

2010-09-14 Thread Roberto Alsina
On Tuesday 14 September 2010 11:01:23 Michael P. Soulier wrote:
   On 14/09/10 Roberto Alsina said:
  Sorry about the late reply!
 
  
 
  Sphinx has changed something internally, and rst2pdf has not been able
  to  follow it. Specifically, what was before the module index is now
  something else, and there's no code in rst2pdf to handle it.
 
  
 
  rst2pdf from SVN will work, but you will get no module index.
 
 When do you plan to align with the latest sphinx? I'll try to keep using
 sphinx 0.6.5 until then.

There's no fixed timeframe. I need to make a living and rst2pdf is not how I 
do it :-)

Also, I have not been using sphinx myself, so I am lacking a bit of 
motivation.

-- 
You received this message because you are subscribed to the Google Groups 
sphinx-dev group.
To post to this group, send email to sphinx-...@googlegroups.com.
To unsubscribe from this group, send email to 
sphinx-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.