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

Add --comments-url and --comments-domain options.

Now one can simply use these options instead of injecting special
comments-enabling JavaScript with --head-html.  The JavaScript side
is now also better as it accesses the commentsUrl and commentsDomain
properties of Docs.data object, not a lot more properties on the
root Docs object.
parent cc9de6ad
Loading
Loading
Loading
Loading
+2 −13
Original line number Diff line number Diff line
@@ -162,20 +162,9 @@ class JsDuckRunner
    @options += options
  end

  # Enables comments when CORS is supported by browser.
  # This excludes Opera and IE < 8.
  # We check explicitly for IE version to make sure the code works the
  # same way in both real IE7 and IE7-mode of IE8/9.
  def add_comments(db_name, version)
    comments_base_url = "http://localhost:3000/auth"
    @options += ["--head-html", <<-EOHTML]
      <script type="text/javascript">
        Docs.enableComments = ("withCredentials" in new XMLHttpRequest()) || (Ext.ieVersion >= 8);
        Docs.baseUrl = "#{comments_base_url}";
        Docs.commentsDb = "#{db_name}";
        Docs.commentsVersion = "#{version}";
      </script>
    EOHTML
    add_options("--comments-url", "http://localhost:3000/auth")
    add_options("--comments-domain", db_name+"/"+version)
  end

  def add_ext4
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ module JsDuck
          :showPrintButton => @opts.seo,
          :touchExamplesUi => @opts.touch_examples_ui,
          :source => @opts.source,
          :commentsUrl => @opts.comments_url,
          :commentsDomain => @opts.comments_domain,
        }
      }) + ";\n"
      File.open(filename, 'w') {|f| f.write(js) }
+22 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ module JsDuck
    attr_accessor :eg_iframe
    attr_accessor :examples_base_url
    attr_accessor :tests
    attr_accessor :comments_url
    attr_accessor :comments_domain

    # Debugging
    attr_accessor :template_dir
@@ -103,6 +105,8 @@ module JsDuck
      @eg_iframe = nil
      @examples_base_url = "extjs-build/examples/"
      @tests = false
      @comments_url = nil
      @comments_domain = nil

      # Debugging
      @root_dir = File.dirname(File.dirname(File.dirname(__FILE__)))
@@ -376,6 +380,24 @@ module JsDuck
          @new_since = v
        end

        opts.on('--comments-url=URL',
          "Address of comments server.",
          "",
          "For example: http://projects.sencha.com/auth",
          "",
          "Must be used together with --comments-domain option.") do |url|
          @comments_url = url
        end

        opts.on('--comments-domain=STRING',
          "A string consisting of <name>/<version>.",
          "",
          "For example: ext-js/4",
          "",
          "Must be used together with --comments-url option.") do |domain|
          @comments_domain = domain
        end

        opts.separator ""
        opts.separator "Tweaking:"
        opts.separator ""
+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ Ext.define('Docs.Auth', {
     */
    init: function(callback, scope) {
        Ext.Ajax.request({
            url: Docs.baseUrl + '/session_new',
            url: Docs.data.commentsUrl + '/session_new',
            params: { sid: this.getSid() },
            method: 'GET',
            cors: true,
@@ -58,7 +58,7 @@ Ext.define('Docs.Auth', {
     */
    login: function(cfg) {
        Ext.Ajax.request({
            url: Docs.baseUrl + '/login',
            url: Docs.data.commentsUrl + '/login',
            method: 'POST',
            cors: true,
            params: {
@@ -87,7 +87,7 @@ Ext.define('Docs.Auth', {
     */
    logout: function(callback, scope) {
        Ext.Ajax.request({
            url: Docs.baseUrl + '/logout?sid=' + this.getSid(),
            url: Docs.data.commentsUrl + '/logout?sid=' + this.getSid(),
            method: 'POST',
            cors: true,
            callback: function() {
+10 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ Ext.define('Docs.Comments', {
     * @param {Object} scope
     */
    init: function(callback, scope) {
        if (!Docs.enableComments) {
        if (!(Docs.data.commentsUrl && Docs.data.commentsDomain && this.isBrowserSupported())) {
            callback.call(scope);
            return;
        }
@@ -42,6 +42,14 @@ Ext.define('Docs.Comments', {
        }, this);
    },

    // Comments only get enabled when CORS is supported by browser.
    // This excludes older Opera and IE < 8.
    // We check explicitly for IE version to make sure the code works the
    // same way in both real IE7 and IE7-mode of IE8/9.
    isBrowserSupported: function() {
        return ("withCredentials" in new XMLHttpRequest()) || (Ext.ieVersion >= 8);
    },

    // Fetches comment counts and subscriptions.
    fetchCountsAndSubscriptions: function(callback, scope) {
        this.request("jsonp", {
@@ -243,7 +251,7 @@ Ext.define('Docs.Comments', {
    },

    buildRequestUrl: function(url) {
        url = Docs.baseUrl + '/' + Docs.commentsDb + '/' + Docs.commentsVersion + url;
        url = Docs.data.commentsUrl + "/" + Docs.data.commentsDomain + url;
        return url + (url.match(/\?/) ? '&' : '?') + 'sid=' + Docs.Auth.getSid();
    },

Loading