grape-axlsx 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ba370a9110a9e5c07526bfa2d988ad119b91094
4
+ data.tar.gz: 857f6fea4218dffd5799a99da14c50123ebb8ec9
5
+ SHA512:
6
+ metadata.gz: 3852907ad61e6e481b49875b5bc0fd98d8d93d533f4b4b57298e2da4a29f5a8010760e97ef918bbdfb92008d0d553335851676c017e8e69e85c712b5f66d70ce
7
+ data.tar.gz: 32117e739923779077190f0fc9e9d1ca62a88b2e545addf113adae8c92073de39ce97717a73f7e037a16f7e931f70f7fd9cf980f7922887109d6668eaf411c86
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-axlsx.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ivan Kabluchkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Grape::Axlsx
2
+
3
+ Use [Axlsx](https://github.com/randym/axlsx) templates in [Grape](https://github.com/ruby-grape/grape)
4
+
5
+ Based on [grape-jbuilder](https://github.com/milkcocoa/grape-jbuilder) and [axlsx-rails](https://github.com/straydogstudio/axlsx_rails)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'grape-axlsx'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install grape-axlsx
22
+
23
+ ## Usage
24
+
25
+ ### Setup view root directory
26
+
27
+ ```ruby
28
+ use Rack::Config do |env|
29
+ env['api.tilt.root'] = '/path/to/view/root/directory'
30
+ end
31
+ ```
32
+
33
+ ### Setup Axlsx Formatter for xlsx api format
34
+
35
+ ```ruby
36
+ class API < Grape::API
37
+ content_type :xlsx, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
38
+ format :xlsx
39
+ formatter :xlsx, Grape::Formatter::Axlsx
40
+ end
41
+ ```
42
+
43
+ ### Specify axlsx template path
44
+
45
+ ```ruby
46
+ resources :users do
47
+ get axlsx: 'users/user.xlsx.axlsx' do
48
+ @users = User.all
49
+ end
50
+ end
51
+
52
+ # or you can omit .axlsx extension
53
+
54
+ ...
55
+ get axlsx: 'users/user.xlsx' do
56
+ ...
57
+ ```
58
+
59
+ ### Example of axlsx template
60
+
61
+ ```ruby
62
+ # NOTE: xlsx_package is predefined instance of Axlsx::Package
63
+ wb = xlsx_package.workbook
64
+ wb.add_worksheet(name: "Users list") do |sheet|
65
+ sheet.add_row ["id", "First name", "Last name", "Middle name"]
66
+ @users.each do |user|
67
+ sheet.add_row [user.id, user.first_name, user.last_name, user.middle_name]
68
+ end
69
+ end
70
+ ```
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it ( https://github.com/lfidnl/grape-axlsx/fork )
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape/axlsx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grape-axlsx"
8
+ spec.version = Grape::Axlsx::VERSION
9
+ spec.authors = ["Ivan Kabluchkov"]
10
+ spec.email = ["ikabluchkov@gmail.com"]
11
+
12
+ spec.summary = %q{Use Axlsx in Grape}
13
+ spec.description = %q{Simple implementation for using Axlsx templates in Grape.}
14
+ spec.homepage = "https://github.com/lfidnl/grape-axlsx"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "grape", ">= 0.3"
21
+ spec.add_dependency "axlsx"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,5 @@
1
+ require "axlsx"
2
+
3
+ require "grape/axlsx/version"
4
+ require "grape/axlsx/renderer"
5
+ require "grape/formatter/axlsx"
@@ -0,0 +1,34 @@
1
+ module Grape
2
+ module Axlsx
3
+ class Renderer
4
+ attr_reader :view_path, :template
5
+
6
+ def initialize(view_path, template)
7
+ @view_path, @template = view_path, template
8
+ end
9
+
10
+ def render(scope)
11
+ unless view_path
12
+ raise "Use Rack::Config to set 'api.tilt.root' in config.ru"
13
+ end
14
+
15
+ context = scope.instance_eval { binding }
16
+ eval "xlsx_package = ::Axlsx::Package.new; #{template_content}; xlsx_package.to_stream.string;", context
17
+ end
18
+
19
+ private
20
+
21
+ def file
22
+ File.join view_path, template_with_extension
23
+ end
24
+
25
+ def template_with_extension
26
+ template[/\.axlsx$/] ? template : "#{template}.axlsx"
27
+ end
28
+
29
+ def template_content
30
+ File.read(file)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Grape
2
+ module Axlsx
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module Grape
2
+ module Formatter
3
+ class Axlsx
4
+ attr_reader :env, :endpoint, :object
5
+
6
+ def self.call(object, env)
7
+ new(object, env).call
8
+ end
9
+
10
+ def initialize(object, env)
11
+ @object, @env = object, env
12
+ @endpoint = env['api.endpoint']
13
+ end
14
+
15
+ def call
16
+ Grape::Axlsx::Renderer.new(env['api.tilt.root'], template).render(endpoint)
17
+ end
18
+
19
+ private
20
+
21
+ def template
22
+ endpoint.options.fetch(:route_options, {})[:axlsx]
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-axlsx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Kabluchkov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: axlsx
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Simple implementation for using Axlsx templates in Grape.
84
+ email:
85
+ - ikabluchkov@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - grape-axlsx.gemspec
98
+ - lib/grape/axlsx.rb
99
+ - lib/grape/axlsx/renderer.rb
100
+ - lib/grape/axlsx/version.rb
101
+ - lib/grape/formatter/axlsx.rb
102
+ homepage: https://github.com/lfidnl/grape-axlsx
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.0
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Use Axlsx in Grape
126
+ test_files: []