Class: Lissio::Server::Index
- Inherits:
-
Object
- Object
- Lissio::Server::Index
- Defined in:
- lib/lissio/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #html ⇒ Object
-
#initialize(server) ⇒ Index
constructor
A new instance of Index.
- #lissio(source = @server.main) ⇒ Object
Constructor Details
#initialize(server) ⇒ Index
Returns a new instance of Index.
44 45 46 47 |
# File 'lib/lissio/server.rb', line 44 def initialize(server) @server = server @path = server.index end |
Instance Method Details
#call(env) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/lissio/server.rb', line 49 def call(env) if env['PATH_INFO'] =~ /\.[^.]+$/ [404, {"Content-Type" => "text/plain"}, []] else [200, { 'Content-Type' => 'text/html' }, [html]] end end |
#html ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lissio/server.rb', line 57 def html source = if @path unless File.exist?(@path) raise "index does not exist: #{@path}" end File.read @path elsif File.exist? 'index.html.erb' File.read 'index.html.erb' else <<-HTML <!DOCTYPE html> <html> <head> <%= lissio %> </head> <body> </body> </html> HTML end ::ERB.new(source).result binding end |
#lissio(source = @server.main) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lissio/server.rb', line 82 def lissio(source = @server.main) if @server.debug if (assets = @server.sprockets[source].to_a).empty? raise "Cannot find asset: #{source}" end assets.map {|a| %{<script src="/assets/#{a.logical_path}?body=1"></script>} }.join ?\n else @server.sprockets.js_compressor = :uglify "<script src=\"/assets/#{source}.js\"></script>" end end |