workbook_rails 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,14 +12,14 @@ module WorkbookRails
12
12
  initializer 'workbook_rails.action_controller' do
13
13
  ActiveSupport.on_load :action_controller do
14
14
  require 'workbook_rails/action_controller'
15
- end
16
- end
17
15
 
18
- unless Mime::Type.lookup_by_extension(:xlsx)
19
- Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
20
- end
21
- unless Mime::Type.lookup_by_extension(:xls)
22
- Mime::Type.register "application/vnd.ms-excel", :xls
16
+ unless Mime[:xlsx]
17
+ Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
18
+ end
19
+ unless Mime[:xls]
20
+ Mime::Type.register "application/vnd.ms-excel", :xls
21
+ end
22
+ end
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -9,15 +9,16 @@ module WorkbookRails
9
9
  when :xlsx then workbook.stream_xlsx
10
10
  when :xls then
11
11
  io = StringIO.new
12
- workbook.to_xls.write(io)
12
+ xls = workbook.is_a?(Spreadsheet::Workbook) ? workbook : workbook.to_xls
13
+ xls.write(io)
13
14
  io.string
14
15
  end
15
16
  end
16
17
 
17
- def self.call(template)
18
+ def self.call(template, source = nil)
18
19
  "workbook = Workbook::Book.new;\n" +
19
- template.source +
20
- ";\nWorkbookRails::TemplateHandler.workbook_to_string(workbook, lookup_context.rendered_format);"
20
+ (source || template.source) +
21
+ ";\nWorkbookRails::TemplateHandler.workbook_to_string(workbook, lookup_context.formats.last);"
21
22
  end
22
23
 
23
24
  end
@@ -1,3 +1,3 @@
1
1
  module WorkbookRails
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -40,10 +40,6 @@ class HomeController < ApplicationController
40
40
  end
41
41
  end
42
42
 
43
- def render_file_path
44
- render :xlsx => 'index', :file => Rails.root.join('app','views','users','respond_with')
45
- end
46
-
47
43
  def withpartial
48
44
  end
49
45
 
@@ -11,6 +11,6 @@ class UsersController < ApplicationController
11
11
  def send_instructions
12
12
  @user = User.find(params[:user_id])
13
13
  @user.send_instructions
14
- render text: "Email sent"
14
+ render plain: "Email sent"
15
15
  end
16
16
  end
@@ -6,9 +6,9 @@ class Notifier < ActionMailer::Base
6
6
 
7
7
  # normal syntax
8
8
  xlsx = render_to_string handlers: [:wb], template: 'users/mailers/instructions', layout: false, formats: [:xlsx]
9
- attachments["user_#{user.id}.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
9
+ attachments["user_#{user.id}.xlsx"] = {mime_type: Mime[:xlsx], content: xlsx}
10
10
 
11
11
  mail :to => user.email, :subject => 'Instructions'
12
12
  end
13
13
 
14
- end
14
+ end
@@ -12,6 +12,5 @@ Rails.application.routes.draw do
12
12
  get "/withpartial(.:format)", :to => "home#withpartial", :as => :withpartial
13
13
  get "/home/render_elsewhere(.:format)", :to => "home#render_elsewhere"
14
14
  get "/render_elsewhere(.:format)", :to => "home#render_elsewhere"
15
- get "/render_file_path(.:format)", :to => "home#render_file_path"
16
15
  root to: "home#index"
17
16
  end
@@ -1,4 +1,4 @@
1
- class CreateUsers < ActiveRecord::Migration
1
+ class CreateUsers < (Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[5.0])
2
2
  def change
3
3
  create_table :users do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class CreateLikes < ActiveRecord::Migration
1
+ class CreateLikes < (Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[5.0])
2
2
  def change
3
3
  create_table :likes do |t|
4
4
  t.string :name
@@ -1,32 +1,30 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
5
4
  #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
11
10
  #
12
- # It's strongly recommended to check this file into your version control system.
11
+ # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(:version => 20121206210955) do
15
-
16
- create_table "likes", :force => true do |t|
17
- t.string "name"
18
- t.integer "user_id"
19
- t.datetime "created_at"
20
- t.datetime "updated_at"
13
+ ActiveRecord::Schema[7.0].define(version: 2012_12_06_210955) do
14
+ create_table "likes", force: :cascade do |t|
15
+ t.string "name"
16
+ t.integer "user_id"
17
+ t.datetime "created_at", precision: nil
18
+ t.datetime "updated_at", precision: nil
21
19
  end
22
20
 
23
- create_table "users", :force => true do |t|
24
- t.string "name"
25
- t.string "last_name"
26
- t.string "address"
27
- t.string "email"
28
- t.datetime "created_at"
29
- t.datetime "updated_at"
21
+ create_table "users", force: :cascade do |t|
22
+ t.string "name"
23
+ t.string "last_name"
24
+ t.string "address"
25
+ t.string "email"
26
+ t.datetime "created_at", precision: nil
27
+ t.datetime "updated_at", precision: nil
30
28
  end
31
29
 
32
30
  end
Binary file
@@ -0,0 +1,24 @@
1
+  (13.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
2
+  (10.5ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
3
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
4
+ Migrating to CreateUsers (20120717192452)
5
+  (0.1ms) begin transaction
6
+ DEPRECATION WARNING: Directly inheriting from ActiveRecord::Migration is deprecated. Please specify the Rails release the migration was written for:
7
+
8
+ class CreateUsers < ActiveRecord::Migration[4.2] (called from load at /home/sergio/.rvm/gems/ruby-2.3.1/bin/rake:23)
9
+  (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "last_name" varchar, "address" varchar, "email" varchar, "created_at" datetime, "updated_at" datetime)
10
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20120717192452"]]
11
+  (10.0ms) commit transaction
12
+ Migrating to CreateLikes (20121206210955)
13
+  (0.7ms) begin transaction
14
+ DEPRECATION WARNING: Directly inheriting from ActiveRecord::Migration is deprecated. Please specify the Rails release the migration was written for:
15
+
16
+ class CreateLikes < ActiveRecord::Migration[4.2] (called from load at /home/sergio/.rvm/gems/ruby-2.3.1/bin/rake:23)
17
+  (0.3ms) CREATE TABLE "likes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "user_id" integer, "created_at" datetime, "updated_at" datetime)
18
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20121206210955"]]
19
+  (11.0ms) commit transaction
20
+ ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]]
21
+  (0.1ms) begin transaction
22
+ SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", 2017-03-16 16:22:28 UTC], ["updated_at", 2017-03-16 16:22:28 UTC]]
23
+  (8.5ms) commit transaction
24
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"