Class: Guides::App
- Inherits:
-
Object
- Object
- Guides::App
- Defined in:
- lib/guides/preview.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(options = {}) ⇒ App
constructor
A new instance of App.
- #local_assets ⇒ Object
- #source_assets ⇒ Object
- #source_templates ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ App
Returns a new instance of App.
5 6 7 8 9 10 |
# File 'lib/guides/preview.rb', line 5 def initialize( = {}) @production = !![:production] @local = Rack::File.new(local_assets) @source = Rack::File.new(source_assets) @output = Rack::File.new(File.join(Guides.root, @production ? "output" : "staging")) end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/guides/preview.rb', line 24 def call(env) path = env["PATH_INFO"] case path when "/" env["PATH_INFO"] = "/index.html" return call(env) when /\/(.*)\.html$/ name = $1 generator = Guides::Generator.new({ :production => @production }) source_file = Dir["#{source_templates}/#{name}.{#{Guides::Generator::EXTENSIONS.join(",")}}"].first unless source_file return [404, {"Content-Type" => "text/html"}, ["#{name} not found in #{source_templates}: #{Guides.root}"]] end source_base = File.basename(source_file) if generator.construction?(source_base) && @production return [404, {"Content-Type" => "text/html"}, ["#{name} is under construction and not available in production"]] end generator.send(:generate_guide, source_base, "#{name}.html") return @output.call(env) else source = @source.call(env) return source if source.first == 200 return @local.call(env) end end |
#local_assets ⇒ Object
12 13 14 |
# File 'lib/guides/preview.rb', line 12 def local_assets File.("../templates/assets", __FILE__) end |