DEV: Absorb onebox gem into core (#12979)

* Move onebox gem in core library

* Update template file path

* Remove warning for onebox gem caching

* Remove onebox version file

* Remove onebox gem

* Add sanitize gem

* Require onebox library in lazy-yt plugin

* Remove onebox web specific code

This code was used in standalone onebox Sinatra application

* Merge Discourse specific AllowlistedGenericOnebox engine in core

* Fix onebox engine filenames to match class name casing

* Move onebox specs from gem into core

* DEV: Rename `response` helper to `onebox_response`

Fixes a naming collision.

* Require rails_helper

* Don't use `before/after(:all)`

* Whitespace

* Remove fakeweb

* Remove poor unit tests

* DEV: Re-add fakeweb, plugins are using it

* Move onebox helpers

* Stub Instagram API

* FIX: Follow additional redirect status codes (#476)

Don’t throw errors if we encounter 303, 307 or 308 HTTP status codes in responses

* Remove an empty file

* DEV: Update the license file

Using the copy from https://choosealicense.com/licenses/gpl-2.0/#

Hopefully this will enable GitHub to show the license UI?

* DEV: Update embedded copyrights

* DEV: Add Onebox copyright notice

* DEV: Add MIT license, convert COPYRIGHT.txt to md

* DEV: Remove an incorrect copyright claim

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: jbrw <jamie@goatforce5.org>
This commit is contained in:
Arpit Jalan
2021-05-26 15:11:35 +05:30
committed by GitHub
parent d0779a87bb
commit 283b08d45f
211 changed files with 78330 additions and 74 deletions

View File

@ -0,0 +1,25 @@
<aside class="onebox {{subname}}">
<header class="source">
{{#favicon}}
<img src="{{favicon}}" class="site-icon"/>
{{/favicon}}
{{#article_published_time}}
<a href="{{link}}" target="_blank" rel="noopener" title="{{article_published_time_title}}">{{domain}} &ndash; {{article_published_time}}</a>
{{/article_published_time}}
{{^article_published_time}}
<a href="{{link}}" target="_blank" rel="noopener">{{domain}}</a>
{{/article_published_time}}
</header>
<article class="onebox-body">
{{{view}}}
</article>
<div class="onebox-metadata">
{{#metadata_1_label}}<span style="float: left;">{{metadata_1_label}}: {{metadata_1_value}}</span>{{/metadata_1_label}}
{{#metadata_2_label}}<span style="float: right;">{{metadata_2_label}}: {{metadata_2_value}}</span>{{/metadata_2_label}}
</div>
<div style="clear: both"></div>
</aside>

View File

@ -0,0 +1,16 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
{{#description}}
<p>{{description}}</p>
{{/description}}
{{#data_1}}
<p>
<span class="label1">{{label_1}}: {{data_1}}</span>
{{#data_2}}
<span class="label2">{{label_2}}: {{data_2}}</span>
{{/data_2}}
</p>
{{/data_1}}

View File

@ -0,0 +1,15 @@
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
{{#by_info}}<b>{{by_info}}</b>{{/by_info}}
<p>{{description}}</p>
<p>
{{#rating}}{{rating}}{{/rating}}
{{#isbn_asin}}{{isbn_asin_text}}: {{isbn_asin}}, {{/isbn_asin}}
{{#publisher}}{{publisher}}, {{/publisher}}
{{#published}}{{published}}{{/published}}
{{#price}}<strong>{{price}}</strong>{{/price}}
</p>

View File

@ -0,0 +1,5 @@
{{#body}}
<div class="github-row">
<p class="github-body-container">{{body}}{{#excerpt}}<span class="show-more-container"><a href="{{html_url}}" target="_blank" rel="noopener" class="show-more">…</a>{{/excerpt}}</span>{{#excerpt}}<span class="excerpt hidden">{{excerpt}}</span>{{/excerpt}}</p>
</div>
{{/body}}

View File

@ -0,0 +1,54 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4>
{{^has_lines}}
{{#model_file}}
<iframe class="render-viewer" width="{{width}}" height="{{height}}" src="{{content}}" sandbox="allow-scripts allow-same-origin allow-top-navigation ">
Viewer requires iframe.
</iframe>
{{/model_file}}
{{^model_file}}
<pre><code class="{{lang}}">{{content}}</code></pre>
{{/model_file}}
{{/has_lines}}
{{#has_lines}}
{{! This is a template comment | Sample rules for this box
<style>
pre.onebox code ol{
margin-left:0px;
}
pre.onebox code ol .lines{
margin-left:30px;
}
pre.onebox code ol.lines li {
list-style-type: decimal;
margin-left:45px;
}
pre.onebox code li{
list-style-type: none;
background-color:#fff;
border-bottom:1px solid #F0F0F0;
padding-left:5px;
}
pre.onebox code li.selected{
background-color:#cfc
}
</style>
}}
<pre class="onebox">
<code class="{{lang}}">
<ol class="start lines" start="{{cr_results.from}}" style="counter-reset: li-counter {{cr_results.from_minus_one}} ;">
{{#lines}}
<li{{#selected}} class="selected"{{/selected}}>{{data}}</li>
{{/lines}}
</ol>
</code>
</pre>
{{/has_lines}}
{{#truncated}}
This file has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
{{/truncated}}

View File

@ -0,0 +1,33 @@
<div class="github-row">
<div class="github-icon-container" title="Commit">
<svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M10.86 7c-.45-1.72-2-3-3.86-3-1.86 0-3.41 1.28-3.86 3H0v2h3.14c.45 1.72 2 3 3.86 3 1.86 0 3.41-1.28 3.86-3H14V7h-3.14zM7 10.2c-1.22 0-2.2-.98-2.2-2.2 0-1.22.98-2.2 2.2-2.2 1.22 0 2.2.98 2.2 2.2 0 1.22-.98 2.2-2.2 2.2z"></path></svg>
</div>
<div class="github-info-container">
<h4>
<a href="{{html_url}}" target="_blank" rel="noopener">{{title}}</a>
</h4>
<div class="github-info">
<div class="date">
committed <span class="discourse-local-date" data-format="ll" data-date="{{committed_at_date}}" data-time="{{committed_at_time}}" data-timezone="UTC">{{committed_at}}</span>
</div>
<div class="user">
<a href="{{author.html_url}}" target="_blank" rel="noopener">
<img alt="{{author.login}}" src="{{author.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
{{author.login}}
</a>
</div>
<div class="lines" title="changed {{files.length}} files with {{stats.additions}} additions and {{stats.deletions}} deletions">
<a href="{{html_url}}" target="_blank" rel="noopener">
<span class="added">+{{stats.additions}}</span>
<span class="removed">-{{stats.deletions}}</span>
</a>
</div>
</div>
</div>
</div>
{{> github/github_body}}

View File

@ -0,0 +1,11 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
{{#path}}
<p><a href="{{link}}" target="_blank" rel="noopener">{{path}}</a></p>
{{/path}}
{{#description}}
<p><span class="label1">{{description}}</span></p>
{{/description}}

View File

@ -0,0 +1,15 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{link}}</a></h4>
{{#gist_files}}
<h5>{{filename}}</h5>
<pre><code class="{{language}}">{{content}}</code></pre>
{{#truncated?}}
This file has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
{{/truncated?}}
{{/gist_files}}
<p>
{{#truncated_files?}}
There are more than three files. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
{{/truncated_files?}}
</p>

View File

@ -0,0 +1,38 @@
<div class="github-row">
<div class="github-icon-container" title="Issue">
<svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
</div>
<div class="github-info-container">
<h4>
<a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
</h4>
<div class="github-info">
<div class="date">
opened <span class="discourse-local-date" data-format="ll" data-date="{{created_at_date}}" data-time="{{created_at_time}}" data-timezone="UTC">{{created_at}}</span>
</div>
{{#closed_at}}
<div class="date">
closed <span class="discourse-local-date" data-format="ll" data-date="{{closed_at_date}}" data-time="{{closed_at_time}}" data-timezone="UTC">{{closed_at}}</span>
</div>
{{/closed_at}}
<div class="user">
<a href="{{user.html_url}}" target="_blank" rel="noopener">
<img alt="{{user.login}}" src="{{user.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
{{user.login}}
</a>
</div>
</div>
<div class="labels">
{{#labels}}
<span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">{{name}}</span>
{{/labels}}
</div>
</div>
</div>
{{> github/github_body}}

View File

@ -0,0 +1,37 @@
<div class="github-row">
<div class="github-icon-container" title="Pull Request">
<svg width="60" height="60" class="github-icon" viewBox="0 0 12 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
</div>
<div class="github-info-container">
<h4>
<a href="{{html_url}}" target="_blank" rel="noopener">{{title}}</a>
</h4>
<div class="branches">
<code>{{base.label}}</code> ← <code>{{head.label}}</code>
</div>
<div class="github-info">
<div class="date">
opened <span class="discourse-local-date" data-format="ll" data-date="{{created_at_date}}" data-time="{{created_at_time}}" data-timezone="UTC">{{created_at}}</span>
</div>
<div class="user">
<a href="{{user.html_url}}" target="_blank" rel="noopener">
<img alt="{{user.login}}" src="{{user.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
{{user.login}}
</a>
</div>
<div class="lines" title="{{commits}} commits changed {{changed_files}} files with {{additions}} additions and {{deletions}} deletions">
<a href="{{html_url}}/files" target="_blank" rel="noopener">
<span class="added">+{{additions}}</span>
<span class="removed">-{{deletions}}</span>
</a>
</div>
</div>
</div>
</div>
{{> github/github_body}}

View File

@ -0,0 +1,21 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4>
{{^has_lines}}
<pre><code class="{{lang}}">{{content}}</code></pre>
{{/has_lines}}
{{#has_lines}}
<pre class="onebox">
<code class="{{lang}}">
<ol class="start lines" start="{{cr_results.from}}" style="counter-reset: li-counter {{cr_results.from_minus_one}} ;">
{{#lines}}
<li{{#selected}} class="selected"{{/selected}}>{{data}}</li>
{{/lines}}
</ol>
</code>
</pre>
{{/has_lines}}
{{#truncated}}
This file has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
{{/truncated}}

View File

@ -0,0 +1,5 @@
<a href="{{link}}" target="_blank" rel="noopener"><span class="googledocs-onebox-logo g-{{type}}-logo"></span></a>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
<p>{{description}}</p>

View File

@ -0,0 +1,9 @@
{{^image}}
<a href="{{link}}" target="_blank" rel="noopener"><span class="googledocs-onebox-logo g-drive-logo"></span></a>
{{/image}}
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
<p>{{description}}</p>

View File

@ -0,0 +1,5 @@
<h3>{{title}}</h3>
<img src="{{image}}" class="thumbnail">
<p>{{description}}</p>
<em>{{price}}</em>

View File

@ -0,0 +1,13 @@
<h3><a href="{{{link}}}" target="_blank" rel="noopener">{{title}}</a></h3>
{{#image}}
<div class="instagram-images">
<a href="{{{link}}}" target="_blank" rel="noopener">
<img class="instagram-image" src="{{{image}}}">
</a>
</div>
{{/image}}
{{#description}}
<div class="instagram-description">{{description}}</div>
{{/description}}

View File

@ -0,0 +1,7 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{link}}</a></h4>
<pre><code class="lang-auto">{{content}}</code></pre>
{{#truncated?}}
This paste has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
{{/truncated?}}

View File

@ -0,0 +1,7 @@
<a href="{{link}}" target="_blank" rel="noopener"><span class="pdf-onebox-logo"></span></a>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
{{#filesize}}
<p class="filesize">{{filesize}}</p>
{{/filesize}}

View File

@ -0,0 +1,12 @@
<h4>
<a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
</h4>
<div class="date">
{{authors}},
<i>{{journal}}</i>, {{date}}
</div>
<p class="pubmed-abstract">
{{abstract}}
</p>

View File

@ -0,0 +1,22 @@
{{#owner.profile_image}}
<a href="{{owner.link}}" target="_blank" rel="noopener">
<img alt="{{owner.display_name}}" src="{{owner.profile_image}}" class="thumbnail onebox-avatar">
</a>
{{/owner.profile_image}}
<h4>
<a href="{{link}}" target="_blank" rel="noopener">{{{title}}}</a>
</h4>
<div class="tags">
<strong>{{tags}}</strong>
</div>
<div class="date">
{{#is_question}}asked by{{/is_question}}
{{#is_answer}}answered by{{/is_answer}}
<a href="{{owner.link}}" target="_blank" rel="noopener">
{{owner.display_name}}
</a>
on <a href="{{link}}" target="_blank" rel="noopener">{{creation_date}}</a>
</div>

View File

@ -0,0 +1,38 @@
{{#avatar}}<img src="{{avatar}}" class="thumbnail onebox-avatar">{{/avatar}}
<h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4>
<div class="tweet">
{{{tweet}}}
{{#quoted_tweet}}
<div class="quoted">
<a class="quoted-link" href="{{quoted_link}}">
<p class="quoted-title">{{quoted_full_name}} <span>@{{quoted_screen_name}}</span></p>
</a>
<div>{{quoted_tweet}}</div>
</div>
{{/quoted_tweet}}
</div>
<div class="date">
<a href="{{link}}" target="_blank" rel="noopener">{{timestamp}}</a>
{{#likes}}
<span class="like">
<svg viewBox="0 0 512 512" width="14px" height="16px" aria-hidden="true">
<path d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path>
</svg>
{{likes}}
</span>
{{/likes}}
{{#retweets}}
<span class="retweet">
<svg viewBox="0 0 640 512" width="14px" height="16px" aria-hidden="true">
<path d="M629.657 343.598L528.971 444.284c-9.373 9.372-24.568 9.372-33.941 0L394.343 343.598c-9.373-9.373-9.373-24.569 0-33.941l10.823-10.823c9.562-9.562 25.133-9.34 34.419.492L480 342.118V160H292.451a24.005 24.005 0 0 1-16.971-7.029l-16-16C244.361 121.851 255.069 96 276.451 96H520c13.255 0 24 10.745 24 24v222.118l40.416-42.792c9.285-9.831 24.856-10.054 34.419-.492l10.823 10.823c9.372 9.372 9.372 24.569-.001 33.941zm-265.138 15.431A23.999 23.999 0 0 0 347.548 352H160V169.881l40.416 42.792c9.286 9.831 24.856 10.054 34.419.491l10.822-10.822c9.373-9.373 9.373-24.569 0-33.941L144.971 67.716c-9.373-9.373-24.569-9.373-33.941 0L10.343 168.402c-9.373 9.373-9.373 24.569 0 33.941l10.822 10.822c9.562 9.562 25.133 9.34 34.419-.491L96 169.881V392c0 13.255 10.745 24 24 24h243.549c21.382 0 32.09-25.851 16.971-40.971l-16.001-16z"></path>
</svg>
{{retweets}}
</span>
{{/retweets}}
</div>

View File

@ -0,0 +1,3 @@
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

View File

@ -0,0 +1,5 @@
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
<p>{{description}}</p>

View File

@ -0,0 +1,7 @@
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
{{#image}}
<div class="xkcd-image"><img src="{{image}}"></div>
{{/image}}
<p>{{description}}</p>