-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
976 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ApplicationHelper | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Like < ActiveRecord::Base | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Foo, bar</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
Oops, something went wrong.