Skip to content

Commit

Permalink
DEV: Format mustache templates (#473)
Browse files Browse the repository at this point in the history
Correct indentation, whitespace, and double-quotes.
  • Loading branch information
CvX authored Apr 19, 2021
1 parent efae3fa commit 907be5b
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 82 deletions.
4 changes: 2 additions & 2 deletions spec/lib/onebox/engine/github_folder_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe "#to_html" do
it "includes link to folder with truncated display path" do
expect(html).to include("<a href='https://github.com/discourse/discourse/tree/master/spec/fixtures' target=\"_blank\" rel=\"noopener\">master/spec/fixtures</a>")
expect(html).to include("<a href=\"https://github.com/discourse/discourse/tree/master/spec/fixtures\" target=\"_blank\" rel=\"noopener\">master/spec/fixtures</a>")
end

it "includes repository name" do
Expand All @@ -38,7 +38,7 @@
end

it "extracts subtitles when linking to docs" do
expect(@onebox.to_html).to include("<a href='https://github.com/discourse/discourse#setting-up-discourse' target=\"_blank\" rel=\"noopener\">discourse/discourse - Setting up Discourse</a>")
expect(@onebox.to_html).to include("<a href=\"https://github.com/discourse/discourse#setting-up-discourse\" target=\"_blank\" rel=\"noopener\">discourse/discourse - Setting up Discourse</a>")
end
end

Expand Down
8 changes: 6 additions & 2 deletions templates/_layout.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
{{#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>
<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>
<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>
2 changes: 1 addition & 1 deletion templates/allowlistedgeneric.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}

<h3><a href='{{link}}' target="_blank" rel="noopener">{{title}}</a></h3>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

{{#description}}
<p>{{description}}</p>
Expand Down
7 changes: 5 additions & 2 deletions templates/amazon.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}

<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

<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}}
Expand Down
78 changes: 44 additions & 34 deletions templates/githubblob.mustache
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
<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}}
{{#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;
{{! 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.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>
<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}}
Expand Down
4 changes: 1 addition & 3 deletions templates/githubcommit.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

<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>
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">
Expand All @@ -28,7 +27,6 @@
</a>
</div>
</div>

</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions templates/githubfolder.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}

<h3><a href='{{link}}' target="_blank" rel="noopener">{{title}}</a></h3>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

{{#path}}
<p><a href='{{link}}' target="_blank" rel="noopener">{{path}}</a></p>
<p><a href="{{link}}" target="_blank" rel="noopener">{{path}}</a></p>
{{/path}}

{{#description}}
Expand Down
15 changes: 9 additions & 6 deletions templates/githubgist.mustache
Original file line number Diff line number Diff line change
@@ -1,12 +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?}}
<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?}}
{{#truncated_files?}}
There are more than three files. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
{{/truncated_files?}}
</p>
6 changes: 3 additions & 3 deletions templates/githubissue.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

<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>
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>
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}}

Expand All @@ -27,7 +27,7 @@
</div>
</div>

<div class='labels'>
<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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/githubpullrequest.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<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>
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">
Expand Down
15 changes: 11 additions & 4 deletions templates/gitlabblob.mustache
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4>

{{^has_lines}}
<pre><code class='{{lang}}'>{{content}}</code></pre>
<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>
<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}}
Expand Down
4 changes: 2 additions & 2 deletions templates/googledocs.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a href='{{link}}' target="_blank" rel="noopener"><span class='googledocs-onebox-logo g-{{type}}-logo'></span></a>
<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>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

<p>{{description}}</p>
4 changes: 2 additions & 2 deletions templates/googledrive.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{^image}}
<a href='{{link}}' target="_blank" rel="noopener"><span class='googledocs-onebox-logo g-drive-logo'></span></a>
<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}}
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}

<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

Expand Down
3 changes: 2 additions & 1 deletion templates/googleplayapp.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h3>{{title}}</h3>
<img src="{{image}}" class="thumbnail"/>

<img src="{{image}}" class="thumbnail">
<p>{{description}}</p>
<em>{{price}}</em>
2 changes: 1 addition & 1 deletion templates/instagram.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{#image}}
<div class="instagram-images">
<a href="{{{link}}}" target="_blank" rel="noopener">
<img class="instagram-image" src="{{{image}}}"/>
<img class="instagram-image" src="{{{image}}}">
</a>
</div>
{{/image}}
Expand Down
8 changes: 6 additions & 2 deletions templates/pastebin.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +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?}}

<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?}}
9 changes: 6 additions & 3 deletions templates/pdf.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +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>
<a href="{{link}}" target="_blank" rel="noopener"><span class="pdf-onebox-logo"></span></a>

{{#filesize}}<p class='filesize'>{{filesize}}</p>{{/filesize}}
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

{{#filesize}}
<p class="filesize">{{filesize}}</p>
{{/filesize}}
1 change: 1 addition & 0 deletions templates/stackexchange.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<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>
Expand Down
25 changes: 20 additions & 5 deletions templates/twitterstatus.mustache
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
{{#avatar}}<img src="{{avatar}}" class="thumbnail onebox-avatar">{{/avatar}}

<h4><a href='{{link}}' target='_blank' rel='noopener'>{{title}}</a></h4>
<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="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 class='date'>
<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}}
</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}}
</svg>
{{retweets}}
</span>
{{/retweets}}
</div>
4 changes: 2 additions & 2 deletions templates/wikimedia.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}

<h3><a href='{{link}}' target='_blank' rel='noopener'>{{title}}</a></h3>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>
4 changes: 2 additions & 2 deletions templates/wikipedia.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
{{#image}}<img src="{{image}}" class="thumbnail">{{/image}}

<h3><a href='{{link}}' target='_blank' rel='noopener'>{{title}}</a></h3>
<h3><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h3>

<p>{{description}}</p>
Loading

0 comments on commit 907be5b

Please sign in to comment.