はてなキーワード: h1とは
今時font color=""はなぁと思って書いてみたら妙に長くなってしまった。我ながらなんという資源の無駄。日付を手打ちしてるなら、むしろ日付全体を生成するほうが全然楽だけど、一応この形で足掻いてみた結果。コメント入れまくってるから省けば多少は見やすくなるかもよ。
なお文書内のh1は全て同一フォーマットの日付であることが前提。形式は多少変わってもOKで、右から何文字目が曜日かって部分だけを書き換えれば動くはず。
<html> <head> <title>曜日テスト</title> <style type="text/css"><!-- span.sun{ /* 日曜日 */ color: red; } span.sat{ /* 土曜日 */ color: blue; } --></style> <script type="text/javascript"><!-- // 日付フォーマット中、右から何文字目が曜日か(曜日1文字の場合にしか対応してない) var DAY_POSITION_FROM_RIGHT = 2; /* * <h1>yyyy年mm月dd日(曜)</h1> を * <h1>yyyy年mm月dd日<span class="xxx">(曜)</span></h1> に変換する。 * onloadで実行して塗り替え。 */ function colorDay(){ var targetList = document.getElementsByTagName("h1"); // h1要素のリストを取る for(i=0; i<targetList.length; i++){ // h1の数だけぶん回す // h1の中身を三枚に下ろす(左側、曜日部分、右側) var nodeValue = targetList[i].firstChild.nodeValue; // h1の子であるテキストノードの値(日付)を取る var nodeValueLeft = nodeValue.substring(0,nodeValue.length - DAY_POSITION_FROM_RIGHT); // 左側 var day = nodeValue.charAt(nodeValue.length - DAY_POSITION_FROM_RIGHT); // 曜日 var nodeValueRight = nodeValue.substring(nodeValue.length - DAY_POSITION_FROM_RIGHT + 1, nodeValue.length); // 右側 var dayType = ""; // 曜日に付与するクラス名を算出(平日なら空) if(day == "日"){ dayType = "sun"; } else if(day == "土"){ dayType = "sat"; } var dayObj = document.createElement("span"); // 曜日を入れるspanノードを生成 dayObj.appendChild(document.createTextNode(day)); // 中身文字列は三枚の真ん中(曜日) dayObj.className = dayType; // クラスを付与 // h1の中身作り直し targetList[i].firstChild.nodeValue = nodeValueLeft; // 元々の値を三枚の左側部分のみにする targetList[i].appendChild(dayObj); // その後ろに作った曜日のspanを足す targetList[i].appendChild(document.createTextNode(nodeValueRight)); // その後ろに三枚の右側を足す } } //--></script> </head> <body onload="colorDay();"> <h1>2007年05月25日(金)</h1> <h1>2007年05月26日(土)</h1> <h1>2007年05月27日(日)</h1> <h1>2007年05月28日(月)</h1> </body> </html>
http://anond.hatelabo.jp/20070522023230
<html> <head> <title>Test</title> <script> dayString = new Array('<font color="#ff0000">日</font>','月','火','水','木','金','<font color="#0000ff">土</font>'); function init() { h1s = document.getElementsByTagName("h1"); for(var i=0; i < h1s.length; i++) { var h1 = h1s[i]; if (h1.innerHTML.match(/([0-9]+)年([0-9]+)月([0-9]+)日/)) { var yy = RegExp.$1; var mm = RegExp.$2; var dd = RegExp.$3; var day = new Date(yy,mm-1,dd).getDay(); h1.innerHTML = yy+"年"+mm+"月"+dd+"日("+dayString[day]+")"; } } } </script> </head> <body onload="init()"> <h1>2007年05月10日</h1> <h1>2007年05月18日</h1> <h1>2007年05月19日</h1> <h1>2007年05月20日</h1> </body>
素人なのでよくわからないぜ。
追記: バグっていたので直しました。ごめん。 > http://anond.hatelabo.jp/20070522034339
rubyとは - はてなダイアリー Rubyとは - はてなダイアリー
RubyForge: One-Click Ruby Installer: Project Info
RDE(Ruby Development Environment) - Ruby??J??????????
#!/usr/bin/ruby -Ks
# print "Content-Type: text/html;charset=UTF-8\n\n"
p "表示"
http://127.0.0.1:3000/ http://127.0.0.1:3000/recipe/list
http://127.0.0.1:3001/ http://127.0.0.1:3001/recipe/list
http://127.0.0.1:3001/account/signup http://127.0.0.1:3001/test
Hot Chips (delete) Snacks 2004-11-11
Ice Water (delete) Beverages 2004-11-11
Killer Mushrooms (delete) Snacks 2005-09-13
満足せる豚。眠たげなポチ。:Rolling with Ruby on Rails - Japanese Translation - p1
満足せる豚。眠たげなポチ。:Rolling on Ruby on Rails - Japanese Translation - p5
ITmedia エンタープライズ:第1回 Instant Railsで始めるWindows環境のRails (1/2)
DROP TABLE IF EXISTS `items`;
CREATE TABLE items (
id int(11) NOT NULL auto_increment,
login varchar(80) default NULL,
password varchar(40) default NULL,
);
えぇてるのぉと:Railsでログイン認証 - livedoor Blog(ブログ)
8 app/views/test/index.rhtmlの編集
Welcom <%= @session['user'].login %>!
Login Generator (1) - Nowhere Near
config/environment.rb に以下の行を追加する。
module LoginEngine
config :salt, "your-salt-here"
end
Engines.start :login
パパブログ: RoR : login_generator : login中のユーザ情報の取得
@session['user'].login
で、idやloginが取得できる。
ちなみにidはActiveRecordおなじみのidで、
;C:\nonidata\InstantRails\ruby\bin;
cd C:\nonidata\InstantRails\ruby\bin
C:\nonidata\InstantRails\ruby\bin>gem install login_generator
Successfully installed login_generator-1.2.2
C:\nonidata\InstantRails>cd C:\nonidata\InstantRails\rails_apps\cookbook
C:\nonidata\InstantRails\rails_apps\cookbook>ruby script/generate login Account
create lib/login_system.rb
C:\nonidata\InstantRails\rails_apps>cd C:\nonidata\InstantRails\rails_apps\cookbook
C:\nonidata\InstantRails\rails_apps\cookbook>ruby script/generate controller test
exists app/controllers/
[Ruby] Rails(ActiveRecord)の多対多関連 - yuum3のお仕事日記
has_one
has_many
belongs_to
has_and_belongs_to_many
habtm と has_many :through (ActiveRecord)
ActiveRecord の歩き方 - Association 編(1) - Rails で行こう! - Ruby on Rails を学ぶ has_many :comments
developerWorks Japan has_one :address
Rubyist Magazine - RubyOnRails を使ってみる 【第 3 回】 ActiveRecord
create メソッドを使うこともできます。create は new したあと save (DB に格納) します。
Rubyist Magazine - RubyOnRails を使ってみる 【第 4 回】 ActionPack
find(:all, :conditions => ["user_name = ?", user_name])
find_all(["user_name = ?", user_name])
find_all_by_user_name(user_name)
Part2 Rubyに学ぶ「Ruby on Railsの正体」:ITpro
book = Product.find_or_create_by_name_and_price('book', 2079)
リスト7●productsテーブルからnameが'book',priceが2079であるようなProductオブジェクトを読み取り,存在しなかった場合はデータベースにレコードを新規作成する処理
RoR Wiki 翻訳 Wiki - HowToUseLegacySchemas
恣意的で複雑なクエリや、主キーを持たないテーブルにはfind_by_sqlを使う
テーブルが論理的な主キーを持たないなら、
find_by_sqlを使えば主キーを全く指定しない曖昧で複雑なクエリを実行も実行できる。
Post.find_by_sql ["SELECT * FROM posts WHERE author = ? AND created > ?", author_id, start_date]
エディタ utf8
チュートリアルを動かしてみる - 肩書「シニアコンサルタント」のつぶやき
Railsでソーシャルブックマークを作ってみようか(第1回) - 坊やがゆく
ようこそ<%= @session['user'].login %>さん
Railsでソーシャルブックマークを作ってみようか(第2回) - 坊やがゆく
Railsでお馴染み37signalsのURLが凄い件について:TKMR.blog.show
URLにキーワードを含めことでSEO対策になるかも、でもそれだけ:TKMR.blog.show
http://127.0.0.1:3001/recipe/list
tetraの外部記憶箱 - Instant Railsのインストール , 追記:phpMyAdminの日本語環境設定 , 未踏ソフト記事