Class: ShowOff
- Inherits:
-
Sinatra::Application
- Object
- Sinatra::Application
- ShowOff
- Defined in:
- lib/showoff.rb
Instance Attribute Summary collapse
-
#cached_image_size ⇒ Object
readonly
Returns the value of attribute cached_image_size.
Class Method Summary collapse
Instance Method Summary collapse
- #eval_ruby(code) ⇒ Object
-
#initialize(app = nil) ⇒ ShowOff
constructor
A new instance of ShowOff.
- #require_ruby_files ⇒ Object
Constructor Details
#initialize(app = nil) ⇒ ShowOff
Returns a new instance of ShowOff.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/showoff.rb', line 37 def initialize(app=nil) super(app) @logger = Logger.new(STDOUT) @logger.formatter = proc { |severity,datetime,progname,msg| "#{progname} #{msg}\n" } @logger.level = settings.verbose ? Logger::DEBUG : Logger::WARN dir = File.(File.join(File.dirname(__FILE__), '..')) @logger.debug(dir) showoff_dir = File.(File.join(File.dirname(__FILE__), '..')) settings.pres_dir ||= Dir.pwd @root_path = "." settings.pres_dir = File.(settings.pres_dir) if (settings.pres_file) ShowOffUtils.presentation_config_file = settings.pres_file end @cached_image_size = {} @logger.debug settings.pres_dir @pres_name = settings.pres_dir.split('/').pop require_ruby_files # Default asset path @asset_path = "./" end |
Instance Attribute Details
#cached_image_size ⇒ Object (readonly)
Returns the value of attribute cached_image_size.
28 29 30 |
# File 'lib/showoff.rb', line 28 def cached_image_size @cached_image_size end |
Class Method Details
.do_static(what) ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/showoff.rb', line 417 def self.do_static(what) what = "index" if !what # Nasty hack to get the actual ShowOff module showoff = ShowOff.new while !showoff.is_a?(ShowOff) showoff = showoff.instance_variable_get(:@app) end name = showoff.instance_variable_get(:@pres_name) path = showoff.instance_variable_get(:@root_path) logger = showoff.instance_variable_get(:@logger) data = showoff.send(what, true) if data.is_a?(File) FileUtils.cp(data.path, "#{name}.pdf") else out = File.("#{path}/static") # First make a directory FileUtils.makedirs(out) # Then write the html file = File.new("#{out}/index.html", "w") file.puts(data) file.close # Now copy all the js and css my_path = File.join( File.dirname(__FILE__), '..', 'public') ["js", "css"].each { |dir| FileUtils.copy_entry("#{my_path}/#{dir}", "#{out}/#{dir}") } # And copy the directory Dir.glob("#{my_path}/#{name}/*").each { |subpath| base = File.basename(subpath) next if "static" == base next unless File.directory?(subpath) || base.match(/\.(css|js)$/) FileUtils.copy_entry(subpath, "#{out}/#{base}") } # Set up file dir file_dir = File.join(out, 'file') FileUtils.makedirs(file_dir) pres_dir = showoff.settings.pres_dir # ..., copy all user-defined styles and javascript files Dir.glob("#{pres_dir}/*.{css,js}").each { |path| FileUtils.copy(path, File.join(file_dir, File.basename(path))) } # ... and copy all needed image files data.scan(/img src=\".\/file\/(.*?)\"/).flatten.each do |path| dir = File.dirname(path) FileUtils.makedirs(File.join(file_dir, dir)) FileUtils.copy(File.join(pres_dir, path), File.join(file_dir, path)) end # copy images from css too Dir.glob("#{pres_dir}/*.css").each do |css_path| File.open(css_path) do |file| data = file.read data.scan(/url\((.*)\)/).flatten.each do |path| logger.debug path dir = File.dirname(path) FileUtils.makedirs(File.join(file_dir, dir)) FileUtils.copy(File.join(pres_dir, path), File.join(file_dir, path)) end end end end end |
.pres_dir_current ⇒ Object
63 64 65 66 |
# File 'lib/showoff.rb', line 63 def self.pres_dir_current opt = {:pres_dir => Dir.pwd} ShowOff.set opt end |
Instance Method Details
#eval_ruby(code) ⇒ Object
483 484 485 486 487 |
# File 'lib/showoff.rb', line 483 def eval_ruby code eval(code).to_s rescue => e e. end |
#require_ruby_files ⇒ Object
68 69 70 |
# File 'lib/showoff.rb', line 68 def require_ruby_files Dir.glob("#{settings.pres_dir}/*.rb").map { |path| require path } end |