xlsxtream_rails 0.2.0 → 0.5.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
  SHA256:
3
- metadata.gz: 2356d39bc93f7932ff1ebcf31f4e79d0feb38c31521227c9524ac745ccaaff3a
4
- data.tar.gz: e3cacfb6c7bcf4cb76ba7bcb1469222631f36e1c8343ae717f8420eb76bc4468
3
+ metadata.gz: 9a54b0cad604244bd9547c4b096192ac193b7e326dc4b013eab909b78edea6c2
4
+ data.tar.gz: e565f309ddb38b134d307c1558dad4a2b0696787688af64853923de4bbbde1d9
5
5
  SHA512:
6
- metadata.gz: 317eb0b72e5c04d913ba5054450e90b4de0ff27067276740ece5f1b4af24f5f5c55df9b4984d25f92da1839f30328cd1379a3bd6941a9faad80e96c603a20fb1
7
- data.tar.gz: adc28f4c75706991af808e076d3f5049d67a8e1b3c688e8788d5ed32b6b7ff418a6b08ac7b449eaed0c481fa5da1f8101ece6d23585158c7c360557de07b6085
6
+ metadata.gz: cac8f0033dd5a7d1b2af96243e011d573da24885a2013ce819d66d806da6b28b88c18d30f6c9cd9bd96d61402df45bdd6081efe57a9ea2b2badcbec67728e66d
7
+ data.tar.gz: 1dfa9fffbdc4092d0ae4641d5311eaa27940fcad75af1b28645f75109622ea4543243ec3ef70fb45172c065359158326647d88b80995098243431f61590e1a7d
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # XlsxtreamRails
2
- Xlsx stream download for rails with template.
2
+ Xlsx stream download for rails.
3
3
 
4
4
  ## Installation
5
5
  Add this line to your application's Gemfile:
@@ -61,18 +61,6 @@ class Post < ApplicationRecord
61
61
  end
62
62
  ```
63
63
 
64
- ## View
65
-
66
- If you want to render with template, you can create the template with the .xlsx.xrb extension (index.xlsx.xrb for example)
67
-
68
- ```ruby
69
- xlsx.write_worksheet do |sheet|
70
- @posts.find_each do |post|
71
- sheet.add_row [post.id, post.title]
72
- end
73
- end
74
- ```
75
-
76
64
  ## This gem is inspired by the following
77
65
 
78
66
  [spreadsheet_architect](https://github.com/westonganger/spreadsheet_architect)
@@ -9,8 +9,10 @@ ActionController::Renderers.add :xlsx do |data, options|
9
9
  # disposition / filename
10
10
  options[:disposition] = options.delete(:disposition) || "attachment"
11
11
 
12
- if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Relation)
13
- options[:filename] ||= data.klass.name.pluralize
12
+ options[:filename] ||= if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Relation)
13
+ "#{data.klass.model_name.human}_#{Time.now.to_i}"
14
+ else
15
+ Time.now.to_i
14
16
  end
15
17
 
16
18
  options[:filename] = options[:filename] ? options[:filename].strip.sub(/\.xlsx$/i, "") : "data"
@@ -0,0 +1,8 @@
1
+ module XlsxtreamRails
2
+ module ClassMethods
3
+ # TODO
4
+ def to_xlsx
5
+ column_names.map { |x| x.to_sym }
6
+ end
7
+ end
8
+ end
@@ -1,11 +1,6 @@
1
1
  module XlsxtreamRails
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer "xlsxtream_rails.initialization" do
4
- ActiveSupport.on_load(:action_view) do
5
- require "xlsxtream_rails/template_handler"
6
- ActionView::Template.register_template_handler :xrb, ActionView::Template::Handlers::XrbBuilder.new
7
- end
8
-
9
4
  ActiveSupport.on_load(:action_controller) do
10
5
  require "xlsxtream_rails/action_controller"
11
6
  end
@@ -1,3 +1,3 @@
1
1
  module XlsxtreamRails
2
- VERSION = "0.2.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,11 +1,15 @@
1
1
  require "xlsxtream"
2
+ require "xlsxtream_rails/class_methods"
2
3
  require "xlsxtream_rails/utils"
3
4
  require "xlsxtream_rails/version"
4
5
  require "xlsxtream_rails/railtie"
5
6
 
6
7
  module XlsxtreamRails
8
+ def self.included(base)
9
+ base.send(:extend, ClassMethods)
10
+ end
11
+
7
12
  def xlsx_columns(opts = {})
8
- column_names = self.class.column_names
9
- column_names.map { |x| x.to_sym }
13
+ self.class.to_xlsx
10
14
  end
11
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsxtream_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - doabit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.4.0
41
- description: Xlsx stream download for rails with template.
41
+ description: Xlsx stream download for rails.
42
42
  email:
43
43
  - doinsist@gmail.com
44
44
  executables: []
@@ -51,8 +51,8 @@ files:
51
51
  - lib/tasks/xlsxtream_rails_tasks.rake
52
52
  - lib/xlsxtream_rails.rb
53
53
  - lib/xlsxtream_rails/action_controller.rb
54
+ - lib/xlsxtream_rails/class_methods.rb
54
55
  - lib/xlsxtream_rails/railtie.rb
55
- - lib/xlsxtream_rails/template_handler.rb
56
56
  - lib/xlsxtream_rails/utils.rb
57
57
  - lib/xlsxtream_rails/version.rb
58
58
  homepage: https://github.com/ruby-gems/xlsxtream_rails
@@ -80,5 +80,5 @@ requirements: []
80
80
  rubygems_version: 3.2.3
81
81
  signing_key:
82
82
  specification_version: 4
83
- summary: Xlsx stream download for rails with template.
83
+ summary: Xlsx stream download for rails.
84
84
  test_files: []
@@ -1,19 +0,0 @@
1
- require "action_view"
2
- require "stringio"
3
-
4
- module ActionView
5
- module Template::Handlers
6
- class XrbBuilder
7
- def default_format
8
- Mime[:xlsx].symbol
9
- end
10
-
11
- def call(template, source = nil)
12
- builder = StringIO.new
13
- builder << "# encoding: utf-8\n"
14
- builder << (source || template.source)
15
- builder.string
16
- end
17
- end
18
- end
19
- end