HTML5で、オフラインでも使えるiPod/iPhone超簡単アプリっぽいものをSinatra+Hamlのワンファイル・サーバで作ってみた
http://www.publickey1.jp/blog/11/html5ipodiphone.html を Ruby の Sinatra+Haml のワンファイル・サーバで実現してみました。
個人的には、「set :haml, :format => :html5」することで、haml で html5 を出力することが恐くなくなったのが大きいです。
#server.rb require 'rubygems' require 'sinatra/base' require 'haml' class App < Sinatra::Base set :haml, :format => :html5 get '/' do content_type 'text/html' haml <<-EOS !!!UTF-8 %html(manifest='/manifest.manifest') %body %img(src='/image.png') EOS end get '/image.png' do content_type 'image/png' send_file 'image.png' end get '/manifest.manifest' do content_type 'text/cache-manifest' <<-EOS CACHE MANIFEST # version 33 CACHE: image.png EOS end end App.run! :port => 8081
sinatra や haml *1の rubygems を入れておけば、「ruby server.rb」とするだけで、8081番ポートに「HTML5で、オフラインでも使えるiPod/iPhone超簡単アプリっぽいもの」が起動します。
私の iPod touch でも路線図がオフラインで使えるようになりました。Publickey ありがとう。
*1:あと、thin とかも