mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-08-13 17:03:45 -04:00
Expose updated fractal api access in front-end
This commit is contained in:
parent
88711084e7
commit
60160e1642
@ -124,6 +124,7 @@ module MailCatcher
|
||||
get "/messages/:id/analysis.?:format?" do
|
||||
id = params[:id].to_i
|
||||
if part = MailCatcher::Mail.message_part_html(id)
|
||||
# TODO: Server-side cache? Make the browser cache based on message create time? Hmm.
|
||||
uri = URI.parse("http://api.getfractal.com/api/v2/validate#{"/format/#{params[:format]}" if params[:format].present?}")
|
||||
response = Net::HTTP.post_form(uri, api_key: "5c463877265251386f516f7428", html: part["body"])
|
||||
content_type ".#{params[:format]}" if params[:format].present?
|
||||
|
@ -136,12 +136,9 @@ class MailCatcher
|
||||
$("#message .views :not(.analysis).tab.selected").removeClass 'selected'
|
||||
|
||||
if id?
|
||||
# Makes a new iframe which will have a foreign origin eventually, and populate it with a quick intro and a form to send to Fractal.
|
||||
$iframe = $('#message iframe').contents().children().html("""
|
||||
<html class="mailcatcher"><head>#{$('link[rel="stylesheet"]')[0].outerHTML}</head><body><iframe></iframe></body></html>
|
||||
""")
|
||||
.find("head").append($('link[rel="stylesheet"]').clone()).end()
|
||||
.find('iframe').contents().children().html("""
|
||||
# Makes a new iframe and populate it with a quick intro and a button
|
||||
$iframe = $('#message iframe').contents().children()
|
||||
.html("""
|
||||
<html>
|
||||
<head>
|
||||
<title>Analysis</title>
|
||||
@ -151,34 +148,25 @@ class MailCatcher
|
||||
<h1>Analyse your email with Fractal</h1>
|
||||
<p><a href="http://getfractal.com/" target="_blank">Fractal</a> is a really neat service that applies common email design and development knowledge from <a href="http://www.email-standards.org/" target="_blank">Email Standards Project</a> to your HTML email and tells you what you've done wrong or what you should do instead.</p>
|
||||
<p>Please note that this <strong>sends your email to the Fractal service</strong> for analysis. Read their <a href="http://getfractal.com/terms" target="_blank">terms of service</a> if you're paranoid.</p>
|
||||
<form action="http://getfractal.com/validate" method="POST">
|
||||
<input type="hidden" name="html" />
|
||||
<input type="submit" value="Analyse" disabled="disabled" /><span class="loading" style="color: #999">Loading your email...</span>
|
||||
<p>(This output is still just raw XML. Someone keen to transform this into something prettier would be greatly appreciated!)</p>
|
||||
<form>
|
||||
<input type="submit" value="Analyse" /><span class="loading" style="color: #999; display: none">Analysing…</span>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
""")
|
||||
# This should be cached if already accessed, so it's actually quite quick
|
||||
$.get "/messages/#{id}.html", (html) ->
|
||||
$iframe
|
||||
.find('input[name="html"]').attr('value', html).end()
|
||||
.find('.loading').hide().end()
|
||||
.find('input[type="submit"]').attr('disabled', null).end()
|
||||
.find('form').submit ->
|
||||
$(this)
|
||||
.find('input[type="submit"]').attr('disabled', 'disabled').end()
|
||||
.find('.loading').text('Analysing...').show()
|
||||
|
||||
# FIXME: Fractal need to allow GET requests to their JSONP endpoint, then we can use the API:
|
||||
# $.ajax
|
||||
# url: 'http://getfractal.com/api/v1/validate/format/jsonp'
|
||||
# data:
|
||||
# api_key: '59372c4f65426f78282c5c657d'
|
||||
# html: html
|
||||
# dataType: 'jsonp'
|
||||
# success: (json) ->
|
||||
# console.log json
|
||||
# $iframe.children().html json
|
||||
$form = $iframe.find('form')
|
||||
.submit (e) ->
|
||||
e.preventDefault()
|
||||
$(this)
|
||||
.find('input[type="submit"]').attr('disabled', 'disabled').end()
|
||||
.find('.loading').show()
|
||||
$.ajax
|
||||
url: "/messages/#{id}/analysis.xml",
|
||||
dataType: "text"
|
||||
success: (data) ->
|
||||
$form.replaceWith('<h2>Results</h2><pre id="result"></pre>')
|
||||
$iframe.find("#result").text data
|
||||
|
||||
refresh: ->
|
||||
$.getJSON '/messages', (messages) =>
|
||||
|
@ -148,15 +148,22 @@
|
||||
}
|
||||
};
|
||||
MailCatcher.prototype.loadMessageAnalysis = function(id) {
|
||||
var $iframe;
|
||||
var $form, $iframe;
|
||||
id || (id = this.selectedMessage());
|
||||
$("#message .views .analysis.tab:not(.selected)").addClass('selected');
|
||||
$("#message .views :not(.analysis).tab.selected").removeClass('selected');
|
||||
if (id != null) {
|
||||
$iframe = $('#message iframe').contents().children().html("<html class=\"mailcatcher\"><head>" + ($('link[rel="stylesheet"]')[0].outerHTML) + "</head><body><iframe></iframe></body></html>").find("head").append($('link[rel="stylesheet"]').clone()).end().find('iframe').contents().children().html("<html>\n<head>\n<title>Analysis</title>\n" + ($('link[rel="stylesheet"]')[0].outerHTML) + "\n</head>\n<body class=\"iframe\">\n<h1>Analyse your email with Fractal</h1>\n<p><a href=\"http://getfractal.com/\" target=\"_blank\">Fractal</a> is a really neat service that applies common email design and development knowledge from <a href=\"http://www.email-standards.org/\" target=\"_blank\">Email Standards Project</a> to your HTML email and tells you what you've done wrong or what you should do instead.</p>\n<p>Please note that this <strong>sends your email to the Fractal service</strong> for analysis. Read their <a href=\"http://getfractal.com/terms\" target=\"_blank\">terms of service</a> if you're paranoid.</p>\n<form action=\"http://getfractal.com/validate\" method=\"POST\">\n<input type=\"hidden\" name=\"html\" />\n<input type=\"submit\" value=\"Analyse\" disabled=\"disabled\" /><span class=\"loading\" style=\"color: #999\">Loading your email...</span>\n</form>\n</body>\n</html>");
|
||||
return $.get("/messages/" + id + ".html", function(html) {
|
||||
return $iframe.find('input[name="html"]').attr('value', html).end().find('.loading').hide().end().find('input[type="submit"]').attr('disabled', null).end().find('form').submit(function() {
|
||||
return $(this).find('input[type="submit"]').attr('disabled', 'disabled').end().find('.loading').text('Analysing...').show();
|
||||
$iframe = $('#message iframe').contents().children().html("<html>\n<head>\n<title>Analysis</title>\n" + ($('link[rel="stylesheet"]')[0].outerHTML) + "\n</head>\n<body class=\"iframe\">\n<h1>Analyse your email with Fractal</h1>\n<p><a href=\"http://getfractal.com/\" target=\"_blank\">Fractal</a> is a really neat service that applies common email design and development knowledge from <a href=\"http://www.email-standards.org/\" target=\"_blank\">Email Standards Project</a> to your HTML email and tells you what you've done wrong or what you should do instead.</p>\n<p>Please note that this <strong>sends your email to the Fractal service</strong> for analysis. Read their <a href=\"http://getfractal.com/terms\" target=\"_blank\">terms of service</a> if you're paranoid.</p>\n<p>(This output is still just raw XML. Someone keen to transform this into something prettier would be greatly appreciated!)</p>\n<form>\n<input type=\"submit\" value=\"Analyse\" /><span class=\"loading\" style=\"color: #999; display: none\">Analysing…</span>\n</form>\n</body>\n</html>");
|
||||
return $form = $iframe.find('form').submit(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).find('input[type="submit"]').attr('disabled', 'disabled').end().find('.loading').show();
|
||||
return $.ajax({
|
||||
url: "/messages/" + id + "/analysis.xml",
|
||||
dataType: "text",
|
||||
success: function(data) {
|
||||
$form.replaceWith('<h2>Results</h2><pre id="result"></pre>');
|
||||
return $iframe.find("#result").text(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user