Class: Deck::RackApp
- Inherits:
-
Object
- Object
- Deck::RackApp
- Defined in:
- lib/deck/rack_app.rb
Class Method Summary collapse
- .app_root ⇒ Object
- .build(slide_files, options = {}) ⇒ Object
- .enable_thin_logging ⇒ Object
- .public_file_server ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
- #deck ⇒ Object
- #extract_options(config) ⇒ Object
- #extract_slides(config, json_file_dir) ⇒ Object
-
#initialize(slide_files, options = {}) ⇒ RackApp
constructor
A new instance of RackApp.
- #parse_showoff_json(slide_file) ⇒ Object
- #slides ⇒ Object
Constructor Details
#initialize(slide_files, options = {}) ⇒ RackApp
Returns a new instance of RackApp.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/deck/rack_app.rb', line 39 def initialize , = {} @options = @slide_files = [].flatten.map do || case when /\/?showoff(.*)\.json$/ parse_showoff_json() else File.new() end end.flatten @file_servers = [::Deck::RackApp.public_file_server] + @slide_files.map do || File. File.dirname(.path) if .is_a? File end.compact.uniq.map do || Rack::File.new() end end |
Class Method Details
.app_root ⇒ Object
8 9 10 11 |
# File 'lib/deck/rack_app.rb', line 8 def self.app_root here = File.dirname(__FILE__) app_root = File. "#{here}/../.." end |
.build(slide_files, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/deck/rack_app.rb', line 17 def self.build , = {} enable_thin_logging() Rack::Builder.app do use Rack::ShowExceptions use Rack::ShowStatus use Rack::Codehighlighter, :coderay, :element => "pre>code", :markdown => true, :pattern => /\A[:@]{3}\s?(\w+)\s*(\n|
)/i run ::Deck::RackApp.new(, ) end end |
.enable_thin_logging ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/deck/rack_app.rb', line 31 def self.enable_thin_logging if const_defined?(:Thin) if require "thin/logging" Thin::Logging.debug = true end end end |
.public_file_server ⇒ Object
13 14 15 |
# File 'lib/deck/rack_app.rb', line 13 def self.public_file_server Rack::File.new("#{app_root}/public") end |
Instance Method Details
#call(env) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/deck/rack_app.rb', line 86 def call env request = Rack::Request.new(env) if request.path == "/" [200, {'Content-Type' => 'text/html'}, [deck.to_pretty]] else result = [404, {}, []] @file_servers.each do |file_server| result = file_server.call(env) return result if result.first < 400 end result end end |
#deck ⇒ Object
100 101 102 |
# File 'lib/deck/rack_app.rb', line 100 def deck SlideDeck.new({:slides => }.merge(@options)) end |
#extract_options(config) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/deck/rack_app.rb', line 78 def (config) ["style", "transition"].each do |key| if config[key] and !@options[key.to_sym] @options[key.to_sym] = config[key] end end end |
#extract_slides(config, json_file_dir) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/deck/rack_app.rb', line 67 def (config, json_file_dir) config['sections'].map do |markdown_file| if markdown_file =~ /^# / # you can use literal markdown instead of a file name s = Slide.split(markdown_file) s else File.new(json_file_dir + '/' + markdown_file) end end end |
#parse_showoff_json(slide_file) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/deck/rack_app.rb', line 59 def parse_showoff_json() json_file_dir = File.(File.dirname()) json_file = config = JSON.parse(File.read(json_file)) (config) (config, json_file_dir) end |