Contenu connexe Similaire à 20101106 ramaze発表 (20) 20101106 ramaze発表29. Rails > Ramaze > Sinatra > CGI
Railsよりシンプル・軽量
が求められるケースも
複雑・充実 シンプル・軽量
コンビニへ行くのにプリウスでも良いが
軽でも自転車でもよい
292010年11月7日日曜日
47. ■ Ramaze インストール Ruby1.9.2 環境
> gem i ramaze
===============================================
Thank you for installing Ramaze!
To create a new project:
$ ramaze create yourproject
===============================================
Successfully installed ramaze-2010.06.18
1 gem installed
Installing ri documentation for ramaze-2010.06.18...
Installing RDoc documentation for ramaze-2010.06.18...
innateが一緒にインストールされなかったら innateも
> gem i innate
472010年11月7日日曜日
48. require 'ramaze'
class MainController < Ramaze::Controller
def index
"Hello, Ramaze!"
end
end
Ramaze.start
はじめの一歩 Hello Ramaze!
このソースhello.rbをRubyで実行し http://localhost:7000/ でアクセス
482010年11月7日日曜日
50. require 'ramaze'
class MainController < Ramaze::Controller
map ‘/another‘
def hello
"Hello from Another"
end
end
Ramaze.start
ルーティング another Hello !
このhello2.rbをRubyで実行し http://localhost:7000/another/hello でアクセス
502010年11月7日日曜日
53. Ramazeの雛形作成 mkdir controller
mkdir layout
mkdir model
mkdir public
mkdir public/css
mkdir public/js
mkdir spec
mkdir view
create app.rb
create config.ru
create controller/init.rb
create controller/main.rb
create layout/default.xhtml
create model/init.rb
create public/.htaccess
create public/css/screen.css
create public/dispatch.fcgi
create public/favicon.ico
create public/js/jquery.js
create public/ramaze.png
create spec/main.rb
create start.rb
create view/index.xhtml
右のような
ディレクトリ
ファイル
が生成される
controller
model
view
など
Railsに慣れていると
見慣れた感じで安心
できます
532010年11月7日日曜日
54. Ramazeのコントローラ雛形編集
class Controller < Ramaze::Controller
layout :default
helper :xhtml
engine :Etanni
end
class Controller < Ramaze::Controller
layout :default
helper :user
engine :Haml
end
コントロラーのengine: 利用したいものを指定
542010年11月7日日曜日
55. Ramazeのモデル雛形編集
DataMapper.setup(:default, "sqlite3://#{__DIR__('words.db')}")
class Word include DataMapper::Resource
property :id, Serial
property :name, String
property :description, Text
validates_is_unique :name
end
DataMapper.auto_upgrade!
require 'activerecord'
ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:database => 'app',
:username => 'postgres',
:password => 'xxxxx',
:encoding => 'unicode'
)
DataMapperの例
ActiveRecordの例
552010年11月7日日曜日
57. Haml/Sass
<div id='content'>
<div class='left column'>
<h2>Welcome to our site!</h2>
<p><%= print_information %></p>
</div>
<div class="right column">
<%= render :partial => "sidebar" %>
</div>
</div>
#content
.left.column
%h2 Welcome to our site!
%p= print_information
.right.column
= render :partial => "sidebar"
erb
Haml
これをHamlで表記すると簡潔になる
572010年11月7日日曜日
61. Haml/Sass
• インデントを利用するため見た目が簡潔になる。
• { }が不要。代わりに半角スペース2文字のインデ
ントを用いる。
• ;(セミコロン)が不要。
• オリジナルsassソースからCSSを生成するのに
saas 活用ツール saag が便利
• gem install sugamasao-saag --source http://gems.githu
612010年11月7日日曜日
65. iPhone縦向きスクリーン幅は320ピクセル固定
(これより大きいと自動縮小されるVewportのデ
フォルト幅は980ピクセル )
!!! XML
!!!
%html{ html_attrs("ja") }
%head
%meta{:"http-equiv"=>"Content-Type", :content=>"text/html", :charset=>"utf-8"}
%meta{:name=>"viewport", :content=>"width=device-width", :charset=>"utf-8"}
- if /MSIE/ =~ request.env['HTTP_USER_AGENT']
%link{:href=>"/css/maitore_ie.css", :rel => "stylesheet", :type => "text/css"}
- elsif /iPhone/ =~ request.env['HTTP_USER_AGENT']
%script{:type => "text/javascript", :src => "/js/maitore.js"}
%link{:media=>"only screen and (max-device-width: 480px)",:href=>"/css/
maitore_iphone.css", :rel => "stylesheet", :type => "text/css"}
- else
%link{:media=>"screen and (min-device-width: 481px)",:href=>"/css/
maitore_pc.css", :rel => "stylesheet", :type => "text/css"}
iPhone用metaタグ設定他
652010年11月7日日曜日
66. !!! XML
!!!
%html{ html_attrs("ja") }
%head
%meta{:"http-equiv"=>"Content-Type", :content=>"text/
html", :charset=>"utf-8"}
%meta{:name=>"viewport", :content=>"width=device-
width", :charset=>"utf-8"}
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang='ja' xml:lang='ja' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta charset='utf-8' content='text/html' http-equiv='Content-
Type' />
<meta charset='utf-8' content='width=device-width'
name='viewport' />
.hamlを.xhtmlに展開
662010年11月7日日曜日
69. HTML5
HTML5 における HTML4 からの変更点
http://standards.mitsue.co.jp/resources/w3c/TR/html5-diff/
デザイナーのためのHTML5リソースまとめ
http://www.designwalker.com/2009/11/html5.html
692010年11月7日日曜日