May 10, 2008

egalite - 1

Rubyで新しいウェブアプリケーションフレームワークを書いています。フレームワークは沢山ありますので、私が新しいのを作ったところで話題にはならないでしょうけど、なかなか気に入っているので、完成したら公開したいと思っています。

とりあえず、現時点で稼動しているサンプルコードを載せたいと思います。

プログラム本体。

require 'egalite'

class DefaultController < Egalite::Controller
  def get(name = 'egalite')
    [
     "hello #{name}.",
     "cookies = #{cookies.inspect}",
     "#{url_for(:action => :bar, :params => [:a,:b])}",
     "<a href='test'>template test</a>",
     link_to('params test',:action => :test2, :hoge => "p i y o",
       "foo[bar][1]" => 1, "foo[bar][2]" => :two),
     link_to('add cookie', :action => :set_cookie, :id => :piyopiyo),
     link_to('del cookie', :action => :delete_cookie),
    ].join('<br/>')
  end
  def test
    {:posts => [
      {:title => 'piyo', :content => 'hiyoko.'},
      {:title => 'foo', :content => 'bar.'},
    ]}
  end
  def test2
    params.inspect
  end
  def set_cookie(s)
    cookies['test'] = {:expires => Time.now + 3600, :value => s, :path => '/'}
    redirect_to('/')
  end
  def delete_cookie
    cookies['test'] = {:expires => Time.now - 3600, :value => nil}
    redirect_to('/')
  end
end

ShowException = true
RouteDebug = false
egalite = Egalite::Handler.new

Rack::Handler::WEBrick.run(egalite, :Port => 4000)

HTMLページ (pages/test.html)

<html>
<head>
  <title>Egalite - A next web application framework on Ruby</title>
</head>
<body>
  <h1>Welcome to Egalite</h1>
  <group name='posts'>
    <h2>&=title;</h2>
    <p>&=content;</p>
  </group>
</body>
</html>
Posted by arai at May 10, 2008 04:49 PM
Comments

Where the name "Egalite" is from ?

Posted by: morita on May 10, 2008 10:02 PM

It's from Liberte, Egalite, Fraternite, the motto of France. (Liberty, Equality, Fraternity)

http://en.wikipedia.org/wiki/Libert%C3%A9,_%C3%A9galit%C3%A9,_fraternit%C3%A9

Posted by: arai on May 11, 2008 04:51 AM

なるほど。かっこいいすね。

Posted by: morita on May 11, 2008 10:05 AM

It seems very simple and fun :)

Posted by: mithrandir on May 24, 2008 02:46 AM
Post a comment














Please enter this 6digits Security Code (for SPAM's sake...).
spam対策のため6桁のセキュリティコードを入力してください。