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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/showoff.rb', line 38 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.
32 33 34 |
# File 'lib/showoff.rb', line 32 def cached_image_size @cached_image_size end |
Class Method Details
.do_static(what) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/showoff.rb', line 252 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 |