Permalink
Browse files

can set the filename

  • Loading branch information...
1 parent 01d5a89 commit 0bf1ddb3af2a827b47b6a89ad93130b29dcd507f @xinuc committed May 31, 2009
Showing with 13 additions and 20 deletions.
  1. +1 −1 install.rb
  2. +2 −2 lib/ekuseru.rb
  3. +5 −6 lib/template_handler/eks.rb
  4. +3 −9 lib/template_handler/options.rb
  5. +2 −2 lib/workbook/workbook.rb
View
2 install.rb
@@ -1 +1 @@
-# Install hook code here
+puts IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
View
4 lib/ekuseru.rb
@@ -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
View
11 lib/template_handler/eks.rb
@@ -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
View
12 lib/template_handler/options.rb
@@ -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
View
4 lib/workbook/workbook.rb
@@ -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

0 comments on commit 0bf1ddb

Please sign in to comment.