-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmydoc_help_api.html
More file actions
615 lines (421 loc) · 43 KB
/
mydoc_help_api.html
File metadata and controls
615 lines (421 loc) · 43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="You can loop through files and generate a JSON file that developers can consume like a help API. Developers can pull in values from the JSON into interface e...">
<meta name="keywords" content="publishingsingle_sourcingcontent_types, API, content API, UI text, inline help, context-sensitive help, popovers, tooltips">
<title>Help APIs and UI tooltips | IB-Ruby documentation</title>
<link rel="stylesheet" href="css/syntax.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->
<link rel="stylesheet" href="css/modern-business.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/customstyles.css">
<link rel="stylesheet" href="css/boxshadowproperties.css">
<!-- most color styles are extracted out to here -->
<link rel="stylesheet" href="css/theme-blue.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="js/jquery.navgoco.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Anchor.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.2.0/anchor.min.js"></script>
<script src="js/toc.js"></script>
<script src="js/customscripts.js"></script>
<link rel="shortcut icon" href="images/favicon.ico">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml" title="documentation-theme-jekyll" href="https://github.com/feed.xml">
<script>
$(document).ready(function() {
// Initialize navgoco with default options
$("#mysidebar").navgoco({
caretHtml: '',
accordion: true,
openClass: 'active', // open
save: false, // leave false or nav highlighting doesn't work right
cookie: {
name: 'navgoco',
expires: false,
path: '/'
},
slide: {
duration: 400,
easing: 'swing'
}
});
$("#collapseAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', false);
});
$("#expandAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', true);
});
});
</script>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
<script>
$(document).ready(function() {
$("#tg-sb-link").click(function() {
$("#tg-sb-sidebar").toggle();
$("#tg-sb-content").toggleClass('col-md-9');
$("#tg-sb-content").toggleClass('col-md-12');
$("#tg-sb-icon").toggleClass('fa-toggle-on');
$("#tg-sb-icon").toggleClass('fa-toggle-off');
});
});
</script>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container topnavlinks">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="fa fa-home fa-lg navbar-brand" href="index.html"> <span class="projectTitle"> IB-Ruby Doc</span></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<!-- toggle sidebar button -->
<li><a id="tg-sb-link" href="#"><i id="tg-sb-icon" class="fa fa-toggle-on"></i> Nav</a></li>
<!-- entries without drop-downs appear here -->
<li><a href="https://github.com/ib-ruby" target="_blank" rel="noopener">GitHub</a></li>
<li><a href="news">News</a></li>
<!-- entries with drop-downs appear here -->
<!-- conditional logic to control which topnav appears for the audience defined in the configuration file.-->
<!--comment out this block if you want to hide search-->
<li>
<!--start search-->
<div id="search-demo-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<script src="js/jekyll-search.js" type="text/javascript"></script>
<script type="text/javascript">
SimpleJekyllSearch.init({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
dataSource: 'search.json',
searchResultTemplate: '<li><a href="{url}" title="Help APIs and UI tooltips">{title}</a></li>',
noResultsText: 'No results found.',
limit: 10,
fuzzy: true,
})
</script>
<!--end search-->
</li>
</ul>
</div>
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div id="main">
<!-- Content Row -->
<div class="row">
<!-- Sidebar Column -->
<div class="col-md-3" id="tg-sb-sidebar">
<ul id="mysidebar" class="nav">
<li class="sidebarTitle"> </li>
<!-- if you aren't using the accordion, uncomment this block:
<p class="external">
<a href="#" id="collapseAll">Collapse All</a> | <a href="#" id="expandAll">Expand All</a>
</p>
-->
</ul>
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<script>$("li.active").parents('li').toggleClass("active");</script>
</div>
<!-- Content Column -->
<div class="col-md-9" id="tg-sb-content">
<div class="post-header">
<h1 class="post-title-main">Help APIs and UI tooltips</h1>
</div>
<div class="post-content">
<div class="summary">You can loop through files and generate a JSON file that developers can consume like a help API. Developers can pull in values from the JSON into interface elements, styling them as popovers for user interface text, for example. The beauty of this method is that the UI text remains in the help system (or at least in a single JSON file delivered to the dev team) and isn't hard-coded into the UI.</div>
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<script>
$( document ).ready(function() {
// Handler for .ready() called.
$('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3,h4' });
/* this offset helps account for the space taken up by the floating toolbar. */
$('#toc').on('click', 'a', function() {
var target = $(this.getAttribute('href'))
, scroll_target = target.offset().top
$(window).scrollTop(scroll_target - 10);
return false
})
});
</script>
<div id="toc"></div>
<h2 id="full-code-demo-of-content-api">Full code demo of content API</h2>
<p>You can create a help API that developers can use to pull in content.</p>
<p>For the full code demo, see the notes in the <a href="tooltips.html">Tooltips file</a>.</p>
<p>In this demo, the popovers pull in and display content from the information in a <a target="_blank" rel="noopener" href="tooltips.json">tooltips.json</a> file located in the same directory.</p>
<p>Instead of placing the JSON source in the same directory, you could also host the JSON file on another site.</p>
<p>Additionally, instead of tooltip popovers, you could also print content directly to the page. Basically, whatever you can stuff into a JSON file, developers can integrate it onto a page.</p>
<h2 id="diagram-overview">Diagram overview</h2>
<p>Here’s a diagram showing the basic idea of the help API:</p>
<p><img src="images/helpapi.svg" style="width: 650px;" /></p>
<p>Is this really an API? Well, sort of. The help content is pushed out into a JSON file that other websites and applications can easily consume. The endpoints don’t deliver different data based on parameters added to a URL. But the overall concept is similar to an API: you have a client requesting resources from a server.</p>
<p>Note that in this scenario, the help is openly accessible on the web. If you have a private system, it’s more complicated.</p>
<p>To deliver help this way using Jekyll, follow the steps in each of the sections below.</p>
<h2 id="1-create-a-collection-for-the-help-content">1. Create a “collection” for the help content</h2>
<p>A collection is another content type that extends Jekyll beyond the use of pages and posts. Call the collection “tooltips.”</p>
<p>Add the following information to your configuration file to declare your collection:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>collections:
tooltips:
output: false
</code></pre></div></div>
<p>In your Jekyll project’s root directory, create a new folder called “_tooltips” and put every page that you want to be part of that tooltips collection inside that folder.</p>
<p>In Jekyll, folders that begin with an underscore (“_”) aren’t included in the output. However, in the collection information that you add to your configuration file, if you change <code class="language-plaintext highlighter-rouge">output</code> to <code class="language-plaintext highlighter-rouge">true</code>, the tooltips folder will appear in the output, and each page inside tooltips will be generated. You most likely don’t want this for tooltips (you just want the JSON file), so make the <code class="language-plaintext highlighter-rouge">output</code> setting <code class="language-plaintext highlighter-rouge">false</code>.</p>
<h2 id="2-create-tooltip-definitions-in-a-yaml-file">2. Create tooltip definitions in a YAML file</h2>
<p>Inside the _data folder, create a YAML file called something like definitions.yml. Add the definitions for each of your tooltips here like this:</p>
<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">basketball</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Basketball</span><span class="nv"> </span><span class="s">is</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">sport</span><span class="nv"> </span><span class="s">involving</span><span class="nv"> </span><span class="s">two</span><span class="nv"> </span><span class="s">teams</span><span class="nv"> </span><span class="s">of</span><span class="nv"> </span><span class="s">five</span><span class="nv"> </span><span class="s">players</span><span class="nv"> </span><span class="s">each</span><span class="nv"> </span><span class="s">competing</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">put</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">ball</span><span class="nv"> </span><span class="s">through</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">small</span><span class="nv"> </span><span class="s">circular</span><span class="nv"> </span><span class="s">rim</span><span class="nv"> </span><span class="s">10</span><span class="nv"> </span><span class="s">feet</span><span class="nv"> </span><span class="s">above</span><span class="nv"> </span><span class="s">the</span><span class="nv"> </span><span class="s">ground.</span><span class="nv"> </span><span class="s">Basketball</span><span class="nv"> </span><span class="s">requires</span><span class="nv"> </span><span class="s">players</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">be</span><span class="nv"> </span><span class="s">in</span><span class="nv"> </span><span class="s">top</span><span class="nv"> </span><span class="s">physical</span><span class="nv"> </span><span class="s">condition,</span><span class="nv"> </span><span class="s">since</span><span class="nv"> </span><span class="s">they</span><span class="nv"> </span><span class="s">spend</span><span class="nv"> </span><span class="s">most</span><span class="nv"> </span><span class="s">of</span><span class="nv"> </span><span class="s">the</span><span class="nv"> </span><span class="s">game</span><span class="nv"> </span><span class="s">running</span><span class="nv"> </span><span class="s">back</span><span class="nv"> </span><span class="s">and</span><span class="nv"> </span><span class="s">forth</span><span class="nv"> </span><span class="s">along</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">94-foot-long</span><span class="nv"> </span><span class="s">floor."</span>
</code></pre></div></div>
<p>The definition of basketball is stored this data file so that you can re-use it in other parts of the help as well. You’ll likely want the definition to appear not only in the tooltip in the UI, but also in the regular documentation as well.</p>
<h2 id="3-create-pages-in-your-collection">3. Create pages in your collection</h2>
<p>Create pages inside your new tooltips collection (that is, inside the _tooltips folder). Each page needs to have a unique <code class="language-plaintext highlighter-rouge">id</code> in the frontmatter as well as a <code class="language-plaintext highlighter-rouge">product</code>. Then reference the definition you created in the definitions.yml file.</p>
<p>Here’s an example:</p>
<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="nn">---</span>
<span class="na">doc_id</span><span class="pi">:</span> <span class="s">basketball</span>
<span class="na">product</span><span class="pi">:</span> <span class="s">mydoc</span>
<span class="nn">---</span>
<span class="pi">{{</span><span class="nv">site.data.definitions.basketball</span><span class="pi">}}</span>
</code></pre></div></div>
<p>(Note: Avoid using <code class="language-plaintext highlighter-rouge">id</code>, as it seems to generate out as <code class="language-plaintext highlighter-rouge">/tooltips/basketball</code> instead of just `basketball.)</p>
<p>You need to create a separate file for each tooltip you want to deliver.</p>
<p>The product attribute is required in the frontmatter to distinguish the tooltips produced here from the tooltips for other products in the same _tooltips folder. When creating the JSON file, Jekyll will iterate through all the pages inside _tooltips, regardless of any subfolders included here.</p>
<h2 id="4-create-a-json-file-that-loops-through-your-collection-pages">4. Create a JSON file that loops through your collection pages</h2>
<p>Now it’s time to create a JSON file with Liquid code that iterates through our tooltip collection and grabs the information from each tooltip file.</p>
<p>Inside your project’s pages directory (e.g., mydoc), add a file called “tooltips.json.” (You can use whatever name you want.) Add the following to your JSON file:</p>
<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code>---
layout: null
search: exclude
---
{
"entries":
[
<span class="p">{%</span><span class="w"> </span><span class="nt">for</span><span class="w"> </span><span class="nv">page</span><span class="w"> </span><span class="nt">in</span><span class="w"> </span><span class="nv">site.tooltips</span><span class="w"> </span><span class="p">%}</span>
{
"doc_id": "<span class="p">{{</span><span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">doc_id</span><span class="w"> </span><span class="p">}}</span>",
"body": "<span class="p">{{</span><span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">content</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">strip_newlines</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">replace</span><span class="p">:</span><span class="w"> </span><span class="s1">'\'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\\\'</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">replace</span><span class="p">:</span><span class="w"> </span><span class="s1">'"'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\"'</span><span class="w"> </span><span class="p">}}</span>"
} <span class="p">{%</span><span class="w"> </span><span class="kr">unless</span><span class="w"> </span><span class="nb">forloop.last</span><span class="w"> </span><span class="p">%}</span>,<span class="p">{%</span><span class="w"> </span><span class="kr">endunless</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">endfor</span><span class="w"> </span><span class="p">%}</span>
]
}
</code></pre></div></div>
<p>This code will loop through all pages in the tooltips collection and insert the <code class="language-plaintext highlighter-rouge">id</code> and <code class="language-plaintext highlighter-rouge">body</code> into key-value pairs for the JSON code. Here’s an example of what that looks like after it’s processed by Jekyll in the site build:</p>
<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
</span><span class="nl">"entries"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
</span><span class="p">{</span><span class="w">
</span><span class="nl">"doc_id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"baseball"</span><span class="p">,</span><span class="w">
</span><span class="nl">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Baseball is considered America's pasttime sport, though that may be more of a historical term than a current one. There's a lot more excitement about football than baseball. A baseball game is somewhat of a snooze to watch, for the most part."</span><span class="w">
</span><span class="p">},</span><span class="w">
</span><span class="p">{</span><span class="w">
</span><span class="nl">"doc_id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"basketball"</span><span class="p">,</span><span class="w">
</span><span class="nl">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Basketball is a sport involving two teams of five players each competing to put a ball through a small circular rim 10 feet above the ground. Basketball requires players to be in top physical condition, since they spend most of the game running back and forth along a 94-foot-long floor."</span><span class="w">
</span><span class="p">},</span><span class="w">
</span><span class="p">{</span><span class="w">
</span><span class="nl">"doc_id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"football"</span><span class="p">,</span><span class="w">
</span><span class="nl">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"No doubt the most fun sport to watch, football also manages to accrue the most injuries with the players. From concussions to blown knees, football players have short sport lives."</span><span class="w">
</span><span class="p">},</span><span class="w">
</span><span class="p">{</span><span class="w">
</span><span class="nl">"doc_id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"soccer"</span><span class="p">,</span><span class="w">
</span><span class="nl">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"If there's one sport that dominates the world landscape, it's soccer. However, US soccer fans are few and far between. Apart from the popularity of soccer during the World Cup, most people don't even know the name of the professional soccer organization in their area."</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>
<p>You can also view the same JSON file here: <a target="_blank" rel="noopener" href="tooltips.json">tooltips.json</a>.</p>
<p>You can add different fields depending on how you want the JSON to be structured. Here we just have to fields: <code class="language-plaintext highlighter-rouge">doc_id</code> and <code class="language-plaintext highlighter-rouge">body</code>. And the JSON is looking just in the tooltips collection that we created.</p>
<div class="alert alert-info" role="alert"><i class="fa fa-bars"></i> Check out <a href="https://google.github.io/styleguide/jsoncstyleguide.xml">Google’s style guide</a> for JSON. These best practices can help you keep your JSON file valid.</div>
<p>Note that you can create different JSON files that specialize in different content. For example, suppose you have some getting started information. You could put that into a different JSON file. Using the same structure, you might add an <code class="language-plaintext highlighter-rouge">if</code> tag that checks whether the page has frontmatter that says <code class="language-plaintext highlighter-rouge">type: getting_started</code> or something. Or you could put the content into separate collection entirely (different from tooltips).</p>
<p>By chunking up your JSON files, you can provide a quicker lookup. (I’m not sure how big the JSON file can be before you experience any latency with the jQuery lookup.)</p>
<h2 id="5-build-your-site-and-look-for-the-json-file">5. Build your site and look for the JSON file</h2>
<p>When you build your site, Jekyll will iterate through every page in your _tooltips folder and put the page id and body into this format. In the output, look for the JSON file in the tooltips.json file. You’ll see that Jekyll has populated it with content. This is because of the triple hyphen lines in the JSON file — this instructs Jekyll to process the file.</p>
<h2 id="6-allow-cors-access-to-your-help-if-stored-on-a-remote-server">6. Allow CORS access to your help if stored on a remote server</h2>
<p>You can simply deliver the JSON file to devs to add to the project. But if you have the option, it’s best to keep the JSON file stored in your own help system. Assuming you have the ability to update your content on the fly, this will give you completely control over the tooltips without being tied to a specific release window.</p>
<p>When people make calls to your site <em>from other domains</em>, you must allow them access to get the content. To do this, you have to enable something called CORS (cross origin resource sharing) within the server where your help resides.</p>
<p>In other words, people are going to be executing calls to reach into your site and grab your content. Just like the door on your house, you have to unlock it so people can get in. Enabling CORS is unlocking it.</p>
<p>How you enable CORS depends on the type of server.</p>
<p>If your server setup allows htaccess files to override general server permissions, create an .htaccess file and add the following:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Header set Access-Control-Allow-Origin "*"
</code></pre></div></div>
<p>Store this in the same directory as your project. This is what I’ve done in a directory on my web host (bluehost.com). Inside http://idratherassets.com/wp-content/apidemos/, I uploaded a file called “.htaccess” with the preceding code.</p>
<p>After I uploaded it, I renamed it to .htaccess, right-clicked the file and set the permissions to 774.</p>
<p>To test whether your server permissions are set correctly, open a terminal and run the following curl command pointing to your tooltips.json file:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl -I http://idratherassets.com/wp-content/apidemos/tooltips.json
</code></pre></div></div>
<p>The <code class="language-plaintext highlighter-rouge">-I</code> command tells cURL to return the request header only.</p>
<p>If the server permissions are set correctly, you should see the following line somewhere in the response:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Access-Control-Allow-Origin: *
</code></pre></div></div>
<p>If you don’t see this response, CORS isn’t allowed for the file.</p>
<p>If you have an AWS S3 bucket, you can supposedly add a CORS configuration to the bucket permissions. Log into AWS S3 and click your bucket. On the right, in the Permissions section, click <strong>Add CORS Configuration</strong>. In that space, add the following policy:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><CORSConfiguration></span>
<span class="nt"><CORSRule></span>
<span class="nt"><AllowedOrigin></span>*<span class="nt"></AllowedOrigin></span>
<span class="nt"><AllowedMethod></span>GET<span class="nt"></AllowedMethod></span>
<span class="nt"></CORSRule></span>
<span class="nt"></CORSConfiguration></span>
</code></pre></div></div>
<p>(Although this should work, in my experiment it doesn’t. And I’m not sure why…)</p>
<p>In other server setups, you may need to edit one of your Apache configuration files. See <a href="http://enable-cors.org/server.html">Enable CORS</a> or search online for ways to allow CORS for your server.</p>
<p>If you don’t have CORS enabled, users will see a CORS error/warning message in the console of the page making the request.</p>
<div class="alert alert-info" role="alert"><i class="fa fa-bars"></i> If enabling CORS is problematic, you could always just send developers the tooltips.json file and ask them to place it on their own server.</div>
<h2 id="7-explain-how-developers-can-access-the-help">7. Explain how developers can access the help</h2>
<p>Developers can access the help using the <code class="language-plaintext highlighter-rouge">.get</code> method from jQuery, among other methods. Here’s an example of how to get tooltips for basketball, baseball, football, and soccer:</p>
<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">tooltips.json</span><span class="dl">"</span><span class="p">;</span>
<span class="nx">$</span><span class="p">.</span><span class="kd">get</span><span class="p">(</span> <span class="nx">url</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">data</span> <span class="p">)</span> <span class="p">{</span>
<span class="cm">/* Bootstrap popover text is defined inside a data-content attribute inside an element. That's
why I'm using attr here. If you just want to insert content on the page, use append and remove the data-content argument from the parentheses.*/</span>
<span class="nx">$</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">entries</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">page</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">page</span><span class="p">.</span><span class="nx">doc_id</span> <span class="o">==</span> <span class="dl">"</span><span class="s2">basketball</span><span class="dl">"</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span> <span class="dl">"</span><span class="s2">#basketball</span><span class="dl">"</span> <span class="p">).</span><span class="nx">attr</span><span class="p">(</span> <span class="dl">"</span><span class="s2">data-content</span><span class="dl">"</span><span class="p">,</span> <span class="nx">page</span><span class="p">.</span><span class="nx">body</span> <span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">page</span><span class="p">.</span><span class="nx">doc_id</span> <span class="o">==</span> <span class="dl">"</span><span class="s2">baseball</span><span class="dl">"</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span> <span class="dl">"</span><span class="s2">#baseball</span><span class="dl">"</span> <span class="p">).</span><span class="nx">attr</span><span class="p">(</span> <span class="dl">"</span><span class="s2">data-content</span><span class="dl">"</span><span class="p">,</span> <span class="nx">page</span><span class="p">.</span><span class="nx">body</span> <span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">page</span><span class="p">.</span><span class="nx">doc_id</span> <span class="o">==</span> <span class="dl">"</span><span class="s2">football</span><span class="dl">"</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span> <span class="dl">"</span><span class="s2">#football</span><span class="dl">"</span> <span class="p">).</span><span class="nx">attr</span><span class="p">(</span> <span class="dl">"</span><span class="s2">data-content</span><span class="dl">"</span><span class="p">,</span> <span class="nx">page</span><span class="p">.</span><span class="nx">body</span> <span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">page</span><span class="p">.</span><span class="nx">doc_id</span> <span class="o">==</span> <span class="dl">"</span><span class="s2">soccer</span><span class="dl">"</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span> <span class="dl">"</span><span class="s2">#soccer</span><span class="dl">"</span> <span class="p">).</span><span class="nx">attr</span><span class="p">(</span> <span class="dl">"</span><span class="s2">data-content</span><span class="dl">"</span><span class="p">,</span> <span class="nx">page</span><span class="p">.</span><span class="nx">body</span> <span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">});</span>
</code></pre></div></div>
<p>View the <a target="_blank" rel="noopener" href="tooltips.html" class="noCrossRef">tooltip demo</a> for a demonstration. See the source code for full code details.</p>
<p>The <code class="language-plaintext highlighter-rouge">url</code> in the demo is relative, but you could equally point it to an absolute path on a remote host assuming CORS is enabled on the host.</p>
<p>The <code class="language-plaintext highlighter-rouge">each</code> method looks through all the JSON content to find the item whose <code class="language-plaintext highlighter-rouge">page.id</code> is equal to <code class="language-plaintext highlighter-rouge">basketball</code>. It then looks for an element on the page named <code class="language-plaintext highlighter-rouge">#basketball</code> and adds a <code class="language-plaintext highlighter-rouge">data-content</code> attribute to that element.</p>
<div class="alert alert-danger" role="alert"><i class="fa fa-exclamation-circle"></i> <b>Warning:</b> Make sure your JSON file is valid. Otherwise, this method won’t work. I use the <a href="https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en">JSON Formatter extension for Chrome</a>. When I go to the tooltips.json page in my browser, the JSON content — if valid — is nicely formatted (and includes some color coding). If the file isn’t valid, it’s not formatted and there isn’t any color. You can also check the JSON formatting using <a href="http://jsonformatter.curiousconcept.com/">JSON Formatter and Validator</a>. If your JSON file isn’t valid, identify the problem area using the validator and troubleshoot the file causing issues. It’s usually due to some code that isn’t escaping correctly.</div>
<p>Why <code class="language-plaintext highlighter-rouge">data-content</code>? Well, in this case, I’m using <a href="http://getbootstrap.com/javascript/#popovers">Bootstrap popovers</a> to display the tooltip content. The <code class="language-plaintext highlighter-rouge">data-content</code> attribute is how Bootstrap injects popovers.</p>
<p>Here’s the section on the page where the popover is inserted:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><p>Basketball <span class="glyphicon glyphicon-info-sign" id="basketball" data-toggle="popover"></span></p>
</code></pre></div></div>
<p>Notice that I just have <code class="language-plaintext highlighter-rouge">id="basketball"</code> added to this popover element. Developers merely need to add a unique ID to each tooltip they want to pull in the help content. Either you tell developers the unique ID they should add, or ask them what IDs they added (or just tell them to use an ID that matches the field’s name).</p>
<p>In order to use jQuery and Bootstrap, you’ll need to add the appropriate references in the head tags of your page:</p>
<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o"><</span><span class="nx">link</span> <span class="nx">rel</span><span class="o">=</span><span class="dl">"</span><span class="s2">stylesheet</span><span class="dl">"</span> <span class="nx">href</span><span class="o">=</span><span class="dl">"</span><span class="s2">https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css</span><span class="dl">"</span><span class="o">></span>
<span class="o"><</span><span class="nx">script</span> <span class="nx">src</span><span class="o">=</span><span class="dl">"</span><span class="s2">https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js</span><span class="dl">"</span><span class="o">><</span><span class="sr">/script</span><span class="err">>
</span><span class="o"><</span><span class="nx">script</span> <span class="nx">src</span><span class="o">=</span><span class="dl">"</span><span class="s2">https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js</span><span class="dl">"</span><span class="o">><</span><span class="sr">/script</span><span class="err">>
</span>
<span class="o"><</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="dl">"</span><span class="s2">text/javascript</span><span class="dl">"</span><span class="o">></span>
<span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">[data-toggle="popover"]</span><span class="dl">'</span><span class="p">).</span><span class="nx">popover</span><span class="p">({</span>
<span class="na">placement</span> <span class="p">:</span> <span class="dl">'</span><span class="s1">right</span><span class="dl">'</span><span class="p">,</span>
<span class="na">trigger</span><span class="p">:</span> <span class="dl">'</span><span class="s1">hover</span><span class="dl">'</span><span class="p">,</span>
<span class="na">html</span><span class="p">:</span> <span class="kc">true</span>
<span class="p">});</span>
<span class="o"><</span><span class="sr">/script</span><span class="err">>
</span></code></pre></div></div>
<p>Again, see the <a class="noCrossRef" href="tooltips.html">Tooltip Demo</a> for a demo of the full code.</p>
<p>Note that even though you reference a Bootstrap JS script, Bootstrap’s popovers require you to initialize them using the above code as well — they aren’t turned on by default.</p>
<p>View the source code of the <a target="_blank" rel="noopener" href="tooltips.html" class="noCrossRef">tooltip demo</a> for the full comments.</p>
<h2 id="8-create-easy-links-to-embed-the-help-in-your-help-site">8. Create easy links to embed the help in your help site</h2>
<p>You might also want to insert the same content into different parts of your help site. For example, if you have tooltips providing definitions for fields, you’ll probably want to create a page in your help that lists those same definitions.</p>
<p>You could use the same method developers use to pull help content into their applications. But it will probably be easier to simply use Jekyll’s tags for doing it.</p>
<p>Here’s how you would reuse the content:</p>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><h2></span>Reuse Demo<span class="nt"></h2></span>
<span class="nt"><table></span>
<span class="nt"><thead></span>
<span class="nt"><tr></span>
<span class="nt"><th></span>Sport<span class="nt"></th></span>
<span class="nt"><th></span>Comments<span class="nt"></th></span>
<span class="nt"></tr></span>
<span class="nt"></thead></span>
<span class="nt"><tbody></span>
<span class="nt"><tr></span>
<span class="nt"><td></span>Basketball<span class="nt"></td></span>
<span class="nt"><td></span>{{site.data.definitions.basketball}}<span class="nt"></td></span>
<span class="nt"></tr></span>
<span class="nt"><tr></span>
<span class="nt"><td></span>Baseball<span class="nt"></td></span>
<span class="nt"><td></span>{{site.data.definitions.baseball}}<span class="nt"></td></span>
<span class="nt"></tr></span>
<span class="nt"><tr></span>
<span class="nt"><td></span>Football<span class="nt"></td></span>
<span class="nt"><td></span>{{site.data.definitions.football}}<span class="nt"></td></span>
<span class="nt"></tr></span>
<span class="nt"><tr></span>
<span class="nt"><td></span>Soccer<span class="nt"></td></span>
<span class="nt"><td></span>{{site.data.definitions.soccer}}<span class="nt"></td></span>
<span class="nt"></tr></span>
<span class="nt"></tbody></span>
<span class="nt"></table></span>
</code></pre></div></div>
<p>And here’s the code:</p>
<h2>Reuse Demo</h2>
<table>
<thead>
<tr>
<th>Sport</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>Basketball</td>
<td>Basketball is a sport involving two teams of five players each competing to put a ball through a small circular rim 10 feet above the ground. Basketball requires players to be in top physical condition, since they spend most of the game running back and forth along a 94-foot-long floor.</td>
</tr>
<tr>
<td>Baseball</td>
<td>Baseball is considered America's pasttime sport, though that may be more of a historical term than a current one. There's a lot more excitement about football than baseball. A baseball game is somewhat of a snooze to watch, for the most part.</td>
</tr>
<tr>
<td>Football</td>
<td>No doubt the most fun sport to watch, football also manages to accrue the most injuries with the players. From concussions to blown knees, football players have short sport lives.</td>
</tr>
<tr>
<td>Soccer</td>
<td>If there's one sport that dominates the world landscape, it's soccer. However, US soccer fans are few and far between. Apart from the popularity of soccer during the World Cup, most people don't even know the name of the professional soccer organization in their area.</td>
</tr>
</tbody>
</table>
<p>Now you have both documentation and UI tooltips generated from the same definitions file.</p>
<div class="tags">
<b>Tags: </b>
<a href="tag_publishing.html" class="btn btn-default navbar-btn cursorNorm" role="button">publishing</a>
<a href="tag_single_sourcing.html" class="btn btn-default navbar-btn cursorNorm" role="button">single_sourcing</a>
<a href="tag_content_types.html" class="btn btn-default navbar-btn cursorNorm" role="button">content_types</a>
</div>
</div>
<hr class="shaded"/>
<footer>
<div class="row">
<div class="col-lg-12 footer">
©2021 IB-Ruby. All rights reserved. <br />
<span>Page last updated:</span> July 3, 2016<br/> Site last generated: Jul 27, 2021 <br />
<p><img src="images/company_logo.png" alt="Company logo"/></p>
</div>
</div>
</footer>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
<!-- /#main -->
</div>
</body>
</html>