fusioncharts_exporter 0.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +20 -0
- data/app/assets/javascripts/fusioncharts_exporter/application.js +13 -0
- data/app/assets/javascripts/fusioncharts_exporter/exporter.js +2 -0
- data/app/assets/stylesheets/fusioncharts_exporter/application.css +15 -0
- data/app/assets/stylesheets/fusioncharts_exporter/exporter.css +4 -0
- data/app/controllers/fusioncharts_exporter/application_controller.rb +4 -0
- data/app/controllers/fusioncharts_exporter/exporter_controller.rb +39 -0
- data/app/helpers/fusioncharts_exporter/application_helper.rb +4 -0
- data/app/helpers/fusioncharts_exporter/exporter_helper.rb +4 -0
- data/app/models/fusioncharts_exporter/export.rb +165 -0
- data/app/views/layouts/fusioncharts_exporter/application.html.erb +14 -0
- data/config/routes.rb +5 -0
- data/lib/fusioncharts_exporter.rb +4 -0
- data/lib/fusioncharts_exporter/engine.rb +9 -0
- data/lib/fusioncharts_exporter/version.rb +3 -0
- data/lib/generators/fusioncharts_exporter/install/USAGE +8 -0
- data/lib/generators/fusioncharts_exporter/install/install_generator.rb +19 -0
- data/lib/generators/fusioncharts_exporter/install/templates/fusioncharts_exporter.erb +3 -0
- data/lib/tasks/fusioncharts_exporter_tasks.rake +4 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a54cb09e7702dec4294fd809aeb92c90827cfb39
|
4
|
+
data.tar.gz: f847a1d576f74b1682c51d965b54f8e80d6dc942
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 211c26f4c983063b09c2a0e8d31f1489489626d63430ab98cdb1ed24accdb89466d7c45e91472476a6447b5b49d35ea57f07fee78f8c75a6a7c33c6829e0e8fb
|
7
|
+
data.tar.gz: df7de0a512355bca33991e7c2933c7009770a63c1854da1cc7fb15c02dd5d2ddee5072bc24ff383b859d6b45d9f33f5c0d086fe31835117dc3614843a4748fe9
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'FusionchartsExporter'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
load 'rails/tasks/engine.rake'
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_dependency "fusioncharts_exporter/application_controller"
|
2
|
+
|
3
|
+
module FusionchartsExporter
|
4
|
+
class ExporterController < ApplicationController
|
5
|
+
|
6
|
+
# The action that controls the export
|
7
|
+
def index
|
8
|
+
@exporter = Export.new
|
9
|
+
@exporter.setRootPath(Rails.root)
|
10
|
+
@exporter.setConfigFile(File.join(Rails.root, "config", "fusioncharts_exporter.yml"))
|
11
|
+
@exporter.setParams(params)
|
12
|
+
@exporter.process_image
|
13
|
+
|
14
|
+
return download if @exporter.downloadable?
|
15
|
+
|
16
|
+
return save if @exporter.saveable?
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Download helper
|
23
|
+
def download
|
24
|
+
File.open(@exporter.get_downloaded_filename, "r") do |f|
|
25
|
+
send_data f.read, :filename => @exporter.get_export_filename, :type => @exporter.get_mime_type
|
26
|
+
|
27
|
+
@exporter.remove_files
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Save helper
|
32
|
+
def save
|
33
|
+
status = @exporter.save
|
34
|
+
|
35
|
+
render :json => { "success" => status }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module FusionchartsExporter
|
2
|
+
class Export
|
3
|
+
|
4
|
+
# Path where all temporary images will be stored.
|
5
|
+
FUSIONCHARTS_TEMP_PATH = "tmp/fusioncharts"
|
6
|
+
|
7
|
+
def setConfigFile(configFile)
|
8
|
+
@configFile = configFile
|
9
|
+
@config = YAML.load_file(@configFile)
|
10
|
+
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def setParams(params)
|
15
|
+
@params = params
|
16
|
+
@options = {}
|
17
|
+
@export_params = @params[:parameters]
|
18
|
+
@export_params.split("|").each do |p|
|
19
|
+
splitted = p.split("=")
|
20
|
+
@options[splitted[0]] = splitted[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return the options instance variable
|
27
|
+
def get_options
|
28
|
+
@options
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return the filename with the absolute path of the current downloaded item
|
32
|
+
def get_downloaded_filename
|
33
|
+
get_download_filename
|
34
|
+
end
|
35
|
+
|
36
|
+
def downloadable?
|
37
|
+
@options['exportaction'] === 'download' ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
def saveable?
|
41
|
+
@options['exportaction'] === 'save' ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
def remove_files
|
45
|
+
@remove_files.each { |f| File.delete(f) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def save
|
49
|
+
begin
|
50
|
+
dest = get_destination
|
51
|
+
FileUtils.mv(get_download_filename, dest)
|
52
|
+
|
53
|
+
stat = true
|
54
|
+
rescue
|
55
|
+
stat = false
|
56
|
+
end
|
57
|
+
|
58
|
+
@remove_files.reject!{ |f| f === get_download_filename }
|
59
|
+
self.remove_files
|
60
|
+
|
61
|
+
if stat
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
|
68
|
+
def process_image
|
69
|
+
|
70
|
+
pre_process_image
|
71
|
+
|
72
|
+
File.open(@options['filepath'], "w") do |f|
|
73
|
+
f.write(@params[:stream])
|
74
|
+
end
|
75
|
+
|
76
|
+
extension = @options['exportformat']
|
77
|
+
|
78
|
+
unless(extension == 'svg')
|
79
|
+
|
80
|
+
# Create a PNG / PDF image
|
81
|
+
temp_extension = extension == 'pdf' ? 'pdf' : 'png'
|
82
|
+
cmd = @config['inkscape_path'] + " --without-gui --export-background=#{@options['meta']['bgColor']} --file=#{@options['filepath']} --export-#{temp_extension}=#{@options['tempfilename']}.#{temp_extension} --export-width=#{@options['meta']['width']} --export-height=#{@options['meta']['height']}"
|
83
|
+
raise "Inkscape was unable to convert svg to png. Is Inkscape configured and installed correctly?" unless system(cmd)
|
84
|
+
@remove_files << @options['tempfilename'] + ".#{temp_extension}"
|
85
|
+
|
86
|
+
# Create JPG image
|
87
|
+
if extension == 'jpg' || extension == 'jpeg'
|
88
|
+
cmd = @config['imagemagick_path'] + " -quality 100 #{@options['tempfilename']}.png #{@options['tempfilename']}.#{extension}"
|
89
|
+
raise "ImageMagick was unable to convert to jpg. Is ImageMagick configured and installed correctly?" unless system(cmd)
|
90
|
+
@remove_files << @options['tempfilename'] + ".jpg"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
# Get the name file that will be called during download
|
97
|
+
def get_export_filename
|
98
|
+
@options['exportfilename'] + "." + @options['exportformat']
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_mime_type(options=nil)
|
102
|
+
options = options || @options
|
103
|
+
mime_types = {
|
104
|
+
'jpg' => 'image/jpeg',
|
105
|
+
'jpeg' => 'image/jpeg',
|
106
|
+
'gif' => 'image/gif',
|
107
|
+
'png' => 'image/png',
|
108
|
+
'pdf' => 'application/pdf',
|
109
|
+
'svg' => 'image/svg+xml'
|
110
|
+
}
|
111
|
+
|
112
|
+
if(mime_types[options['exportformat']])
|
113
|
+
return mime_types[options['exportformat']]
|
114
|
+
else
|
115
|
+
raise "Invalid mime type"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def setRootPath(path)
|
120
|
+
@root_path = path
|
121
|
+
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
# Get the full download filename with the path
|
128
|
+
def get_download_filename
|
129
|
+
@options['tempfilename'] + "." + @options['exportformat']
|
130
|
+
end
|
131
|
+
|
132
|
+
def pre_process_image
|
133
|
+
@random_filename = SecureRandom.urlsafe_base64 + "_" + Time.now.to_i.to_s
|
134
|
+
@random_filename_path = File.join(Rails.root, FUSIONCHARTS_TEMP_PATH, @random_filename)
|
135
|
+
|
136
|
+
@options['tempfilename'] = @random_filename_path
|
137
|
+
@options['filepath'] = @random_filename_path + ".svg"
|
138
|
+
@options['meta'] = get_meta_options
|
139
|
+
@remove_files = [ @options['filepath'] ]
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
# Get all meta request paramaters
|
145
|
+
def get_meta_options
|
146
|
+
|
147
|
+
meta = {}
|
148
|
+
@params.each do |p|
|
149
|
+
match = p[0].match(/^meta_(.*)/)
|
150
|
+
if(match)
|
151
|
+
meta[$1] = p[1]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
return meta
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
# Get the absoulte save path where the file be saved on the server
|
160
|
+
def get_destination
|
161
|
+
File.join(@root_path, @config['save_path'], @random_filename + "." + @options['exportformat'])
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>FusionchartsExporter</title>
|
5
|
+
<%= stylesheet_link_tag "fusioncharts_exporter/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "fusioncharts_exporter/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module FusionchartsExporter
|
2
|
+
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
# Generate configuration file
|
8
|
+
def generate_config
|
9
|
+
template "fusioncharts_exporter.erb", "#{Rails.root}/config/fusioncharts_exporter.yml"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create directory where all images will be stored temporarily
|
13
|
+
def generate_temp_dir
|
14
|
+
empty_directory File.join(Rails.root, "tmp", "fusioncharts")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fusioncharts_exporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FusionCharts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Rails engine to export fusioncharts into image and pdf.
|
70
|
+
email:
|
71
|
+
- mail@labs.fusioncharts.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- app/assets/javascripts/fusioncharts_exporter/application.js
|
77
|
+
- app/assets/javascripts/fusioncharts_exporter/exporter.js
|
78
|
+
- app/assets/stylesheets/fusioncharts_exporter/application.css
|
79
|
+
- app/assets/stylesheets/fusioncharts_exporter/exporter.css
|
80
|
+
- app/controllers/fusioncharts_exporter/application_controller.rb
|
81
|
+
- app/controllers/fusioncharts_exporter/exporter_controller.rb
|
82
|
+
- app/helpers/fusioncharts_exporter/application_helper.rb
|
83
|
+
- app/helpers/fusioncharts_exporter/exporter_helper.rb
|
84
|
+
- app/models/fusioncharts_exporter/export.rb
|
85
|
+
- app/views/layouts/fusioncharts_exporter/application.html.erb
|
86
|
+
- config/routes.rb
|
87
|
+
- lib/fusioncharts_exporter/engine.rb
|
88
|
+
- lib/fusioncharts_exporter/version.rb
|
89
|
+
- lib/fusioncharts_exporter.rb
|
90
|
+
- lib/generators/fusioncharts_exporter/install/install_generator.rb
|
91
|
+
- lib/generators/fusioncharts_exporter/install/templates/fusioncharts_exporter.erb
|
92
|
+
- lib/generators/fusioncharts_exporter/install/USAGE
|
93
|
+
- lib/tasks/fusioncharts_exporter_tasks.rake
|
94
|
+
- MIT-LICENSE
|
95
|
+
- Rakefile
|
96
|
+
homepage: https://github.com/fusioncharts/rails-exporter
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Fusioncharts Export Handler.
|
120
|
+
test_files: []
|