mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
Initial release of Discourse
This commit is contained in:
30
lib/oneboxer/gist_onebox.rb
Normal file
30
lib/oneboxer/gist_onebox.rb
Normal file
@ -0,0 +1,30 @@
|
||||
require_dependency 'oneboxer/handlebars_onebox'
|
||||
|
||||
module Oneboxer
|
||||
class GistOnebox < HandlebarsOnebox
|
||||
|
||||
matcher /^https?:\/\/gist\.github\.com/
|
||||
favicon 'github.png'
|
||||
|
||||
def translate_url
|
||||
m = @url.match(/gist\.github\.com\/(?<id>[0-9a-f]+)/mi)
|
||||
return "https://api.github.com/gists/#{m[:id]}" if m
|
||||
@url
|
||||
end
|
||||
|
||||
def parse(data)
|
||||
|
||||
parsed = JSON.parse(data)
|
||||
|
||||
result = {files: [], title: parsed['description']}
|
||||
|
||||
parsed['files'].each do |filename, attrs|
|
||||
result[:files] << {filename: filename}.merge!(attrs)
|
||||
end
|
||||
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user