Skip to content

Instantly share code, notes, and snippets.

@Y-KURI
Created August 9, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Y-KURI/0e40031a85a04e441c3a19bd464926aa to your computer and use it in GitHub Desktop.
Save Y-KURI/0e40031a85a04e441c3a19bd464926aa to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"rake aborted!\n",
"No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)\n",
"\n",
"(See full trace by running task with --trace)\n"
]
},
{
"ename": "",
"evalue": "1",
"execution_count": 10,
"output_type": "error",
"traceback": []
}
],
"source": [
"# Rakefileが無いとあかん言われる。\n",
"rake"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rakefile\n"
]
}
],
"source": [
"ls"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"desc 'Create hello-rake.txt'\n",
"task :samplefile do\n",
" open('hello-rake.txt','w'){|f|f.write('Hello Rake.')\n",
" }\n",
"end"
]
}
],
"source": [
"# 実行するとhello-rakeというテキストファイルをつくってくれるごくシンプルなrakeタスク\n",
"cat Rakefile"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"#rakeの後にタスク名をいれて呼び出す\n",
"rake samplefile"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rakefile\thello-rake.txt\n"
]
}
],
"source": [
"# hello-rake.txtが出来ている\n",
"ls"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello Rake."
]
}
],
"source": [
"# txt中身を確認\n",
"cat hello-rake.txt"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"rake samplefile # Create hello-rake.txt\n"
]
}
],
"source": [
"# タスクとその説明(desc)の一覧表示\n",
"rake -T"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# encoding: utf-8\n",
"\n",
"desc '全HTMLファイルを作成する'\n",
"task :publish => 'index.html'\n",
"\n",
"desc 'トップページのHTMLファイルを作成する'\n",
"file 'index.html' => ['template/index.html', 'template/header_menu.html'] do\n",
" # 元になるHTMLファイルの読み込み\n",
" base_html = File.read('template/index.html', encoding: 'utf-8')\n",
" menu_html = File.read('template/header_menu.html', encoding: 'utf-8')\n",
" \n",
" # トップページHTMLの出力\n",
" open('index.html', 'w'){|f|\n",
" f.write base_html.gsub('{HEADER_MENU_HTML}', menu_html)\n",
" }\n",
"end"
]
}
],
"source": [
"# 複数のファイルからひとつのhtmlファイルを生成するタスク\n",
"# gsubを使って一致する正規表現を置換して新たなhtmlファイルをつくる\n",
"cat Rakefile"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<div id=\"MENU\">\n",
" <ul>\n",
" <li><a href=\"index.html\">トップページ</a></li>\n",
" <li><a href=\"50tour.html\">そば家50店めぐり</a></li>\n",
" <li><a href=\"no-more-weight.html\">太らないための食べ方講座</a></li>\n",
" </ul>\n",
"</div>"
]
}
],
"source": [
"# 元のヘッダーのhtml\n",
"cat template/header_menu.html"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<!DOCTYPE html>\n",
"<html>\n",
"<head>\n",
" <meta charset=\"utf-8\" />\n",
" <title>るびくるのグルメサイト「Rubicle Groumet」</title>\n",
"</head>\n",
"\n",
"<body>\n",
" {HEADER_MENU_HTML}\n",
" <h1>Rubicle Groumet</h1>\n",
" <p>るびくるのグルメサイトです。おいしい食べ物についての情報を紹介していきます。</p>\n",
"</body>\n",
"</html>"
]
}
],
"source": [
"# 元のトップページのテンプレ(ヘッダーに置換するパターンを埋め込む)\n",
"cat template/index.html"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"# taskの実行\n",
"rake publish"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rakefile\thello-rake.txt\tindex.html\ttemplate\n"
]
}
],
"source": [
"# 新たにhtmlファイルが生成され\n",
"ls"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rakefile\thello-rake.txt\tindex.html\ttemplate\n",
"<!DOCTYPE html>\n",
"<html>\n",
"<head>\n",
" <meta charset=\"utf-8\" />\n",
" <title>るびくるのグルメサイト「Rubicle Groumet」</title>\n",
"</head>\n",
"\n",
"<body>\n",
" <div id=\"MENU\">\n",
" <ul>\n",
" <li><a href=\"index.html\">トップページ</a></li>\n",
" <li><a href=\"50tour.html\">そば家50店めぐり</a></li>\n",
" <li><a href=\"no-more-weight.html\">太らないための食べ方講座</a></li>\n",
" </ul>\n",
"</div>\n",
" <h1>Rubicle Groumet</h1>\n",
" <p>るびくるのグルメサイトです。おいしい食べ物についての情報を紹介していきます。</p>\n",
"</body>\n",
"</html>"
]
}
],
"source": [
"# ヘッダー部分が置換されている\n",
"cat index.html"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Rakefileに下記ように記述するとrakeを実行するだけでpublishタスクを呼び出せるようになる\n",
"\n",
"task :default => :publish\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment