Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

79 lignes
2.2 KiB

  1. from __future__ import unicode_literals, absolute_import
  2. import click
  3. import os
  4. import frappe
  5. from frappe.commands import pass_context
  6. @click.command('write-docs')
  7. @pass_context
  8. @click.argument('app')
  9. @click.option('--target', default=None)
  10. @click.option('--local', default=False, is_flag=True, help='Run app locally')
  11. def write_docs(context, app, target=None, local=False):
  12. "Setup docs in target folder of target app"
  13. from frappe.utils.setup_docs import setup_docs
  14. if not target:
  15. target = os.path.abspath(os.path.join("..", "docs", app))
  16. for site in context.sites:
  17. try:
  18. frappe.init(site=site)
  19. frappe.connect()
  20. make = setup_docs(app)
  21. make.make_docs(target, local)
  22. finally:
  23. frappe.destroy()
  24. @click.command('build-docs')
  25. @pass_context
  26. @click.argument('app')
  27. @click.option('--docs-version', default='current')
  28. @click.option('--target', default=None)
  29. @click.option('--local', default=False, is_flag=True, help='Run app locally')
  30. @click.option('--watch', default=False, is_flag=True, help='Watch for changes and rewrite')
  31. def build_docs(context, app, docs_version="current", target=None, local=False, watch=False):
  32. "Setup docs in target folder of target app"
  33. from frappe.utils import watch as start_watch
  34. if not target:
  35. target = os.path.abspath(os.path.join("..", "docs", app))
  36. for site in context.sites:
  37. _build_docs_once(site, app, docs_version, target, local)
  38. if watch:
  39. def trigger_make(source_path, event_type):
  40. if "/templates/autodoc/" in source_path:
  41. _build_docs_once(site, app, docs_version, target, local)
  42. elif ("/docs.css" in source_path
  43. or "/docs/" in source_path
  44. or "docs.py" in source_path):
  45. _build_docs_once(site, app, docs_version, target, local, only_content_updated=True)
  46. apps_path = frappe.get_app_path(app, "..", "..")
  47. start_watch(apps_path, handler=trigger_make)
  48. def _build_docs_once(site, app, docs_version, target, local, only_content_updated=False):
  49. from frappe.utils.setup_docs import setup_docs
  50. try:
  51. frappe.init(site=site)
  52. frappe.connect()
  53. make = setup_docs(app)
  54. if not only_content_updated:
  55. make.build(docs_version)
  56. make.make_docs(target, local)
  57. finally:
  58. frappe.destroy()
  59. commands = [
  60. build_docs,
  61. write_docs,
  62. ]