Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

can set the filename

  • Loading branch information...
commit 0bf1ddb3af2a827b47b6a89ad93130b29dcd507f 1 parent 01d5a89
Nugroho Herucahyono authored
2  install.rb
View
@@ -1 +1 @@
-# Install hook code here
+puts IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
4 lib/ekuseru.rb
View
@@ -4,7 +4,7 @@
class ActionView::Base
private
- def setup
- @ekuseru_options = Ekuseru::TemplateHandler::Options.new controller
+ def _ekuseru_setup
+ @_ekuseru_options = Ekuseru::TemplateHandler::Options.new controller
end
end
11 lib/template_handler/eks.rb
View
@@ -3,14 +3,13 @@ module TemplateHandler
class Eks < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable
- def compile(template)
- "setup\n" +
+ def compile template
+ "_ekuseru_setup\n" +
"xls = Spreadsheet::Workbook.new\n" +
"#{template.source}\n" +
- "xls.render;"
+ "@_ekuseru_options.set_disposition(__filename ||= nil)\n" +
+ "xls.render\n"
end
end
end
-end
-
-
+end
12 lib/template_handler/options.rb
View
@@ -2,19 +2,13 @@ module Ekuseru
module TemplateHandler
class Options
- def initialize(controller)
+ def initialize controller
@controller = controller
- set_content_type
- set_disposition
- end
-
- def set_content_type
@controller.response.content_type ||= Mime::XLS
end
- def set_disposition
- # filename = options[:filename] ? "filename=#{options[:filename]}" : nil
- @controller.headers["Content-Disposition"] = ["attachment", nil].compact.join(';')
+ def set_disposition(filename = nil)
+ @controller.headers["Content-Disposition"] = ["attachment", filename ? "filename=\"#{filename}\"" : nil].compact.join(';')
end
end
4 lib/workbook/workbook.rb
View
@@ -7,11 +7,11 @@ class Workbook
# shit... don't know what's the better way..
# how to extract the file content from ole?
- # can u help me?
+ # any idea?
def render
tmp = File.join RAILS_ROOT, "tmp/", MD5::hexdigest(rand.to_s)
self.write tmp
- IO.read(tmp)
+ IO.read tmp
ensure
FileUtils.rm tmp if File.exists? tmp
end
Please sign in to comment.
Something went wrong with that request. Please try again.