Skip to content

Instantly share code, notes, and snippets.

@KeenS
Created January 5, 2019 09:54
Show Gist options
  • Save KeenS/c95556921ba82684f80b71e79ec4d216 to your computer and use it in GitHub Desktop.
Save KeenS/c95556921ba82684f80b71e79ec4d216 to your computer and use it in GitHub Desktop.
# coding: utf-8
var = [
{ "id": "hello", "title": "Hello World", "children": [
{ "id": "comment", "title": "コメント", "children": nil },
{ "id": "print", "title": "フォーマットしてプリント", "children": [
{ "id": "print_debug", "title": "デバッグ", "children": nil },
{ "id": "print_display", "title": "ディスプレイ", "children": [
{ "id": "testcase_list", "title": "テストケース: リスト", "children": nil }
] },
{ "id": "fmt", "title": "フォーマット", "children": nil }
] }
] },
{ "id": "primitives", "title": "基本データ型", "children": [
{ "id": "literals", "title": "リテラルとオペレータ", "children": nil },
{ "id": "tuples", "title": "タプル", "children": nil },
{ "id": "array", "title": "配列とスライス", "children": nil }
] },
{ "id": "custom_types", "title": "カスタム型", "children": [
{ "id": "structs", "title": "構造体", "children": nil },
{ "id": "enum", "title": "列挙型", "children": [
{ "id": "enum_use", "title": "use", "children": nil },
{ "id": "c_like", "title": "C言語ライクな列挙型", "children": nil },
{ "id": "testcase_linked_list", "title": "テストケース: 連結リスト", "children": nil }
] },
{ "id": "constants", "title": "定数", "children": nil }
] },
{ "id": "variable_bindings", "title": "変数バインディング", "children": [
{ "id": "mut", "title": "ミュータビリティ", "children": nil },
{ "id": "scope", "title": "スコープとシャドーイング", "children": nil },
{ "id": "declare", "title": "宣言", "children": nil }
] },
{ "id": "cast", "title": "型キャスティング", "children": [
{ "id": "literals", "title": "リテラル", "children": nil },
{ "id": "inference", "title": "型推論", "children": nil },
{ "id": "alias", "title": "エイリアス", "children": nil }
] },
{ "id": "expression", "title": "式文", "children": nil },
{ "id": "flow_control", "title": "条件分岐", "children": [
{ "id": "if_else", "title": "if/else", "children": nil },
{ "id": "loop", "title": "loop", "children": [
{ "id": "nested", "title": "ネストとラベル", "children": nil }
] },
{ "id": "while", "title": "while", "children": nil },
{ "id": "for", "title": "for と range", "children": nil },
{ "id": "match", "title": "match", "children": [
{ "id": "destructuring", "title": "デストラクト", "children": [
{ "id": "destructure_tuple", "title": "タプル", "children": nil },
{ "id": "destructure_enum", "title": "列挙型", "children": nil },
{ "id": "destructure_pointers", "title": "ポインタとref", "children": nil },
{ "id": "destructure_structures", "title": "構造体", "children": nil }
] },
{ "id": "guard", "title": "ガード", "children": nil },
{ "id": "binding", "title": "バインディング", "children": nil }
] },
{ "id": "if_let", "title": "if let", "children": nil },
{ "id": "while_let", "title": "while let", "children": nil }
] },
{ "id": "fn", "title": "関数", "children": [
{ "id": "methods", "title": "メソッド", "children": nil },
{ "id": "closures", "title": "クロージャ", "children": [
{ "id": "capture", "title": "要素の捕捉", "children": nil },
{ "id": "input_parameters", "title": "捕捉時の型推論", "children": nil },
{ "id": "anonymity", "title": "クロージャを受け取る関数", "children": nil },
{ "id": "input_functions", "title": "関数を受け取る関数", "children": nil },
{ "id": "output_parameters", "title": "クロージャを返す関数", "children": nil },
{ "id": "closure_examples", "title": "`std`における使用例", "children": [
{ "id": "iter_any", "title": "Iterator::any", "children": nil },
{ "id": "iter_find", "title": "Iterator::find", "children": nil }
] }
] },
{ "id": "hof", "title": "高階関数", "children": nil }
] },
{ "id": "macros", "title": "macro_rules!", "children": [
{ "id": "designators", "title": "識別子", "children": nil },
{ "id": "overload", "title": "オーバーロード", "children": nil },
{ "id": "repeat", "title": "リピート", "children": nil },
{ "id": "dry", "title": "DRY (Don't Repeat Yourself)", "children": nil }
] },
{ "id": "mod", "title": "モジュール", "children": [
{ "id": "visibility", "title": "プライベートとパブリック", "children": nil },
{ "id": "struct_visibility", "title": "構造体の場合", "children": nil },
{ "id": "use", "title": "`use`宣言", "children": nil },
{ "id": "super", "title": "`super` と `self`", "children": nil },
{ "id": "split", "title": "ファイルの階層構造", "children": nil }
] },
{ "id": "crates", "title": "クレイト", "children": [
{ "id": "lib", "title": "ライブラリ", "children": nil },
{ "id": "link", "title": "`extern crate`", "children": nil }
] },
{ "id": "attribute", "title": "アトリビュート", "children": [
{ "id": "unused", "title": "`dead_code`", "children": nil },
{ "id": "crate", "title": "クレイト", "children": nil },
{ "id": "cfg", "title": "`cfg`", "children": [
{ "id": "custom", "title": "条件の追加", "children": nil }
] }
] },
{ "id": "generics", "title": "ジェネリクス", "children": [
{ "id": "gen_fn", "title": "関数", "children": nil },
{ "id": "impl", "title": "メソッド", "children": nil },
{ "id": "gen_trait", "title": "ジェネリックトレイト", "children": nil },
{ "id": "bounds", "title": "ジェネリック境界", "children": [
{ "id": "testcase_empty", "title": "テストケース: 空トレイト", "children": nil }
] },
{ "id": "multi_bounds", "title": "複数のジェネリック境界", "children": nil },
{ "id": "where", "title": "Where句", "children": nil },
{ "id": "assoc_items", "title": "関連型", "children": [
{ "id": "the_problem", "title": "関連型が必要になる状況", "children": nil },
{ "id": "types", "title": "関連型", "children": nil }
] },
{ "id": "phantom", "title": "幽霊型パラメータ", "children": [
{ "id": "testcase_units", "title": "テストケース: 単位を扱う", "children": nil }
] }
] },
{ "id": "scope", "title": "スコーピングの規則", "children": [
{ "id": "raii", "title": "RAII", "children": nil },
{ "id": "move", "title": "所有権とムーブ", "children": [
{ "id": "mut", "title": "ミュータビリティ", "children": nil }
] },
{ "id": "borrow", "title": "借用", "children": [
{ "id": "mut", "title": "ミュータビリティ", "children": nil },
{ "id": "freeze", "title": "値のフリーズ", "children": nil },
{ "id": "alias", "title": "エイリアス", "children": nil },
{ "id": "ref", "title": "refパターン", "children": nil }
] },
{ "id": "lifetime", "title": "ライフタイム", "children": [
{ "id": "explicit", "title": "明示的アノテーション", "children": nil },
{ "id": "fn", "title": "関数", "children": nil },
{ "id": "methods", "title": "メソッド", "children": nil },
{ "id": "struct", "title": "構造体", "children": nil },
{ "id": "lifetime_bounds", "title": "ライフタイム境界", "children": nil },
{ "id": "lifetime_coercion", "title": "圧縮", "children": nil },
{ "id": "static_lifetime", "title": "スタティックライフタイム", "children": nil },
{ "id": "elision", "title": "省略", "children": nil }
] }
] },
{ "id": "trait", "title": "トレイト", "children": [
{ "id": "derive", "title": "継承(Derive)", "children": nil },
{ "id": "ops", "title": "演算子のオーバーロード", "children": nil },
{ "id": "drop", "title": "メモリ解放", "children": nil },
{ "id": "iter", "title": "イテレータ", "children": nil },
{ "id": "clone", "title": "クローン", "children": nil }
] },
{ "id": "error", "title": "エラーハンドリング", "children": [
{ "id": "unwrap", "title": "Optionとunwrap", "children": nil },
{ "id": "map", "title": "map", "children": nil },
{ "id": "and_then", "title": "and_then", "children": nil },
{ "id": "result", "title": "Result", "children": nil },
{ "id": "result_map", "title": "Resultにmapする", "children": nil },
{ "id": "result_alias", "title": "Resultのエイリアス", "children": nil },
{ "id": "option_with_result", "title": "OptionとResultを同時に扱う", "children": [
{ "id": "result_string_errors", "title": "Stringをエラーとして扱う", "children": nil },
{ "id": "combinator_combinations", "title": "コンビネータを組み合わせる", "children": nil },
{ "id": "enter_try", "title": "try!入門", "children": nil }
] },
{ "id": "limits_of_strings", "title": "stringの限界","children": nil },
{ "id": "reenter_try", "title": "try!再入門", "children": nil },
{ "id": "reenabling_box", "title": "box化を再度可能にする", "children": nil }
] },
{ "id": "std", "title": "標準ライブラリの型", "children": [
{ "id": "box", "title": "Box, スタックとヒープ", "children": nil },
{ "id": "vec", "title": "ベクタ型", "children": nil },
{ "id": "str", "title": "文字列", "children": nil },
{ "id": "option", "title": "`Option`", "children": nil },
{ "id": "result", "title": "`Result`", "children": [
{ "id": "try", "title": "`try!`", "children": nil }
] },
{ "id": "panic", "title": "`panic!`", "children": nil },
{ "id": "hash", "title": "ハッシュマップ", "children": [
{ "id": "alt_key_types", "title": "key型の変種", "children": nil},
{ "id": "hashset", "title": "ハッシュ集合", "children": nil }
] }
] },
{ "id": "std_misc", "title": "標準ライブラリのその他", "children": [
{ "id": "threads", "title": "スレッド", "children": nil },
{ "id": "channels", "title": "チャネル", "children": nil },
{ "id": "path", "title": "Path", "children": nil },
{ "id": "file", "title": "ファイル I/O", "children": [
{ "id": "open", "title": "`open`", "children": nil },
{ "id": "create", "title": "`create`", "children": nil }
] },
{ "id": "process", "title": "子プロセス", "children": [
{ "id": "pipe", "title": "パイプ", "children": nil },
{ "id": "wait", "title": "dropの延期", "children": nil }
] },
{ "id": "fs", "title": "ファイルシステムとのやり取り", "children": nil },
{ "id": "arg", "title": "引数処理", "children": [
{ "id": "matching", "title": "引数のパース", "children": nil }
] },
{ "id": "ffi", "title": "他言語関数インターフェイス", "children": nil }
] },
{ "id": "meta", "title": "周辺情報", "children": [
{ "id": "doc", "title": "ドキュメンテーション", "children": nil },
{ "id": "test", "title": "テスト", "children": nil }
] },
{ "id": "unsafe", "title": "安全でない操作", "children": nil }
]
def traverse(input, parents)
for item in input
url = (parents + [item[:id] + ".md"]).join("/")
puts "#{" " * parents.length}- [#{item[:title]}](#{url})"
if item[:children]
traverse(item[:children], parents + [item[:id]])
end
end
end
traverse(var, [])
require 'fileutils'
def walk(start)
Dir.foreach(start) do |x|
path = File.join(start, x)
if x == "." or x == ".."
next
elsif File.directory?(path)
walk(path)
else
if x === "input.md"
puts path
content = File.read(path).gsub(/\{(.*\.(rs|play))\}/) do |match|
file = $1
if file =~ /.rs$/
annot = "rust"
file = file
else
annot = "rust,editable"
file = file.gsub(/.play$/, ".rs")
end
ret = "``` #{annot}\n" +
File.read(start + "/" + file) +
"\n```"
FileUtils.rm(start + "/" + file)
ret
end
File.write(start + ".md", content)
FileUtils.rm(path)
end
end
end
if Dir.empty?(start)
Dir::rmdir(start)
end
end
walk ARGV[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment