Skip to content

Commit

Permalink
Merge 2ee1c76 into 4e9a8d7
Browse files Browse the repository at this point in the history
  • Loading branch information
correalucas committed Sep 5, 2019
2 parents 4e9a8d7 + 2ee1c76 commit fe68d11
Show file tree
Hide file tree
Showing 75 changed files with 976 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ env:
- RAILS_VERSION=4.2
- RAILS_VERSION=5.0
- RAILS_VERSION=5.1
# - RAILS_VERSION=5.2
- RAILS_VERSION=5.2
- RAILS_VERSION=6.0
rvm:
- 2.2.10
- 2.3.7
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

**September 5, 2019**: 0.5.3 release

- Improved Rails 6.0 compatibility re MIME type

**May 1st, 2018**: 0.5.2 release

- Improved Rails 5 compatibility re MIME type
Expand Down Expand Up @@ -75,7 +79,7 @@
**July 17, 2012**: 0.1.0 release

- Tests completed
- Acts_as_xlsx tested, example in docs
- Acts_as_xlsx tested, example in docs

**July 12, 2012**: 0.0.1 release

Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ source "http://rubygems.org"
# development dependencies will be added by default to the :development group.
gemspec

ENV["RAILS_VERSION"] ||= '4.2'
ENV["RAILS_VERSION"] ||= '6.0'

case ENV['RAILS_VERSION']
when '6.0'
gem 'rails', "~> 6"
gem 'responders', '~> 2.0'
when '5.1'
gem 'rails', "~> 5.1.0"
gem 'responders', '~> 2.0'
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ source:

## Change log

**September 5, 2019**: 0.5.3 release

- Improved Rails 6.0 compatibility re MIME type

**May 1st, 2018**: 0.5.2 release

- Improved Rails 5 compatibility re MIME type
Expand Down
9 changes: 8 additions & 1 deletion lib/axlsx_rails/template_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ module Template::Handlers
class AxlsxBuilder

def default_format
Rails.version.to_f >= 5 ? Mime[:xlsx] : Mime::XLSX
case
when Rails.version.to_f >= 6
Mime[:xlsx].symbol
when Rails.version.to_f >= 5
Mime[:xlsx]
else
Mime::XLSX
end
end

def call(template, source = nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/axlsx_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module AxlsxRails
VERSION = '0.5.2'
VERSION = '0.5.3'
end
5 changes: 4 additions & 1 deletion spec/ci.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env ruby

if ENV['RAILS_VERSION'] =~ /^5.2/
if ENV['RAILS_VERSION'] =~ /^6.0/
puts "Testing Rails 6.0"
exit system('cd spec/dummy_6.0 && bundle install --without debug && bundle exec rake db:create && bundle exec rake db:migrate && cd ../../ && bundle exec rspec spec')
elsif ENV['RAILS_VERSION'] =~ /^5.2/
puts "Testing Rails 5.2"
exit system('cd spec/dummy_5.2 && bundle install --without debug && bundle exec rake db:create && bundle exec rake db:migrate && cd ../../ && bundle exec rspec spec')
elsif ENV['RAILS_VERSION'] =~ /^5.1/
Expand Down
6 changes: 6 additions & 0 deletions spec/dummy_6.0/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks
Empty file.
13 changes: 13 additions & 0 deletions spec/dummy_6.0/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
15 changes: 15 additions & 0 deletions spec/dummy_6.0/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
5 changes: 5 additions & 0 deletions spec/dummy_6.0/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
Empty file.
56 changes: 56 additions & 0 deletions spec/dummy_6.0/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#---
# Excerpted from "Crafting Rails Applications",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/jvrails for more book information.
#---
class HomeController < ApplicationController
def index
respond_to do |format|
format.html
format.xlsx
end
end

def only_html; end

def another
render :xlsx => "index", :filename => "filename_test.xlsx"
end

def render_elsewhere
case params[:type]
when '1'
render :xlsx => "home/index", :template => 'users/index'
when '2'
render :xlsx => "users/index", :template => 'users/index'
when '3'
render template: "users/index"
when '4'
render "users/index"
else
render :xlsx => "index"
end
end

def render_file_path
render :xlsx => Rails.root.join('app','views','users','index')
end

def withpartial
end

def useheader
respond_to do |format|
format.xlsx {
if params[:set_direct]
response.headers['Content-Disposition'] = "attachment; filename=\"filename_test.xlsx\""
else
render xlsx: "useheader", filename: "filename_test.xlsx"
end
}
end
end
end
18 changes: 18 additions & 0 deletions spec/dummy_6.0/app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class LikesController < ApplicationController
# GET /likes
# GET /likes.json
def index
@user = User.find(params[:user_id])
@likes = @user.likes

respond_to do |format|
format.html # index.html.erb
format.xlsx
end
end

def render_elsewhere
@user = User.find(params[:user_id])
render :xlsx => "index", :template => 'users/index'
end
end
37 changes: 37 additions & 0 deletions spec/dummy_6.0/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class UsersController < ApplicationController
respond_to :xlsx, :html
layout Proc.new { |c| return (c.request.format.symbol == :xlsx ? false : :default )}

# GET /users
# GET /users.json
def index
@users = User.all

respond_to do |format|
format.html # index.html.erb
format.xlsx
end
end

def show
@user = User.find(params[:id])
respond_with(@user) do |format|
format.xlsx { render "respond_with.xlsx.axlsx" }
end
end

def send_instructions
@user = User.find(params[:user_id])
@user.send_instructions
render plain: "Email sent"
end

def export
@user = User.find(params[:id])
respond_to do |format|
format.xlsx do
render xlsx: "export", filename: "export_#{@user.id}"
end
end
end
end
2 changes: 2 additions & 0 deletions spec/dummy_6.0/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file.
14 changes: 14 additions & 0 deletions spec/dummy_6.0/app/mailers/notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Notifier < ActionMailer::Base
default :from => 'noreply@company.com'

def instructions(user)
@user = user

# normal syntax
xlsx = render_to_string handlers: [:axlsx], template: 'users/send_instructions', layout: false, formats: [:xlsx]
attachments["user_#{user.id}.xlsx"] = {mime_type: Mime[:xlsx], content: xlsx}

mail :to => user.email, :subject => 'Instructions'
end

end
Empty file added spec/dummy_6.0/app/models/.keep
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions spec/dummy_6.0/app/models/like.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Like < ActiveRecord::Base
belongs_to :user
end
10 changes: 10 additions & 0 deletions spec/dummy_6.0/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'acts_as_xlsx'
class User < ActiveRecord::Base
acts_as_xlsx columns: [:id, :name, :last_name, :address, :email]

has_many :likes

def send_instructions
Notifier.instructions(self).deliver
end
end
3 changes: 3 additions & 0 deletions spec/dummy_6.0/app/views/home/_cover_sheet.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wb.add_worksheet(name: "Cover Sheet") do |sheet|
sheet.add_row ['Cover', 'Sheet']
end
4 changes: 4 additions & 0 deletions spec/dummy_6.0/app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>Hey, you can download the xlsx for this page by clicking the link below:</p>
<p><%= link_to "XLSX", home_path("xlsx") %></p>
<p><%= link_to "Another", '/another.xlsx' %></p>
<p><%= link_to "User header", '/useheader.xlsx' %></p>
8 changes: 8 additions & 0 deletions spec/dummy_6.0/app/views/home/index.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
wb = xlsx_package.workbook
style_shout = wb.styles.add_style sz: 16, b: true, alignment: { horizontal: :center }
wb.add_worksheet(name: "Foobar") do |sheet|
sheet.add_row ['Bad', 'spellers', 'of', 'the', 'world', '...']
sheet.add_row ['Untie!']
sheet.merge_cells("A2:E2")
sheet["A2"].style = style_shout
end
1 change: 1 addition & 0 deletions spec/dummy_6.0/app/views/home/only_html.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Foo, bar</p>
8 changes: 8 additions & 0 deletions spec/dummy_6.0/app/views/home/useheader.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
wb = xlsx_package.workbook
style_shout = wb.styles.add_style sz: 16, b: true, alignment: { horizontal: :center }
wb.add_worksheet(name: "Foobar") do |sheet|
sheet.add_row ['Bad', 'spellers', 'of', 'the', 'world', '...']
sheet.add_row ['Untie!']
sheet.merge_cells("A2:E2")
sheet["A2"].style = style_shout
end
9 changes: 9 additions & 0 deletions spec/dummy_6.0/app/views/home/withpartial.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
wb = xlsx_package.workbook
render :partial => 'cover_sheet', :locals => {:wb => wb}
style_shout = wb.styles.add_style sz: 16, b: true, alignment: { horizontal: :center }
wb.add_worksheet(name: "Foobar") do |sheet|
sheet.add_row ['Bad', 'spellers', 'of', 'the', 'world', '...']
sheet.add_row ['Untie!']
sheet.merge_cells("A2:E2")
sheet["A2"].style = style_shout
end
12 changes: 12 additions & 0 deletions spec/dummy_6.0/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy 6</title>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
12 changes: 12 additions & 0 deletions spec/dummy_6.0/app/views/layouts/users.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy 6</title>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
17 changes: 17 additions & 0 deletions spec/dummy_6.0/app/views/likes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>Listing likes for <%= @user.name %></h1>

<table>
<tr>
<th>Name</th>
</tr>

<% @likes.each do |like| %>
<tr>
<td><%= like.name %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Like', new_like_path %>
7 changes: 7 additions & 0 deletions spec/dummy_6.0/app/views/likes/index.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: "Foobar") do |sheet|
sheet.add_row [@user.name]
@likes.each do |like|
sheet.add_row [like.name]
end
end
14 changes: 14 additions & 0 deletions spec/dummy_6.0/app/views/notifier/instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Instructions</h1>
<p>
You have successfully signed up to example.com,
your username is: <%= @user.email %>.<br/>
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
6 changes: 6 additions & 0 deletions spec/dummy_6.0/app/views/notifier/instructions.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Instructions

You have successfully signed up to example.com,
your username is: <%= @user.email %>.

Thanks for joining and have a great day!

0 comments on commit fe68d11

Please sign in to comment.