Created
July 19, 2011 23:34
-
-
Save ream88/1094013 to your computer and use it in GitHub Desktop.
writeexcel Template handler (fileextension is .writeexcel) for Rails 3.0
This file contains hidden or 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
| require 'action_dispatch/http/mime_type' | |
| require 'action_view' | |
| require 'writeexcel' | |
| class WriteExcelTemplateHandler < ActionView::TemplateHandler | |
| include ActionView::TemplateHandlers::Compilable | |
| def compile(template) | |
| %{ | |
| tmp = Tempfile.new('writeexcel') | |
| workbook = WriteExcel.new(tmp.path) | |
| #{template.source} | |
| workbook.close | |
| tmp.read | |
| } | |
| end | |
| end | |
| Mime::Type.register('application/vnd.ms-excel', :xls) | |
| ActionView::Template.register_template_handler('writeexcel', WriteExcelTemplateHandler) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, I will try to make a Rails 2.3.5 handler too.