Fix Github Readme tag and add Glitch tag (#357)

This commit is contained in:
Ben Halpern 2018-05-29 14:09:47 -04:00 committed by GitHub
parent 7dd8f791fc
commit a6cc5e4669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 1 deletions

View file

@ -198,6 +198,7 @@ class MarkdownParser
Liquid::Template.register_tag("gist", GistTag)
Liquid::Template.register_tag("instagram", InstagramTag)
Liquid::Template.register_tag("speakerdeck", SpeakerdeckTag)
Liquid::Template.register_tag("glitch", GlitchTag)
Liquid::Template.register_tag("replit", ReplitTag)
Liquid::Template.register_tag("runkit", RunkitTag)
Liquid::Template.register_tag("youtube", YoutubeTag)

View file

@ -31,7 +31,7 @@ class GithubTag
raise_error if repo_details.length > 2
user_name = repo_details[0]
repo_name = repo_details[1]
client = Octokit::Client.new(access_token: Identity.where(provider: "github").last(250).sample)
client = Octokit::Client.new(access_token: Identity.where(provider: "github").last(250).sample.token)
@readme_html = client.readme user_name + "/" + repo_name, :accept =>
"application/vnd.github.html"
@readme = client.readme user_name + "/" + repo_name

View file

@ -0,0 +1,24 @@
class GlitchTag < LiquidTagBase
def initialize(tag_name, id, tokens)
super
@id = parse_id(id)
end
def render(context)
html = <<-HTML
<div class="glitch-embed-wrap" style="height: 450px; width: 100%;margin: 1em auto 1.3em">
<iframe
src="https://glitch.com/embed/#!/embed/#{@id}?path=index.html"
alt="#{@id} on glitch"
style="height: 100%; width: 100%; border: 0;margin:0;padding:0"></iframe>
</div>
HTML
finalize_html(html)
end
private
def parse_id(input)
input_no_space = input.delete(" ")
end
end

View file

@ -14,6 +14,7 @@ Liquid::Template.register_tag("codepen", CodepenTag)
Liquid::Template.register_tag("gist", GistTag)
Liquid::Template.register_tag("instagram", InstagramTag)
Liquid::Template.register_tag("speakerdeck", SpeakerdeckTag)
Liquid::Template.register_tag("glitch", GlitchTag)
Liquid::Template.register_tag("replit", ReplitTag)
Liquid::Template.register_tag("runkit", RunkitTag)
Liquid::Template.register_tag("youtube", YoutubeTag)

View file

@ -0,0 +1,16 @@
require "rails_helper"
RSpec.describe GlitchTag, type: :liquid_template do
describe "#id" do
let(:valid_id) { "BXgGcAUjM39" }
def generate_tag(id)
Liquid::Template.register_tag("glitch", GlitchTag)
Liquid::Template.parse("{% glitch #{id} %}")
end
it "accepts a valid id" do
expect { generate_tag(valid_id) }.not_to raise_error
end
end
end