2011-12-10 27 views
2

我有點難以理解如何在Play上運行scaladoc!框架項目。看來有很多錯綜複雜的因素可以解釋,而且我沒有成功。scaladoc for Play!框架與斯卡拉模塊

有沒有我缺少的教程?你是否需要添加sbt或構建工具以使其合理?

+0

你的意思是還沒有在任何項目或你有因爲玩的一個具體問題上運行Scaladoc?我認爲您可能需要澄清您目前如何構建項目並生成文檔以及您遇到的具體問題。如果你使用sbt,它只是運行'doc'命令的問題,所以這當然很容易。 –

+0

這是Play的一個特定問題。 2.0之前的版本不使用sbt,我不知道如何設置所有東西來手動運行scaladoc。 –

+0

Playframework 2.0使用SBT來構建您的項目。你用什麼版本的遊戲?你嘗試在遊戲控制檯中運行'doc'任務嗎? – David

回答

1

我想出了一個可行的解決方案,但並不完美。您需要運行應用程序以生成模板的Scala代碼。然後用下面的代碼運行'play scaladoc'。

添加 '播放/框架/平陽黴素/播放/命令/ scaladoc.py' 與內容:

import os, os.path 
import shutil 
import subprocess 

from play.utils import * 

COMMANDS = ['scaladoc', 'sd'] 

HELP = { 
    'scaladoc': 'Generate your application scaladoc' 
} 

def execute(**kargs): 
    command = kargs.get("command") 
    app = kargs.get("app") 
    args = kargs.get("args") 
    play_env = kargs.get("env") 

    app.check() 
    modules = app.modules() 
    if not os.environ.has_key('SCALA_HOME'): 
     scaladoc_path = "scaladoc" 
    else: 
     scaladoc_path = os.path.normpath("%s/bin/scaladoc" % os.environ['SCALA_HOME']) 

    fileList = [] 
    def add_scala_files(app_path): 
     for root, subFolders, files in os.walk(os.path.join(app_path, 'app')): 
      for file in files: 
       if file.endswith(".scala"): 
        fileList.append(os.path.join(root, file)) 
     for root, subFolders, files in os.walk(os.path.join(app_path, 
      'tmp/generated')): 
      for file in files: 
       if file.endswith(".scala"): 
        fileList.append(os.path.join(root, file)) 
    add_scala_files(app.path) 
    for module in modules: 
     add_scala_files(os.path.normpath(module)) 
    outdir = os.path.join(app.path, 'scaladoc') 
    sout = open(os.path.join(app.log_path(), 'scaladoc.log'), 'w') 
    serr = open(os.path.join(app.log_path(), 'scaladoc.err'), 'w') 
    if (os.path.isdir(outdir)): 
     shutil.rmtree(outdir) 
    scaladoc_cmd = [scaladoc_path, '-classpath', app.cp_args(), '-d', outdir] + args + fileList 
    print "Generating scaladoc in " + outdir + "..." 
    subprocess.call(scaladoc_cmd, env=os.environ, stdout=sout, stderr=serr) 
    print "Done! You can open " + os.path.join(outdir, 'overview-tree.html') + " in your browser." 
2

與Playframework 2.2.0項目只需要使用這個命令:

clean 
doc 

doc的答案是(只有在你使用乾淨的情況下)iE

主要的Scala API文檔到.../myproject/target/scala-2.10/api ... 然後在這個文件夾中打開index.html。

如果你搜索所有的任務,只需要輸入:

tasks -V