httpng 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +59 -0
- data/bin/httpng +60 -0
- data/lib/httpng/app.rb +53 -0
- data/lib/httpng/assets/html2canvas.js +2795 -0
- data/lib/httpng/assets/httpng.js +66 -0
- data/lib/httpng/assets/jquery.plugin.html2canvas.js +87 -0
- data/lib/httpng/version.rb +5 -0
- data/lib/httpng.rb +6 -0
- metadata +77 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
// Preload html2canvas.
|
2
|
+
document.write('<script src="/html2canvas.js"></script>');
|
3
|
+
document.write('<script src="/jquery.plugin.html2canvas.js"></script>');
|
4
|
+
|
5
|
+
// HTTPNG Namespace.
|
6
|
+
Httpng = {
|
7
|
+
// Send all elements marked for export to server.
|
8
|
+
export: function() {
|
9
|
+
var elements = $('[data-export]');
|
10
|
+
|
11
|
+
// Create a function to show success after all elements returned.
|
12
|
+
var totalCount = elements.length;
|
13
|
+
var completedCount = 0;
|
14
|
+
var errors = [];
|
15
|
+
var showComplete = function() {
|
16
|
+
if(completedCount >= totalCount) {
|
17
|
+
// Show errors if present.
|
18
|
+
if(errors.length > 0) {
|
19
|
+
alert(errors.join("\n"));
|
20
|
+
}
|
21
|
+
// Otherwise show success.
|
22
|
+
else {
|
23
|
+
alert('OK: ' + completedCount + ' element' + (completedCount == 1 ? '' : 's' ) + ' saved.')
|
24
|
+
}
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
28
|
+
// Loop over elements and save.
|
29
|
+
$.each(elements, function(index, element) {
|
30
|
+
var name = $(element).data('export');
|
31
|
+
|
32
|
+
$(element).html2canvas({
|
33
|
+
onrendered: function(canvas) {
|
34
|
+
var data = canvas.toDataURL('image/png').replace(/^data:image\/png;base64,/, '');
|
35
|
+
|
36
|
+
$.post(
|
37
|
+
'/export',
|
38
|
+
{name:name, data:data}
|
39
|
+
)
|
40
|
+
.complete(function() {
|
41
|
+
completedCount++;
|
42
|
+
showComplete()
|
43
|
+
})
|
44
|
+
.error(function() {
|
45
|
+
completedCount++;
|
46
|
+
errors.push('Unable to save: ' + name);
|
47
|
+
showComplete();
|
48
|
+
});
|
49
|
+
}
|
50
|
+
})
|
51
|
+
});
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
// Setup HTTPNG UI.
|
56
|
+
$(document).ready(function() {
|
57
|
+
// Add top bar.
|
58
|
+
$(document).find('body')
|
59
|
+
.prepend('<div id="httpng-bar" style="background-color:#000000; margin-bottom:20px; text-align:right;"><button id="httpng-export">Export</button></div>');
|
60
|
+
|
61
|
+
// Add listener to export button.
|
62
|
+
$(document).find('#httpng-export').click(function(event) {
|
63
|
+
Httpng.export();
|
64
|
+
});
|
65
|
+
});
|
66
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
/**
|
2
|
+
@license html2canvas v0.33 <http://html2canvas.hertzen.com>
|
3
|
+
Copyright (c) 2011 Niklas von Hertzen. All rights reserved.
|
4
|
+
http://www.twitter.com/niklasvh
|
5
|
+
|
6
|
+
Released under MIT License
|
7
|
+
*/
|
8
|
+
/*
|
9
|
+
* jQuery helper plugin for examples and tests
|
10
|
+
*/
|
11
|
+
(function( $ ){
|
12
|
+
$.fn.html2canvas = function(options) {
|
13
|
+
if (options && options.profile && window.console && window.console.profile) {
|
14
|
+
console.profile();
|
15
|
+
}
|
16
|
+
var date = new Date(),
|
17
|
+
html2obj,
|
18
|
+
$message = null,
|
19
|
+
timeoutTimer = false,
|
20
|
+
timer = date.getTime();
|
21
|
+
options = options || {};
|
22
|
+
|
23
|
+
options.onrendered = options.onrendered || function( canvas ) {
|
24
|
+
var $canvas = $(canvas),
|
25
|
+
finishTime = new Date();
|
26
|
+
|
27
|
+
if (options && options.profile && window.console && window.console.profileEnd) {
|
28
|
+
console.profileEnd();
|
29
|
+
}
|
30
|
+
$canvas.css({
|
31
|
+
position: 'absolute',
|
32
|
+
left: 0,
|
33
|
+
top: 0
|
34
|
+
}).appendTo(document.body);
|
35
|
+
$canvas.siblings().toggle();
|
36
|
+
|
37
|
+
$(window).click(function(){
|
38
|
+
$canvas.toggle().siblings().toggle();
|
39
|
+
throwMessage("Canvas Render " + ($canvas.is(':visible') ? "visible" : "hidden"));
|
40
|
+
});
|
41
|
+
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)) + " ms<br />",4000);
|
42
|
+
|
43
|
+
// test if canvas is read-able
|
44
|
+
try {
|
45
|
+
$canvas[0].toDataURL();
|
46
|
+
} catch(e) {
|
47
|
+
if ($canvas[0].nodeName.toLowerCase() === "canvas") {
|
48
|
+
// TODO, maybe add a bit less offensive way to present this, but still something that can easily be noticed
|
49
|
+
alert("Canvas is tainted, unable to read data");
|
50
|
+
}
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
html2obj = html2canvas(this, options);
|
55
|
+
|
56
|
+
function throwMessage(msg,duration){
|
57
|
+
window.clearTimeout(timeoutTimer);
|
58
|
+
timeoutTimer = window.setTimeout(function(){
|
59
|
+
$message.fadeOut(function(){
|
60
|
+
$message.remove();
|
61
|
+
$message = null;
|
62
|
+
});
|
63
|
+
},duration || 2000);
|
64
|
+
if ($message)
|
65
|
+
$message.remove();
|
66
|
+
$message = $('<div />').html(msg).css({
|
67
|
+
margin:0,
|
68
|
+
padding:10,
|
69
|
+
background: "#000",
|
70
|
+
opacity:0.7,
|
71
|
+
position:"fixed",
|
72
|
+
top:10,
|
73
|
+
right:10,
|
74
|
+
fontFamily: 'Tahoma',
|
75
|
+
color:'#fff',
|
76
|
+
fontSize:12,
|
77
|
+
borderRadius:12,
|
78
|
+
width:'auto',
|
79
|
+
height:'auto',
|
80
|
+
textAlign:'center',
|
81
|
+
textDecoration:'none',
|
82
|
+
display:'none'
|
83
|
+
}).appendTo(document.body).fadeIn();
|
84
|
+
html2obj.log(msg);
|
85
|
+
}
|
86
|
+
};
|
87
|
+
})( jQuery );
|
data/lib/httpng.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: httpng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Johnson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: OptionParser
|
16
|
+
requirement: &70245073090280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70245073090280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sinatra
|
27
|
+
requirement: &70245073089740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70245073089740
|
36
|
+
description:
|
37
|
+
email:
|
38
|
+
- benbjohnson@yahoo.com
|
39
|
+
executables:
|
40
|
+
- httpng
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- lib/httpng/app.rb
|
45
|
+
- lib/httpng/assets/html2canvas.js
|
46
|
+
- lib/httpng/assets/httpng.js
|
47
|
+
- lib/httpng/assets/jquery.plugin.html2canvas.js
|
48
|
+
- lib/httpng/version.rb
|
49
|
+
- lib/httpng.rb
|
50
|
+
- README.md
|
51
|
+
- bin/httpng
|
52
|
+
homepage: http://github.com/benbjohnson/httpng
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.10
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: A local server for saving HTML elements as PNG files.
|
76
|
+
test_files: []
|
77
|
+
has_rdoc:
|