tramway-export 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2db1abd681f33aec113b89d0d4e79e2329258884e3f7cb2258c8640f2f3a23e9
4
+ data.tar.gz: c58acc9906fa3d6535fdb89d75b7cd10ada709e6994979d492eb3f6334859022
5
+ SHA512:
6
+ metadata.gz: 68b188497c5fcb65fe07ba35f0a161843951dc7d44d27abc8395c1f85e59a80cf5e1c576e78193e9040c34410df970a17d4a8ef1ecd3fa0850c6dffaaf40de59
7
+ data.tar.gz: b377e4d1a07c3898ed589aa7a91b59b527ae4c738411bc7aaa7b3b760b51e2cf46b46dbeed85ee3c9327a91078ce754f43687cef09b3ee75a2de4c366cf896da
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Pavel Kalashnikov
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/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Tramway::Export
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'tramway-export'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install tramway-export
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
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 = 'Tramway::Export'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/tramway/export .js
2
+ //= link_directory ../stylesheets/tramway/export .css
@@ -0,0 +1,2 @@
1
+ //= require rails-ujs
2
+ //= 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 any plugin's vendor/assets/stylesheets directory 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 other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,9 @@
1
+ module Tramway
2
+ module Export
3
+ class ApplicationController < Tramway::Core::ApplicationController
4
+ protect_from_forgery with: :exception
5
+
6
+ include Tramway::ClassNameHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'xls_exporter'
2
+
3
+ class Tramway::Export::ExportsController < Tramway::Export::ApplicationController
4
+ def show
5
+ scope = params[:scope].present? ? params[:scope] : :all
6
+ model_class = model_class_name(params[:model])
7
+ xlsx_decorator_class = xlsx_decorator_class_name(params[:model])
8
+ records = xlsx_decorator_class.decorate model_class.active.order(id: :desc).send scope
9
+
10
+ book = ::XlsExporter.export do
11
+ add_sheet 'List'
12
+
13
+ export_models records, *xlsx_decorator_class.columns
14
+ end
15
+ stream = StringIO.new
16
+ book.write stream
17
+ send_data stream.string, content_type: 'application/xlsx', filename: xlsx_decorator_class.filename
18
+ end
19
+
20
+ private
21
+
22
+ def xlsx_decorator_class_name(model_name)
23
+ "#{model_name}XlsxDecorator".constantize
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ class Tramway::Export::ApplicationDecorator
2
+ def initialize(object)
3
+ @object = object
4
+ end
5
+
6
+ class << self
7
+ def columns
8
+ []
9
+ end
10
+
11
+ def filename
12
+ 'export.xlsx'
13
+ end
14
+
15
+ def decorate(array)
16
+ array.map do |obj|
17
+ new obj
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def object
25
+ @object
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ module Tramway
2
+ module Export
3
+ module Xlsx
4
+ class ApplicationDecorator < Tramway::Export::ApplicationDecorator
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Tramway
2
+ module Export
3
+ module ApplicationHelper
4
+ include AuthManagement
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Tramway
2
+ module Export
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Tramway
2
+ module Export
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Tramway
2
+ module Export
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ - if Tramway::Export.exportable_model? model_class, project: @application_engine
2
+ - model_name = model_class.name.underscore
3
+ - id = "export-#{model_name}"
4
+ .btn-group{ role: :group }
5
+ %button{ id: id, type: :button, class: 'btn btn-primary dropdown-toggle', data: { toggle: :dropdown, aria: { haspopup: :true, expanded: :false } } }
6
+ = fa_icon(:download)
7
+ .dropdown-menu{ aria: { labelledby: id } }
8
+ - decorator_class.collections.each do |collection|
9
+ = link_to collection_human_name(model_name: model_name, collection_name: collection), Tramway::Export::Engine.routes.url_helpers.exports_path(model: model_class, scope: collection), class: 'dropdown-item'
10
+
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Tramway::Export::Engine.routes.draw do
2
+ resources :exports, only: [] do
3
+ collection do
4
+ get :show
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tramway_export do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ module Tramway
2
+ module Export
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Tramway::Export
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Tramway
2
+ module Export
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require "tramway/export/engine"
2
+
3
+ module Tramway
4
+ module Export
5
+ class << self
6
+ def set_exportable_models(*models, project:)
7
+ @exportable_models ||= {}
8
+ @exportable_models[project] ||= []
9
+ @exportable_models[project] += models
10
+ end
11
+
12
+ def exportable_model?(model_class, project:)
13
+ @exportable_models[project.to_sym]&.include? model_class
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tramway-export
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Kalashnikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xls_exporter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Rails engine for exporting data
28
+ email:
29
+ - kalashnikovisme@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/tramway_export_manifest.js
38
+ - app/assets/javascripts/tramway/export/application.js
39
+ - app/assets/stylesheets/tramway/export/application.css
40
+ - app/controllers/tramway/export/application_controller.rb
41
+ - app/controllers/tramway/export/exports_controller.rb
42
+ - app/decorators/tramway/export/application_decorator.rb
43
+ - app/decorators/tramway/export/xlsx/application_decorator.rb
44
+ - app/helpers/tramway/export/application_helper.rb
45
+ - app/jobs/tramway/export/application_job.rb
46
+ - app/mailers/tramway/export/application_mailer.rb
47
+ - app/models/tramway/export/application_record.rb
48
+ - app/views/tramway/export/_button.html.haml
49
+ - config/routes.rb
50
+ - lib/tasks/tramway/export_tasks.rake
51
+ - lib/tramway/export.rb
52
+ - lib/tramway/export/engine.rb
53
+ - lib/tramway/export/version.rb
54
+ homepage: https://github.com/ulmic/tramway-dev
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.7.6
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Rails engine for exporting data
78
+ test_files: []