Coder Social home page Coder Social logo

perfectlynormal / axlsx_rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caxlsx/caxlsx_rails

0.0 3.0 0.0 137 KB

Rails plugin to provide renderer and template handler for axlsx gem.

License: MIT License

Ruby 96.82% Shell 0.65% JavaScript 2.53%

axlsx_rails's Introduction

Axlsx-Rails โ€” Axlsx templates for Rails views

Build Status Dependency Status

##Installation

In your Gemfile:

gem 'axlsx_rails'

##Requirements

  • Rails 3.1, but it has only been tested on 3.2.6

##Usage

Axlsx-Rails provides a renderer and a template handler. It adds the :xlsx format and parses .xlsx.axslx templates.

###Controller

You can either use the typical format:

respond_to do |format|
  format.xlsx
end

or call render directly:

render xlsx: "foobar", filename: "the_latest_foobar", disposition: 'inline'

If you merely want to specify a file name, you can do it one of two ways:

format.xlsx {
	response.headers['Content-Disposition'] = 'attachment; filename="my_new_filename.xlsx"'
}

Or:

format.xlsx {
  render xlsx: "action_or_template", disposition: "attachment", filename: "my_new_filename.xlsx"
}

NOTE: Someday it would be nice to merely say something like: render :filename 'blah.xlsx"

###Template

Use the .xlsx.axlsx extension (sorry if your lysdexic!) In the template, use xlsx_package variable, which is set with Axlsx::Package.new:

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("B1:B6")
  sheet["B1"].style = style_shout
end

If you use acts_as_xlsx, configure the active record normally, but specify the package in the template:

User.to_xlsx package: xlsx_package, (other options)

To set the author attribute upon Axlsx::Package.new, insert the following in application.rb:

config.axlsx_author = "Elmer Fudd"

NOTE: We really ought to allow the author to be set in each call

####Partials

Partials work as expected:

wb = xlsx_package.workbook
render :partial => 'cover_sheet', :locals => {:wb => wb}
wb.add_worksheet(name: "Content") do |sheet|
  sheet.add_row ['Content']
end

With the partial simply using the passed variables:

wb.add_worksheet(name: "Cover Sheet") do |sheet|
  sheet.add_row ['Cover', 'Sheet']
end

##Dependencies

##Authors

##Change log

  • July 25, 2012: 0.1.2 release

    • Partials tested
  • July 19, 2012: 0.1.1 release

    • Travis-ci added (thanks randym)
    • render statements and filename tests fixes (thanks engwan)
  • July 17, 2012: 0.1.0 release

    • Tests completed
    • Acts_as_xlsx tested, example in docs
  • July 12, 2012: 0.0.1 release

    • Initial posting.
    • It works, but there are no tests! Bad programmer!

axlsx_rails's People

Contributors

engwan avatar perfectlynormal avatar randym avatar straydogstudio avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.