rails_importer 0.1.0 → 0.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: 2efa0069a20c4c032a168de757a72f39a75c85e3
4
- data.tar.gz: af122e4cd9a794292f9218c214d2ae2f7433d1de
3
+ metadata.gz: 960482940d9658460f988cc0ebb40b48ae004205
4
+ data.tar.gz: 6633a7b469898d1450be8189729a3763ae4db22d
5
5
  SHA512:
6
- metadata.gz: 54cfa3a1e61009617e04270ac55671263bd020b6e4eb6cd67018ecdf1f714ef81bda6f8e06ffe7210ab4750f829b5ee3a5a46c65f7d98d51d038e7b406211b0a
7
- data.tar.gz: babd7b55764ed5f371affd5985dac0a5f48fd57191221951788574652fb6b103e74ec1e0746fbf98556d1f850f7a63f82599cb99bffb745a012322bba5cb4884
6
+ metadata.gz: 7c0591bd134f1e8dbde0179f701ea07ebbbce4ef6978f292d789509e05ac6a0bcc09de3e14f2f7585ae5ba441702ba1984e69edb20ae486e205498e65f0797a0
7
+ data.tar.gz: 3e5c4469e487e6c5384f948d1583a8ac86f9154a33393655021957a20745f5f0eae0da799043b0bb359a20302fe460e6291392044e724f91765bbbcdfcea73f9
data/CHANGELOG.md CHANGED
@@ -16,6 +16,10 @@
16
16
 
17
17
  ## Changes
18
18
 
19
+ ### 0.2.0 (February 18, 2016)
20
+
21
+ * [FEATURE] Add sample file link to import form which downloads a pre-defined sample file for each importer
22
+
19
23
  ### 0.1.0 (February 12, 2016)
20
24
 
21
25
  * [FEATURE] First release
data/README.md CHANGED
@@ -112,6 +112,15 @@ end
112
112
  ```
113
113
  The `context` variable used above contains the app routes, so don't forget to use it.
114
114
 
115
+ ## Sample files
116
+ You can add a sample file for each importer if you wish to communicate the spreadsheet structure your importer follows.
117
+
118
+ The sample file must be located inside the `lib/rails_importer/templates/` folder and have the same name as your importer key. For the `ExampleImporter` used above, the path would be: `lib/rails_importer/templates/example.xslx`
119
+
120
+ The import form has a link to the sample file. If you do not declare the file, then this link will redirect to `after_import_path`.
121
+
122
+ Note: `.xlsx` sample files are the only ones currently supported (for now).
123
+
115
124
  ## Import Job
116
125
  When processing an import file, an ActiveJob instance is used. If you're deploying to production, you will want to use some active job adapter, such as [Sidekiq](https://github.com/mperham/sidekiq).
117
126
 
@@ -17,11 +17,14 @@ module RailsImporter
17
17
  end
18
18
  end
19
19
 
20
- # def template
21
- # file = File.open(@importer_class.sample_file)
20
+ def sample
21
+ file = File.open(@importer_class.sample_file)
22
22
 
23
- # send_data file.read, :filename => File.basename(@importer.sample_file)
24
- # end
23
+ send_data file.read, :filename => File.basename(@importer_class.sample_file)
24
+ rescue => e
25
+ flash[:alert] = I18n.t(:sample_file_not_available, scope: :rails_importer)
26
+ redirect_to after_import_path
27
+ end
25
28
 
26
29
  private
27
30
 
@@ -4,5 +4,8 @@
4
4
  <%= f.label :import_file %>
5
5
  <%= f.file_field :import_file %>
6
6
 
7
+ <div class="sample-file">
8
+ <%= link_to I18n.t(:sample_file, scope: :rails_importer), sample_imports_path %>
9
+ </div>
7
10
  <%= f.submit %>
8
11
  <% end %>
@@ -2,3 +2,5 @@ en:
2
2
  rails_importer:
3
3
  importer_does_not_exist: Importer does not exist
4
4
  processing_import: Importing has begun. Results will be available soon.
5
+ sample_file: Sample file
6
+ sample_file_not_available: Sample file not available
@@ -2,3 +2,5 @@ es:
2
2
  rails_importer:
3
3
  importer_does_not_exist: El importador especificado no existe
4
4
  processing_import: La importación ha comenzado. En unos instances el resultado estará disponible.
5
+ sample_file: Archivo de ejemplo
6
+ sample_file_not_available: Archivo de ejemplo no disponible
data/config/routes.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  RailsImporter::Engine.routes.draw do
2
2
  scope "importers/:importer_key" do
3
- resources :imports, only: [:new, :create], path: ''
3
+ resources :imports, only: [:new, :create], path: '' do
4
+ collection do
5
+ get :sample
6
+ end
7
+ end
4
8
  end
5
9
  end
@@ -56,9 +56,14 @@ module RailsImporter
56
56
  raise "#{__FILE__}:#{__LINE__} You must define it"
57
57
  end
58
58
 
59
+ # The importer sample file
60
+ def self.sample_file
61
+ Rails.root.join("lib/rails_importer/templates/#{key}.xlsx")
62
+ end
63
+
59
64
  private
60
65
 
61
- # Returns a Roo instance acording the file extension.
66
+ # Returns a Roo::Spreadsheet instance according the file extension.
62
67
  def open_spreadsheet sheet_name = ''
63
68
  extension = File.extname(@filepath.split("/").last)
64
69
  @spreadsheet = Roo::Spreadsheet.open(@filepath, extension: extension)
@@ -1,3 +1,3 @@
1
1
  module RailsImporter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastián Vicencio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails