togostanza 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c89132e4c11121e7e06b99cdafbaff9afa086b0
4
- data.tar.gz: 0e8c151c4ee36a69fca7c805081c688281382cad
3
+ metadata.gz: 1891e5632d347b87a3b6469d5643a142177ca67a
4
+ data.tar.gz: e49f2c18341beb8fc83ceaea79416bf1ed56c299
5
5
  SHA512:
6
- metadata.gz: a9421058afe1ba8dca550255ccd4d3db8e7b7a4fa1570de0831275582b2da4eba80b9f40e779ab16a5439aefb720e4887a5c8fe40c1e90e644e982837b4897d9
7
- data.tar.gz: 5624ff06623b6f5d3ed83e611100fb5f37b00379850afb1b832d6be171775a93d2d23eaf6324afd8fd6fc63a838a6f0b6c94ab8e96fc65f7a2b3472fb72ba93f
6
+ metadata.gz: e68e08994eabf92b9a3ffd3afda17ad31fb4de1773dcfe8ca8150a410afb2d94fe4166884ae71511c085342286a34e018bd7e079e784ff2ab095f4e617b531d8
7
+ data.tar.gz: 386d18c4921aba105ff4b22d714a836827437f36ee161fc4fbc2c57b512eb4aa3c041b81f09762bd27c2a7b46bd21095c072c0d6df13df2d360b38b341154711
@@ -0,0 +1,124 @@
1
+ /* canvas-toBlob.js
2
+ * A canvas.toBlob() implementation.
3
+ * 2013-12-27
4
+ *
5
+ * By Eli Grey, http://eligrey.com and Devin Samarin, https://github.com/eboyjr
6
+ * License: X11/MIT
7
+ * See https://github.com/eligrey/canvas-toBlob.js/blob/master/LICENSE.md
8
+ */
9
+
10
+ /*global self */
11
+ /*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
12
+ plusplus: true */
13
+
14
+ /*! @source http://purl.eligrey.com/github/canvas-toBlob.js/blob/master/canvas-toBlob.js */
15
+
16
+ (function(view) {
17
+ "use strict";
18
+ var
19
+ Uint8Array = view.Uint8Array
20
+ , HTMLCanvasElement = view.HTMLCanvasElement
21
+ , canvas_proto = HTMLCanvasElement && HTMLCanvasElement.prototype
22
+ , is_base64_regex = /\s*;\s*base64\s*(?:;|$)/i
23
+ , to_data_url = "toDataURL"
24
+ , base64_ranks
25
+ , decode_base64 = function(base64) {
26
+ var
27
+ len = base64.length
28
+ , buffer = new Uint8Array(len / 4 * 3 | 0)
29
+ , i = 0
30
+ , outptr = 0
31
+ , last = [0, 0]
32
+ , state = 0
33
+ , save = 0
34
+ , rank
35
+ , code
36
+ , undef
37
+ ;
38
+ while (len--) {
39
+ code = base64.charCodeAt(i++);
40
+ rank = base64_ranks[code-43];
41
+ if (rank !== 255 && rank !== undef) {
42
+ last[1] = last[0];
43
+ last[0] = code;
44
+ save = (save << 6) | rank;
45
+ state++;
46
+ if (state === 4) {
47
+ buffer[outptr++] = save >>> 16;
48
+ if (last[1] !== 61 /* padding character */) {
49
+ buffer[outptr++] = save >>> 8;
50
+ }
51
+ if (last[0] !== 61 /* padding character */) {
52
+ buffer[outptr++] = save;
53
+ }
54
+ state = 0;
55
+ }
56
+ }
57
+ }
58
+ // 2/3 chance there's going to be some null bytes at the end, but that
59
+ // doesn't really matter with most image formats.
60
+ // If it somehow matters for you, truncate the buffer up outptr.
61
+ return buffer;
62
+ }
63
+ ;
64
+ if (Uint8Array) {
65
+ base64_ranks = new Uint8Array([
66
+ 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1
67
+ , -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
68
+ , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
69
+ , -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
70
+ , 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
71
+ ]);
72
+ }
73
+ if (HTMLCanvasElement && !canvas_proto.toBlob) {
74
+ canvas_proto.toBlob = function(callback, type /*, ...args*/) {
75
+ if (!type) {
76
+ type = "image/png";
77
+ } if (this.mozGetAsFile) {
78
+ callback(this.mozGetAsFile("canvas", type));
79
+ return;
80
+ } if (this.msToBlob && /^\s*image\/png\s*(?:$|;)/i.test(type)) {
81
+ callback(this.msToBlob());
82
+ return;
83
+ }
84
+
85
+ var
86
+ args = Array.prototype.slice.call(arguments, 1)
87
+ , dataURI = this[to_data_url].apply(this, args)
88
+ , header_end = dataURI.indexOf(",")
89
+ , data = dataURI.substring(header_end + 1)
90
+ , is_base64 = is_base64_regex.test(dataURI.substring(0, header_end))
91
+ , blob
92
+ ;
93
+ if (Blob.fake) {
94
+ // no reason to decode a data: URI that's just going to become a data URI again
95
+ blob = new Blob
96
+ if (is_base64) {
97
+ blob.encoding = "base64";
98
+ } else {
99
+ blob.encoding = "URI";
100
+ }
101
+ blob.data = data;
102
+ blob.size = data.length;
103
+ } else if (Uint8Array) {
104
+ if (is_base64) {
105
+ blob = new Blob([decode_base64(data)], {type: type});
106
+ } else {
107
+ blob = new Blob([decodeURIComponent(data)], {type: type});
108
+ }
109
+ }
110
+ callback(blob);
111
+ };
112
+
113
+ if (canvas_proto.toDataURLHD) {
114
+ canvas_proto.toBlobHD = function() {
115
+ to_data_url = "toDataURLHD";
116
+ var blob = this.toBlob();
117
+ to_data_url = "toDataURL";
118
+ return blob;
119
+ }
120
+ } else {
121
+ canvas_proto.toBlobHD = canvas_proto.toBlob;
122
+ }
123
+ }
124
+ }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
data/assets/stanza.css CHANGED
@@ -125,3 +125,46 @@ pre {
125
125
  .span10 { width: 83.3333%; }
126
126
  .span11 { width: 91.6666%; }
127
127
  .span12 { width: 100%; }
128
+
129
+ body > div#stanza_buttons {
130
+ margin: 0 0;
131
+ padding: 0 0;
132
+ }
133
+
134
+ /* tool bar */
135
+ /* line 134, ../sass/stanza.scss */
136
+ #tool_bar {
137
+ margin-top: 0;
138
+ border-top-left-radius: 0;
139
+ border-top-right-radius: 0;
140
+ font-size: 12px;
141
+ line-height: 30px;
142
+ color: #999;
143
+ background-color: #fff;
144
+ padding-top: 2px;
145
+ border-top: dashed 1px #ccc;
146
+ /*@include box-shadow(0 1px 2px rgba(0, 0, 0, 0.2), inset 0 10px 8px -8px rgba(0, 0, 0, 0.12));*/
147
+ }
148
+ /* line 145, ../sass/stanza.scss */
149
+ #tool_bar a {
150
+ color: #45b8cc;
151
+ margin-right: 1.5em;
152
+ }
153
+ /* line 148, ../sass/stanza.scss */
154
+ #tool_bar a:hover {
155
+ color: #005580;
156
+ }
157
+ /* line 152, ../sass/stanza.scss */
158
+ #tool_bar p {
159
+ margin-bottom: 0;
160
+ }
161
+ /* line 155, ../sass/stanza.scss */
162
+ #tool_bar:before, #tool_bar:after {
163
+ display: table;
164
+ line-height: 0;
165
+ content: "";
166
+ }
167
+ /* line 160, ../sass/stanza.scss */
168
+ #tool_bar:after {
169
+ clear: both;
170
+ }
@@ -5,12 +5,154 @@ require 'hashie/mash'
5
5
  FS.register_helper :adjust_iframe_height_script do
6
6
  <<-HTML.strip_heredoc.html_safe
7
7
  <script>$(function() {
8
- height = this.body.offsetHeight + 30;
8
+ height = this.body.offsetHeight + 43;
9
9
  parent.postMessage(JSON.stringify({height: height, id: name}), "*");
10
10
  });</script>
11
11
  HTML
12
12
  end
13
13
 
14
+ FS.register_helper :download_csv do
15
+ <<-HTML.strip_heredoc.html_safe
16
+ <script>$(function() {
17
+ #{init_download_script}
18
+ $("div#stanza_buttons").append("<a id='download_csv' href='#'><i class='fa fa-file'></i> CSV</a>");
19
+
20
+ var csv = '';
21
+ var tables = $('body > table');
22
+ if (tables.length > 0) {
23
+ for (var tableNum = 0; tableNum < tables.length; tableNum++) {
24
+ var table = tables[tableNum];
25
+ var rowLength = table.rows.length;
26
+ var colLength = table.rows[0].cells.length;
27
+ for (var i = 0; i < rowLength; i++) {
28
+ for (var j = 0; j < colLength; j++) {
29
+ var cell = table.rows[i].cells[j];
30
+ var textContent = null;
31
+
32
+ if ($(cell).find("li")[0]) {
33
+ textContent = $(cell).find('li').map(function(){
34
+ return this.textContent.replace(/^\\s+/mg, "").replace(/\\n/g, "");
35
+ }).get().join(" | ");
36
+ } else if ($(cell).find("table")[0]) {
37
+ textContent = $(cell).find('table').find('th, td').map(function(){
38
+ return this.textContent.replace(/^\\s+/mg, "").replace(/\\n/g, "");
39
+ }).get().join(" | ");
40
+ } else {
41
+ textContent = cell.textContent.replace(/^\\s+/mg, "").replace(/\\n/g, "");
42
+ }
43
+ if (j === colLength - 1) {
44
+ csv += textContent;
45
+ } else {
46
+ csv += textContent + ', ';
47
+ }
48
+ }
49
+ csv += "\\r\\n";
50
+ }
51
+ }
52
+ }
53
+
54
+ $("#download_csv").on("click",function(){
55
+ window.open('data:text/plain;' + (window.btoa?'base64,'+btoa(csv):csv));
56
+ });
57
+
58
+ });
59
+ </script>
60
+ HTML
61
+ end
62
+
63
+ FS.register_helper :download_json do
64
+ json = except(:css_uri).to_json
65
+
66
+ <<-HTML.strip_heredoc.html_safe
67
+ <script>$(function() {
68
+ #{init_download_script}
69
+ $("div#stanza_buttons").append("<a id='download_json' href='#'><i class='fa fa-file'></i> JSON</a>");
70
+ var json_str = JSON.stringify(#{json}, "", "\t");
71
+
72
+ $("#download_json").on("click",function(){
73
+ window.open('data:application/json;' + (window.btoa?'base64,'+btoa(json_str):json_str));
74
+ });
75
+ });
76
+ </script>
77
+ HTML
78
+ end
79
+
80
+ FS.register_helper :download_svg do
81
+ <<-HTML.strip_heredoc.html_safe
82
+ <script>$(function() {
83
+ #{init_download_script}
84
+ $("div#stanza_buttons").append("<a id='download_svg' href='#'><i class='fa fa-file'></i> SVG</a>");
85
+
86
+ $("#download_svg").on("click",function(){
87
+ var svg = $("svg");
88
+ if (svg[0]) {
89
+ if (!svg.attr("xmlns")) {
90
+ svg.attr("xmlns","http://www.w3.org/2000/svg");
91
+ }
92
+ if (!svg.attr("xmlns:xlink")) {
93
+ svg.attr("xmlns:xlink","http://www.w3.org/1999/xlink");
94
+ }
95
+
96
+ var svgText = svg.wrap('<div>').parent().html();
97
+ window.open('data:image/svg+xml;' + (window.btoa?'base64,'+btoa(svgText):svgText));
98
+ } else {
99
+ // TODO...
100
+ console.log("Can't open svg file");
101
+ }
102
+ });
103
+
104
+ });
105
+ </script>
106
+ HTML
107
+ end
108
+
109
+ FS.register_helper :download_image do
110
+ <<-HTML.strip_heredoc.html_safe
111
+ <script type="application/javascript" src="/stanza/assets/canvas-toBlob.js"></script>
112
+
113
+ <script type="application/javascript" src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script>
114
+ <script type="application/javascript" src="http://canvg.googlecode.com/svn/trunk/StackBlur.js"></script>
115
+ <script type="application/javascript" src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script>
116
+
117
+ <script>$(function() {
118
+ #{init_download_script}
119
+ $("div#stanza_buttons").append("<a id='download_image' href='#'><i class='fa fa-file'></i> IMAGE</a>");
120
+
121
+ $("body").append("<div style='display: none;'><canvas id='drawarea'></canvas></div>");
122
+
123
+ $("#download_image").on("click",function(){
124
+ var svg = $("svg");
125
+ if (svg[0]) {
126
+ var svgText = svg.wrap('<div>').parent().html();
127
+ canvg('drawarea', svgText, {renderCallback: function(){
128
+ var canvas = $("#drawarea")[0];
129
+
130
+ canvas.toBlob(function(blob) {
131
+ var blob_url = window.URL.createObjectURL(blob);
132
+ window.open(blob_url);
133
+ }, "image/png");
134
+ }
135
+ });
136
+
137
+ } else {
138
+ // TODO...
139
+ console.log("Can't open image file");
140
+ }
141
+ });
142
+
143
+ });
144
+ </script>
145
+ HTML
146
+ end
147
+
148
+ def init_download_script
149
+ <<-HTML.strip_heredoc.html_safe
150
+ if (!$("div#stanza_buttons")[0]) {
151
+ $('body').append("<div id='tool_bar'><div id='stanza_buttons' class='pull-left'></div></div>");
152
+ }
153
+ HTML
154
+ end
155
+
14
156
  module TogoStanza::Stanza
15
157
  autoload :ExpressionMap, 'togostanza/stanza/expression_map'
16
158
  autoload :Grouping, 'togostanza/stanza/grouping'
@@ -40,6 +182,7 @@ module TogoStanza::Stanza
40
182
  else
41
183
  %w(
42
184
  //cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css
185
+ //cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css
43
186
  /stanza/assets/stanza.css
44
187
  )
45
188
  end
@@ -1,3 +1,3 @@
1
1
  module TogoStanza
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/views/layout.haml CHANGED
@@ -5,6 +5,7 @@
5
5
  %meta(charset='utf-8')
6
6
  %title= @page_title || 'Stanza'
7
7
  %link(rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css')
8
+ %link(rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css')
8
9
  %link(rel='stylesheet' href='/stanza/assets/stanza.css')
9
10
  %script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js')
10
11
  %script(src='/stanza/assets/stanza.js')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: togostanza
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -264,6 +264,7 @@ files:
264
264
  - LICENSE.txt
265
265
  - README.md
266
266
  - Rakefile
267
+ - assets/canvas-toBlob.js
267
268
  - assets/csssprite.png
268
269
  - assets/nanostanza.css
269
270
  - assets/nanostanza.js
@@ -363,3 +364,4 @@ test_files:
363
364
  - spec/lib/togostanza/stanza/base_spec.rb
364
365
  - spec/lib/togostanza/stanza/grouping_spec.rb
365
366
  - spec/spec_helper.rb
367
+ has_rdoc: