Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Liquid Tags (#590)
* Fix glitch tag

* Add custom solutions for default liquid tags

* Update liquid tags regex

* Add speakerdeck tag and format guide a bit
  • Loading branch information
Zhao-Andy authored and maestromac committed Sep 4, 2018
1 parent d9b6941 commit 832e892
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 13 deletions.
7 changes: 7 additions & 0 deletions app/liquid_tags/assign_tag.rb
@@ -0,0 +1,7 @@
class AssignTag < Liquid::Block
def initialize(_tag_name, _markup, _options)
raise StandardError.new("Liquid's Assign tag is disabled")
end
end

Liquid::Template.register_tag("assign".freeze, AssignTag)
7 changes: 7 additions & 0 deletions app/liquid_tags/cycle_tag.rb
@@ -0,0 +1,7 @@
class CycleTag < Liquid::Block
def initialize(_tag_name, _markup, _options)
raise StandardError.new("Liquid's Cycle tag is disabled")
end
end

Liquid::Template.register_tag("cycle".freeze, CycleTag)
8 changes: 7 additions & 1 deletion app/liquid_tags/glitch_tag.rb
Expand Up @@ -20,7 +20,13 @@ def render(_context)
private

def parse_id(input)
input.delete(" ")
input_no_space = input.delete(" ")
raise StandardError, "Invalid Glitch ID" unless valid_id?(input_no_space)
input_no_space
end

def valid_id?(input)
(input =~ /^[a-zA-Z0-9\-]{1,110}$/)&.zero?
end
end

Expand Down
7 changes: 7 additions & 0 deletions app/liquid_tags/include_tag.rb
@@ -0,0 +1,7 @@
class IncludeTag < Liquid::Block
def initialize(_tag_name, _markup, _options)
raise StandardError.new("Liquid's Include tag is disabled")
end
end

Liquid::Template.register_tag("include".freeze, IncludeTag)
2 changes: 1 addition & 1 deletion app/liquid_tags/replit_tag.rb
Expand Up @@ -22,7 +22,7 @@ def parse_id(input)
end

def valid_id?(id)
id.length > 1 && id =~ /[a-zA-Z0-9\/]/
id =~ /\A\@[\w]{2,15}\/[a-zA-Z0-9\-]{0,60}\Z/
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/liquid_tags/speakerdeck_tag.rb
Expand Up @@ -41,7 +41,7 @@ def parse_id(input)
end

def valid_id?(id)
!!(id =~ /\A[a-z\d]*\Z/i)
id =~ /\A[a-z\d]{32}\Z/i
end
end

Expand Down
28 changes: 20 additions & 8 deletions app/views/pages/_editor_guide_text.html.erb
Expand Up @@ -35,16 +35,16 @@
<h3><strong>Inline Images</strong></h3>
<p>
<img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OsLaFSo9--/c_fill,f_auto,fl_progressive,h_220,q_auto,w_220/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg" alt="example image, with sloan"></img>
<code>
<pre>
![Alt text of image](put-link-to-image-here)
<figcaption> You can even add a caption using the figcaption tag!</figcaption>
</code>
</pre>
<figcaption> You can even add a caption using the HTML <code>figcaption</code> tag!</figcaption>
</p>

<h3><strong>Headers</strong></h3>
<p>Add a header to your post with this syntax:</p>
<pre>
<code><br>#One '#' for a h1 header<br>##Two '#'s for a h2 header<br>...<br>######Six '#'s for a h6 header</code>
<br># One '#' for a h1 header<br>## Two '#'s for a h2 header<br>...<br>###### Six '#'s for a h6 header
</pre>
<h1>One '#' for a h1 header</h1>
<h2>Two '#'s for a h2 header</h2>
Expand Down Expand Up @@ -74,12 +74,12 @@
<code>{% twitter 834439977220112384 %}</code>

<h3><strong>Glitch embed</strong></h3>
<p>Use the glitch project slug</p>
<p>All you need is the Glitch project slug</p>
<code>{% glitch earthy-course %}</code>

<h3><strong>GitHub Repo Embed</strong></h3>
<p>Use the GitHub username and repo name like this:</p>
<code>{% github thepracticaldev/dev.to_core %}</code>
<p>All you need is the GitHub username and repo:</p>
<code>{% github thepracticaldev/dev.to %}</code>

<h3><strong>GitHub Issue or Comment Embed</strong></h3>
<p>All you need is the GitHub issue or comment URL:</p>
Expand All @@ -100,7 +100,7 @@

<h3><strong>RunKit Embed</strong></h3>
<p>Put executable code within a runkit liquid block, as follows:</p>
<pre><code>{% runkit %}<br>console.log("Place javascript here!"); <br>{% endrunkit %} <br></code></pre>
<pre>{% runkit %}<br>console.log("Place javascript here!"); <br>{% endrunkit %} <br></pre>

<h3><strong>repl.it Embed</strong></h3>
<p>All you need is the URL after the domain name:</p>
Expand All @@ -110,6 +110,18 @@
<p>All you need is the Instagram post <code>id</code> from the URL.</p>
<code>{% instagram BXgGcAUjM39 %}</code>

<h3><strong>Speakerdeck Tag</strong></h3>
<p>All you need is the data-id code from the embed link:</p>
<pre>
<span style="color: gray;"># Given this embed link:</span>
< script async class="speakerdeck-embed"
data-id="<span style="color: orange;">7e9f8c0fa0c949bd8025457181913fd0</span>"
data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js">< /script >
</pre>
<pre>
{% speakerdeck <span style="color: orange;">7e9f8c0fa0c949bd8025457181913fd0</span> %}
</pre>

<h3><strong>Parsing Liquid Tags as a Code Example</strong></h3>
<p>To parse Liquid tags as code, simply wrap it with a single backtick or triple backticks.</p>
<p><code>`{% mytag %}{{ site.SOMETHING }}{% endmytag %}`</code></p>
Expand Down
5 changes: 5 additions & 0 deletions spec/liquid_tags/glitch_tag_spec.rb
Expand Up @@ -3,6 +3,7 @@
RSpec.describe GlitchTag, type: :liquid_template do
describe "#id" do
let(:valid_id) { "BXgGcAUjM39" }
let(:id_with_quotes) { 'some-id" onload="alert(42)"' }

def generate_tag(id)
Liquid::Template.register_tag("glitch", GlitchTag)
Expand All @@ -12,5 +13,9 @@ def generate_tag(id)
it "accepts a valid id" do
expect { generate_tag(valid_id) }.not_to raise_error
end

it "does not accept double quotes" do
expect { generate_tag(id_with_quotes) }.to raise_error(StandardError)
end
end
end
2 changes: 1 addition & 1 deletion spec/liquid_tags/replit_tag_spec.rb
Expand Up @@ -2,7 +2,7 @@

RSpec.describe ReplitTag, type: :liquid_template do
describe "#id" do
let(:replit_id) { "dQw4w9WgXcQ" }
let(:replit_id) { "@WigWog/PositiveFineOpensource" }

def generate_new_liquid(id)
Liquid::Template.register_tag("replit", ReplitTag)
Expand Down
2 changes: 1 addition & 1 deletion spec/liquid_tags/speakerdeck_tag_spec.rb
Expand Up @@ -2,7 +2,7 @@

RSpec.describe SpeakerdeckTag, type: :liquid_template do
describe "#id" do
let(:valid_id) { "BXgGcAUjM39" }
let(:valid_id) { "7e9f8c0fa0c949bd8025457181913fd0" }
let(:invalid_id) { "blahblahblahbl sdsdssd // dsdssd" }

def generate_tag(id)
Expand Down

0 comments on commit 832e892

Please sign in to comment.