Commit d6ac6e2c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add --seo command line option.

Created a minimal PHP script that serves plain HTML class documentation
when search engine requests _escaped_fragment_.  Otherwise it just
serves the old index page (now renamed to template.html).

At the moment the script outputs only docs for the class itself, not
for its members.
parent 66364d38
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ task :sdk do
    # to create symbolic links to template files instead of copying them over.
    # Useful for development.  Turn off for deployment.
    "--template-links",
    "--seo",
    "#{SDK_DIR}/extjs/src",
    "#{SDK_DIR}/platform/src",
    "#{SDK_DIR}/platform/core/src",
@@ -107,6 +108,7 @@ desc "Base task for creating live docs"
task :base_live_docs do
  load_sdk_vars
  run_jsduck_export([
    "--seo",
    "--body-html", <<-EOHTML
    <script type="text/javascript">
      var _gaq = _gaq || [];
@@ -223,8 +225,10 @@ end
desc "Compresses JavaScript and CSS files in output dir"
task :compress do
  load_sdk_vars
  # Detect if we are using index.html or template.html
  index_html = File.exists?("#{OUT_DIR}/index.html") ? "#{OUT_DIR}/index.html" : "#{OUT_DIR}/template.html"
  # Create JSB3 file for Docs app
  system("sencha", "create", "jsb", "-a", "#{OUT_DIR}/index.html", "-p", "#{OUT_DIR}/app.jsb3")
  system("sencha", "create", "jsb", "-a", index_html, "-p", "#{OUT_DIR}/app.jsb3")
  # Concatenate files listed in JSB3 file
  system("sencha", "build", "-p", "#{OUT_DIR}/app.jsb3", "-d", OUT_DIR)
  # Remove intermediate build files
@@ -236,10 +240,10 @@ task :compress do
  system("rm", "-r", "#{OUT_DIR}/app")

  # Concatenate CSS and JS files referenced in index.html file
  html = IO.read("#{OUT_DIR}/index.html")
  html = IO.read(index_html)
  html = combine_css(html, OUT_DIR)
  html = combine_js(html, OUT_DIR)
  File.open("#{OUT_DIR}/index.html", 'w') {|f| f.write(html) }
  File.open(index_html, 'w') {|f| f.write(html) }

  # Clean up SASS files
  system "rm -rf #{OUT_DIR}/resources/sass"
+10 −6
Original line number Diff line number Diff line
@@ -83,7 +83,11 @@ module JsDuck
        else
          copy_template
        end
        create_index_html
        create_template_html
        if !@opts.seo
          FileUtils.rm(@opts.output_dir+"/index.php")
          FileUtils.cp(@opts.output_dir+"/template.html", @opts.output_dir+"/index.html")
        end
        @timer.time(:generating) { write_src(parsed_files) }
        @timer.time(:generating) { write_app_data }
        @timer.time(:generating) { write_classes }
@@ -211,9 +215,9 @@ module JsDuck
      FileUtils.mkdir(@opts.output_dir + "/source")
    end

    def create_index_html
      Logger.instance.log("Creating #{@opts.output_dir}/index.html...")
      html = IO.read(@opts.template_dir+"/index.html")
    def create_template_html
      Logger.instance.log("Creating #{@opts.output_dir}/template.html...")
      html = IO.read(@opts.template_dir+"/template.html")
      html.gsub!("{title}", @opts.title)
      html.gsub!("{footer}", "<div id='footer-content' style='display: none'>#{@footer}</div>")
      html.gsub!("{extjs_path}", @opts.extjs_path)
@@ -221,8 +225,8 @@ module JsDuck
      html.gsub!("{categories}", @categories.to_html)
      html.gsub!("{head_html}", @opts.head_html)
      html.gsub!("{body_html}", @opts.body_html)
      FileUtils.rm(@opts.output_dir+"/index.html")
      File.open(@opts.output_dir+"/index.html", 'w') {|f| f.write(html) }
      FileUtils.rm(@opts.output_dir+"/template.html")
      File.open(@opts.output_dir+"/template.html", 'w') {|f| f.write(html) }
    end
  end

+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ module JsDuck
    attr_accessor :link_tpl
    attr_accessor :img_tpl
    attr_accessor :export
    attr_accessor :seo

    # Debugging
    attr_accessor :processes
@@ -59,6 +60,7 @@ module JsDuck
      # appears inline within text, but that just looks ugly in HTML
      @img_tpl = '<p><img src="doc-resources/%u" alt="%a"></p>'
      @export = nil
      @seo = false

      # Debugging
      @processes = nil
@@ -187,6 +189,10 @@ module JsDuck
          @export = :stdout
        end

        opts.on('--seo', "Creates index.php that handles search engine traffic.", " ") do
          @seo = true
        end

        opts.separator "Debugging:"
        opts.separator ""

template/index.php

0 → 100644
+34 −0
Original line number Diff line number Diff line
<?php

function print_page($title, $body) {
  echo "<!DOCTYPE html>";
  echo "<html>";
  echo "<head>";
  echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
  echo "<title>$title</title>";
  echo "</head>";
  echo "<body>";
  echo "<h1>$title</h1>";
  echo $body;
  echo "</body>";
  echo "</html>";
}

if (isset($_GET["_escaped_fragment_"])) {
  $fragment = $_GET["_escaped_fragment_"];
  if (preg_match('/^\/api\/([^-]*)/', $fragment, $m)) {
    $contents = file_get_contents("output/".$m[1].".js");
    $contents = preg_replace('/^.*?\(/', "", $contents);
    $contents = preg_replace('/\);\s*$/', "", $contents);
    $json = json_decode($contents, true);
    print_page($json["name"], $json["doc"]);
  }
  else {
    echo "Not implemented";
  }
}
else {
  echo file_get_contents("template.html");
}

?>
 No newline at end of file
+0 −0

File moved.