10349: Add support for syntax highlighting inline code blocks.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 12 Sep 2017 15:15:24 +0000 (11:15 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 12 Sep 2017 15:15:24 +0000 (11:15 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

doc/sdk/go/example.html.textile.liquid
doc/sdk/java/example.html.textile.liquid
doc/sdk/perl/example.html.textile.liquid
doc/sdk/python/cookbook.html.textile.liquid
doc/sdk/python/example.html.textile.liquid
doc/sdk/ruby/example.html.textile.liquid
doc/zenweb-liquid.rb

index 45a2e44fa70d1fd8553e01eb42b193d8cd27356d..a5a109b85b8673676919b9c5e9497761e27919aa 100644 (file)
@@ -16,7 +16,7 @@ In these examples, the site prefix is @aaaaa@.
 
 h2.  Initialize SDK
 
-<pre>
+{% codeblock as go %}
 import (
   "git.curoverse.com/arvados.git/sdk/go/arvados"
   "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
@@ -28,49 +28,49 @@ func main() {
     log.Fatalf("Error setting up arvados client %s", err.Error())
   }
 }
-</pre>
+{% endcodeblock %}
 
 h2. create
 
-<pre>
+{% codeblock as go %}
   var collection arvados.Collection
   err := api.Create("collections", Dict{"collection": Dict{"name": "create example"}}, &collection)
-</pre>
+{% endcodeblock %}
 
 h2. delete
 
-<pre>
+{% codeblock as go %}
   var collection arvados.Collection
   err := api.Delete("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{}, &collection)
-</pre>
+{% endcodeblock %}
 
 h2. get
 
-<pre>
+{% codeblock as go %}
   var collection arvados.Collection
   err := api.Get("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{}, &collection)
-</pre>
+{% endcodeblock %}
 
 h2. list
 
-<pre>
+{% codeblock as go %}
   var collection arvados.Collection
   err := api.List("collections", Dict{}, &collection)
-</pre>
+{% endcodeblock %}
 
 h2. update
 
-<pre>
+{% codeblock as go %}
   var collection arvados.Collection
   err := api.Update("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{"collection": Dict{"name": "update example"}}, &collection)
-</pre>
+{% endcodeblock %}
 
 h2. Get current user
 
-<pre>
+{% codeblock as go %}
   var user arvados.User
   err := api.Get("users", "current", Dict{}, &user)
-</pre>
+{% endcodeblock %}
 
 h2. Example program
 
index 0eabdcb9e969b6d9d695806024e117c2e6b4e7f6..bc15b83f41438ffae69640156ccf4ffff13adc61 100644 (file)
@@ -12,47 +12,47 @@ SPDX-License-Identifier: CC-BY-SA-3.0
 
 h2. Initialize SDK
 
-<pre>
+{% codeblock as java %}
 import org.arvados.sdk.Arvados;
-</pre>
+{% endcodeblock %}
 
-<pre>
+{% codeblock as java %}
     String apiName = "arvados";
     String apiVersion = "v1";
 
     Arvados arv = new Arvados(apiName, apiVersion);
-</pre>
+{% endcodeblock %}
 
 h2. create
 
-<pre>
+{% codeblock as java %}
     Map<String, String> collection = new HashMap<String, String>();
     collection.put("name", "create example");
 
     Map<String, Object> params = new HashMap<String, Object>();
     params.put("collection", collection);
     Map response = arv.call("collections", "create", params);
-</pre>
+{% endcodeblock %}
 
 h2. delete
 
-<pre>
+{% codeblock as java %}
     Map<String, Object> params = new HashMap<String, Object>();
     params.put("uuid", uuid);
     Map response = arv.call("collections", "delete", params);
-</pre>
+{% endcodeblock %}
 
 h2. get
 
-<pre>
+{% codeblock as java %}
     params = new HashMap<String, Object>();
     params.put("uuid", userUuid);
     Map response = arv.call("users", "get", params);
-</pre>
+{% endcodeblock %}
 
 h2. list
 
-<pre>
+{% codeblock as java %}
     Map<String, Object> params = new HashMap<String, Object>();
     Map response = arv.call("users", "list", params);
 
@@ -61,11 +61,11 @@ h2. list
 
     Map firstUser = (Map)items.get(0);
     String userUuid = (String)firstUser.get("uuid");
-</pre>
+{% endcodeblock %}
 
 h2. update
 
-<pre>
+{% codeblock as java %}
     Map<String, String> collection = new HashMap<String, String>();
     collection.put("name", "update example");
 
@@ -73,11 +73,11 @@ h2. update
     params.put("uuid", uuid);
     params.put("collection", collection);
     Map response = arv.call("collections", "update", params);
-</pre>
+{% endcodeblock %}
 
 h2. Get current user
 
-<pre>
+{% codeblock as java %}
     Map<String, Object> params = new HashMap<String, Object>();
     Map response = arv.call("users", "current", params);
-</pre>
+{% endcodeblock %}
index 42932a36e0592d551d082195bcbe4e2c97f1c413..b51cfe4cb5b788005410062ba2df1f44f4732bea 100644 (file)
@@ -14,12 +14,10 @@ h2. Initialize SDK
 
 Set up an API client user agent:
 
-<notextile>
-<pre><code class="userinput">
+{% codeblock as perl %}
 use Arvados;
 my $arv = Arvados->new('apiVersion' => 'v1');
-</code></pre>
-</notextile>
+{% endcodeblock %}
 
 The SDK retrieves the list of API methods from the server at run time. Therefore, the set of available methods is determined by the server version rather than the SDK version.
 
@@ -27,60 +25,53 @@ h2. create
 
 Create an object:
 
-<notextile>
-<pre><code class="userinput">my $test_link = $arv->{'links'}->{'create'}->execute('link' => { 'link_class' => 'test', 'name' => 'test' });
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $test_link = $arv->{'links'}->{'create'}->execute('link' => { 'link_class' => 'test', 'name' => 'test' });
+{% endcodeblock %}
 
 h2. delete
 
-<notextile>
-<pre><code class="userinput">my $some_user = $arv->{'collections'}->{'get'}->execute('uuid' => $collection_uuid);
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $some_user = $arv->{'collections'}->{'get'}->execute('uuid' => $collection_uuid);
+{% endcodeblock %}
 
 h2. get
 
 Retrieve an object by ID:
 
-<notextile>
-<pre><code class="userinput">my $some_user = $arv->{'users'}->{'get'}->execute('uuid' => $current_user_uuid);
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $some_user = $arv->{'users'}->{'get'}->execute('uuid' => $current_user_uuid);
+{% endcodeblock %}
 
 Get the UUID of an object that was retrieved using the SDK:
 
-<notextile>
-<pre><code class="userinput">my $current_user_uuid = $current_user->{'uuid'}
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $current_user_uuid = $current_user->{'uuid'}
+{% endcodeblock %}
 
 h2. list
 
 Get a list of objects:
 
-<notextile>
-<pre><code class="userinput">my $repos = $arv->{'repositories'}->{'list'}->execute;
+{% codeblock as perl %}
+my $repos = $arv->{'repositories'}->{'list'}->execute;
 print ("UUID of first repo returned is ", $repos->{'items'}->[0], "\n");
-</code></pre>
-</notextile>
+{% endcodeblock %}
 
 h2. update
 
 Update an object:
 
-<notextile>
-<pre><code class="userinput">my $test_link = $arv->{'links'}->{'update'}->execute(
+{% codeblock as perl %}
+my $test_link = $arv->{'links'}->{'update'}->execute(
         'uuid' => $test_link->{'uuid'},
         'link' => { 'properties' => { 'foo' => 'bar' } });
-</code></pre>
-</notextile>
+{% endcodeblock %}
 
 h2. Get current user
 
 Get the User object for the current user:
 
-<notextile>
-<pre><code class="userinput">my $current_user = $arv->{'users'}->{'current'}->execute;
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $current_user = $arv->{'users'}->{'current'}->execute;
+{% endcodeblock %}
index fa059f7028cd25db55e693d26439b5ce91697ecf..a046654a64c7027afff48213a56303720e0fad3b 100644 (file)
@@ -12,22 +12,25 @@ SPDX-License-Identifier: CC-BY-SA-3.0
 
 h2. Cancel a container request
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 arvados.api().container_requests().update(uuid=container_request_uuid, body={"priority": 0}).execute()
-</code></pre>
+{% endcodeblock %}
 
 h2. Cancel all container requests
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
 result = api.container_requests().list(filters=[["state", "=", "Committed"], ["priority", ">", "0"]]).execute()["items"]
 for container_request in result:
     api.container_requests().update(uuid=container_request["uuid"], body={"priority": 0}).execute()
-</code></pre>
+{% endcodeblock %}
 
 h2. List completed container requests
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
 result = api.container_requests().list(filters=[["name", "like", name], ["state", "=", "Final"]]).execute()["items"]
 container_uuids = [cr["container_uuid"] for cr in result]
@@ -37,32 +40,37 @@ container_dict = {c["uuid"]: c for c in containers}
 for container_request in result:
     container = container_dict[container_request["container_uuid"]]
     print("%s, %s, %s" % (container_request["uuid"], container_request["name"], "Success" if container["exit_code"] == 0 else "Failed"))
-</code></pre>
+{% endcodeblock %}
 
 h2. Get input of a CWL workflow
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
+container_request_uuid="qr1hi-xvhdp-zzzzzzzzzzzzzzz"
 container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
 print(container_request["mounts"]["/var/lib/cwl/cwl.input.json"])
-</code></pre>
+{% endcodeblock %}
 
 h2. Get output of a CWL workflow
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 import arvados.collection
 api = arvados.api()
+container_request_uuid="qr1hi-xvhdp-zzzzzzzzzzzzzzz"
 container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
 collection = arvados.collection.CollectionReader(container_request["output_uuid"])
 print(collection.open("cwl.output.json").read())
-</code></pre>
+{% endcodeblock %}
 
 h2. List input of child requests
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
 parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
-namefilter = "bwa%"
+namefilter = "bwa%"  # the "like" filter uses SQL pattern match syntax
 container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
 parent_container_uuid = container_request["container_uuid"]
 child_requests = arvados.api().container_requests().list(filters=[
@@ -73,14 +81,15 @@ for c in child_requests["items"]:
     for m in c["mounts"].values():
         if "portable_data_hash" in m:
             print("  %s" % m["portable_data_hash"])
-</code></pre>
+{% endcodeblock %}
 
 h2. List output of child requests
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
-parent_request_uuid = "qr1hi-xvhdp-61y7cjymnhyp7yu"
-namefilter = "bwa%"
+parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
+namefilter = "bwa%"  # the "like" filter uses SQL pattern match syntax
 container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
 parent_container_uuid = container_request["container_uuid"]
 child_requests = arvados.api().container_requests().list(filters=[
@@ -91,13 +100,14 @@ collections = arvados.api().collections().list(filters=[["uuid", "in", output_uu
 uuid_to_pdh = {c["uuid"]: c["portable_data_hash"] for c in collections["items"]}
 for c in child_requests["items"]:
     print("%s -> %s" % (c["name"], uuid_to_pdh[c["output_uuid"]]))
-</code></pre>
+{% endcodeblock %}
 
 h2. List failed child requests
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
-parent_request_uuid = "qr1hi-xvhdp-3d8f1zatx1xio36"
+parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
 container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
 parent_container_uuid = container_request["container_uuid"]
 child_requests = arvados.api().container_requests().list(filters=[
@@ -108,38 +118,41 @@ cancelled_child_containers = arvados.api().containers().list(filters=[
     ["uuid", "in", child_containers.keys()]], limit=1000).execute()
 for c in cancelled_child_containers["items"]:
     print("%s (%s)" % (child_containers[c["uuid"]]["name"], child_containers[c["uuid"]]["uuid"]))
-</code></pre>
+{% endcodeblock %}
 
 h2. Get log of a child request
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 import arvados.collection
 api = arvados.api()
-container_request_uuid = "qr1hi-xvhdp-3d8f1zatx1xio36"
+container_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
 container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
 collection = arvados.collection.CollectionReader(container_request["log_uuid"])
 for c in collection:
     print(collection.open(c).read())
-</code></pre>
+{% endcodeblock %}
 
 h2. Create a collection sharing link
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 api = arvados.api()
 download="https://your.download.server"
-collection_uuid="your-4zz18-collectionuuid"
+collection_uuid="qr1hi-4zz18-zzzzzzzzzzzzzzz"
 token = api.api_client_authorizations().create(body={"api_client_authorization":{"scopes": [
     "GET /arvados/v1/collections/%s" % collection_uuid,
     "GET /arvados/v1/collections/%s/" % collection_uuid,
     "GET /arvados/v1/keep_services/accessible"]}}).execute()
 print("%s/c=%s/t=%s/_/" % (download, collection_uuid, token["api_token"]))
-</code></pre>
+{% endcodeblock %}
 
 h2. Combine two or more collections
 
 Note, if two collections have files of the same name, the contents will be concatenated in the resulting manifest.
 
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
 import arvados.collection
 api = arvados.api()
 project_uuid = "qr1hi-tpzed-zzzzzzzzzzzzzzz"
@@ -150,4 +163,4 @@ for u in collection_uuids:
     combined_manifest += c["manifest_text"]
 newcol = arvados.collection.Collection(combined_manifest)
 newcol.save_new(name="My combined collection", owner_uuid=project_uuid)
-</code></pre>
+{% endcodeblock %}
index 6f6ba99dede4de2109e4d6edadcbd051a91ccfb9..504d0784f0ca003610e3b72b630e75e2e4f4a141 100644 (file)
@@ -14,43 +14,43 @@ In these examples, the site prefix is @aaaaa@.
 
 h2.  Initialize SDK
 
-<pre>
+{% codeblock as python %}
 import arvados
 api = arvados.api("v1")
-</pre>
+{% endcodeblock %}
 
 h2. create
 
-<pre>
+{% codeblock as python %}
 result = api.collections().create(body={"collection": {"name": "create example"}}).execute()
-</pre>
+{% endcodeblock %}
 
 h2. delete
 
-<pre>
+{% codeblock as python %}
 result = api.collections().delete(uuid="aaaaa-4zz18-ccccccccccccccc").execute()
-</pre>
+{% endcodeblock %}
 
 h2. get
 
-<pre>
+{% codeblock as python %}
 result = api.collections().get(uuid="aaaaa-4zz18-ccccccccccccccc").execute()
-</pre>
+{% endcodeblock %}
 
 h2. list
 
-<pre>
+{% codeblock as python %}
 result = api.collections().list(filters=[["uuid", "=", "aaaaa-bbbbb-ccccccccccccccc"]]).execute()
-</pre>
+{% endcodeblock %}
 
 h2. update
 
-<pre>
+{% codeblock as python %}
 result = api.collections().update(uuid="aaaaa-4zz18-ccccccccccccccc", body={"collection": {"name": "update example"}}).execute()
-</pre>
+{% endcodeblock %}
 
 h2. Get current user
 
-<pre>
+{% codeblock as python %}
 result = api.users().current().execute()
-</pre>
+{% endcodeblock %}
index 621b664fb63c20f33c80199c80c5ccf9446fbdef..b8c0dcbb8036ac3be675e591ed1373d94575f491 100644 (file)
@@ -14,10 +14,10 @@ h2.  Initialize SDK
 
 Import the module and set up an API client user agent:
 
-<pre>
+{% codeblock as ruby %}
 require 'arvados'
 arv = Arvados.new(apiVersion: 'v1')
-</pre>
+{% endcodeblock %}
 
 The SDK retrieves the list of API methods from the server at run time. Therefore, the set of available methods is determined by the server version rather than the SDK version.
 
@@ -25,56 +25,57 @@ h2. create
 
 Create an object:
 
-<pre>
+{% codeblock as ruby %}
 new_link = arv.link.create(link: {link_class: 'test', name: 'test'})
-</pre>
+{% endcodeblock %}
 
 h2. delete
 
 Delete an object:
 
-<pre>
+{% codeblock as ruby %}
 arv.link.delete(uuid: new_link[:uuid])
-</pre>
+{% endcodeblock %}
 
 h2. get
 
 Retrieve an object by ID:
 
-<pre>
+{% codeblock as ruby %}
 some_user = arv.user.get(uuid: current_user_uuid)
-</pre>
+{% endcodeblock %}
 
 h2. list
 
 Get a list of objects:
 
-<pre>
+{% codeblock as ruby %}
 repos = arv.repository.list
 first_repo = repos[:items][0]
 puts "UUID of first repo returned is #{first_repo[:uuid]}"</code>
+{% endcodeblock %}
+
 UUID of first repo returned is qr1hi-s0uqq-b1bnybpx3u5temz
-</pre>
 
 h2. update
 
 Update an object:
 
-<pre>
+{% codeblock as ruby %}
 updated_link = arv.link.update(uuid: new_link[:uuid],
                                link: {properties: {foo: 'bar'}})
-</pre>
+{% endcodeblock %}
 
 h2. Get current user
 
 Get the User object for the current user:
 
-<pre>
+{% codeblock as ruby %}
 current_user = arv.user.current
-</pre>
+{% endcodeblock %}
 
 Get the UUID of an object that was retrieved using the SDK:
 
-<pre>
+{% codeblock as ruby %}
 current_user_uuid = current_user[:uuid]
-</pre>
+{% endcodeblock %}
index 4a6828188eb289d64272f9b30f39bf7e77b27835..baa8fe42db39ddbcd320c9b0cae48ac06bb301f3 100644 (file)
@@ -16,7 +16,7 @@ module Zenweb
     def render_liquid page, content
       liquid self.body, content, page, binding
     end
-    
+
     ##
     # Render a page's liquid and return the intermediate result
     def liquid template, content, page, binding = TOPLEVEL_BINDING
@@ -24,7 +24,7 @@ module Zenweb
       unless defined? @liquid_template
         @liquid_template = Liquid::Template.parse(template)
       end
-      
+
       vars = {}
       vars["content"] = content
 
@@ -38,7 +38,7 @@ module Zenweb
 
       vars["page"] = page.config.h.clone
       vars["page"]["url"] = page.url
-      
+
       @liquid_template.render(vars)
     end
   end
@@ -57,7 +57,7 @@ module Zenweb
         raise SyntaxError.new("Error in tag 'code' - Valid syntax: include '[code_file]' as '[language]'")
       end
     end
-    
+
     def render(context)
       require 'coderay'
 
@@ -71,6 +71,40 @@ module Zenweb
       html
     end
 
-    Liquid::Template.register_tag('code', LiquidCode)    
+    Liquid::Template.register_tag('code', LiquidCode)
+  end
+
+  class LiquidCodeBlock < Liquid::Block
+    Syntax = /((?:as)\s+(#{Liquid::QuotedFragment}+))?/o
+
+    def initialize(tag_name, markup, tokens)
+      Liquid::Tag.instance_method(:initialize).bind(self).call(tag_name, markup, tokens)
+
+      if markup =~ Syntax
+        @language = $2
+        @attributes = {}
+      else
+        raise SyntaxError.new("Error in tag 'code' - Valid syntax: codeblock as '[language]'")
+      end
+    end
+
+    def render(context)
+      require 'coderay'
+
+      partial = super
+      html = ''
+
+      if partial[0] == '\n'
+        partial = partial[1..-1]
+      end
+
+      context.stack do
+        html = CodeRay.scan(partial, @language).div
+      end
+
+      "<notextile>#{html}</notextile>"
+    end
+
+    Liquid::Template.register_tag('codeblock', LiquidCodeBlock)
   end
 end