Mattflaschen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311866

Change subject: Improve JSDuck
......................................................................

Improve JSDuck

Import tags and externals from Echo.

Change-Id: I788275e5d26652f23665c9d1a27a9a457780386b
---
A jsduck.external.js
A jsduck.json
A jsduck_custom_tags.rb
3 files changed, 160 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageTriage 
refs/changes/66/311866/1

diff --git a/jsduck.external.js b/jsduck.external.js
new file mode 100644
index 0000000..907869c
--- /dev/null
+++ b/jsduck.external.js
@@ -0,0 +1,47 @@
+/**
+ * @class jQuery
+ * <http://api.jquery.com/>
+ */
+
+/**
+ * @method ajax
+ * @source <http://api.jquery.com/jQuery.ajax/>
+ * @return {jqXHR}
+ */
+
+/**
+ * @class jQuery.Event
+ * @source <http://api.jquery.com/Types/#Event>
+ */
+
+/**
+ * @class jQuery.Promise
+ * @source <http://api.jquery.com/Types/#Promise>
+ */
+
+/**
+ * @class jQuery.Deferred
+ * @mixins jQuery.Promise
+ * @source <http://api.jquery.com/jQuery.Deferred/>
+ */
+
+/**
+ * @class jQuery.jqXHR
+ * @source <http://api.jquery.com/Types/#jqXHR>
+ * @alternateClassName jqXHR
+ */
+
+/**
+ * @class mw.Api
+ * @source <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Api>
+ */
+
+/**
+ * @class mw.Message
+ * @source 
<https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Message
+ */
+
+/**
+ * @class mw.Title
+ * @source <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Title>
+ */
diff --git a/jsduck.json b/jsduck.json
new file mode 100644
index 0000000..04fede7
--- /dev/null
+++ b/jsduck.json
@@ -0,0 +1,13 @@
+{
+       "--title": "PageTriage - Documentation",
+       "--processes": "0",
+       "--warnings-exit-nonzero": true,
+       "--external": "OO.*",
+       "--output": "docs",
+       "--tags": "jsduck_custom_tags.rb",
+       "--": [
+               "jsduck.external.js",
+               "modules",
+               "tests"
+       ]
+}
diff --git a/jsduck_custom_tags.rb b/jsduck_custom_tags.rb
new file mode 100644
index 0000000..083f45a
--- /dev/null
+++ b/jsduck_custom_tags.rb
@@ -0,0 +1,100 @@
+# Custom tags for JSDuck 5.x
+# See also:
+# - https://github.com/senchalabs/jsduck/wiki/Tags
+# - https://github.com/senchalabs/jsduck/wiki/Custom-tags
+# - 
https://github.com/senchalabs/jsduck/wiki/Custom-tags/7f5c32e568eab9edc8e3365e935bcb836cb11f1d
+require 'jsduck/tag/tag'
+
+class CommonTag < JsDuck::Tag::Tag
+  def initialize
+    @html_position = POS_DOC + 0.1
+    @repeatable = true
+  end
+
+  def parse_doc(scanner, _position)
+    if @multiline
+      return { tagname: @tagname, doc: :multiline }
+    else
+      text = scanner.match(/.*$/)
+      return { tagname: @tagname, doc: text }
+    end
+  end
+
+  def process_doc(context, tags, _position)
+    context[@tagname] = tags
+  end
+
+  def format(context, formatter)
+    context[@tagname].each do |tag|
+      tag[:doc] = formatter.format(tag[:doc])
+    end
+  end
+end
+
+class SourceTag < CommonTag
+  def initialize
+    @tagname = :source
+    @pattern = 'source'
+    super
+  end
+
+  def to_html(context)
+    context[@tagname].map do |source|
+      <<-EOHTML
+        <h3 class='pa'>Source</h3>
+        #{source[:doc]}
+      EOHTML
+    end.join
+  end
+end
+
+class SeeTag < CommonTag
+  def initialize
+    @tagname = :see
+    @pattern = 'see'
+    super
+  end
+
+  def format(context, formatter)
+    position = context[:files][0]
+    context[@tagname].each do |tag|
+      tag[:doc] = '<li>' + render_long_see(tag[:doc], formatter, position) + 
'</li>'
+    end
+  end
+
+  def to_html(context)
+    <<-EOHTML
+      <h3 class="pa">Related</h3>
+      <ul>
+      #{context[@tagname].map {|tag| tag[:doc]}.join("\n")}
+      </ul>
+    EOHTML
+  end
+
+  def render_long_see(tag, formatter, position)
+    match = tag.match(/\A([^\s]+)( .*)?\Z/m)
+    if match
+      name = match[1]
+      doc = match[2] ? ': ' + match[2] : ''
+      return formatter.format("{@link #{name}} #{doc}")
+    else
+      JsDuck::Logger.warn(nil, 'Unexpected @see argument: "' + tag + '"', 
position)
+      return tag
+    end
+  end
+end
+
+class TodoTag < CommonTag
+  def initialize
+    @tagname = :todo
+    @pattern = 'todo'
+    super
+  end
+
+  def to_html(context)
+    <<-EOHTML
+      <h3>TODO</h3>
+      #{context[@tagname].last[:doc]}
+    EOHTML
+  end
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/311866
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I788275e5d26652f23665c9d1a27a9a457780386b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageTriage
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to