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
-
#initialize(app = nil) ⇒ ShowOff
constructor
A new instance of ShowOff.
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 |
# File 'lib/showoff.rb', line 37 def initialize(app=nil) super(app) puts dir = File.(File.join(File.dirname(__FILE__), '..')) if Dir.pwd == dir .pres_dir = dir + '/example' @root_path = "." else .pres_dir = Dir.pwd @root_path = ".." end @cached_image_size = {} puts .pres_dir @pres_name = .pres_dir.split('/').pop end |
Instance Attribute Details
#cached_image_size ⇒ Object (readonly)
Returns the value of attribute cached_image_size.
31 32 33 |
# File 'lib/showoff.rb', line 31 def cached_image_size @cached_image_size end |
Class Method Details
.do_static(what) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/showoff.rb', line 286 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) data = showoff.send(what, true) if data.is_a?(File) File.cp(data.path, "#{name}.pdf") else out = "#{path}/#{name}/static" # First make a directory File.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}") } end end |