wiki2htmlはlivedoor wikiのような記法で書かれた テキストファイルをHTMLに変換するツールです。以下の方針に従って開発しています。
- できるだけ多くのエラーを発見する
- 設定ファイルによる記法の変更可能性
- HTMLが生成されるまでの時間は遅くない
import Control.Monad.Writer | |
gcd' :: Int -> Int -> Writer [String] Int | |
gcd' a b | |
|b == 0 = do | |
tell["= " ++ show a] | |
return(a) | |
|otherwise = do | |
let nb = a `mod` b | |
expr = "gcd(" ++ show(b) ++ ", " ++ show(nb) ++ ")" | |
msg = show(a) ++ " = " ++ show(b) ++ " * " ++ show(a `div` b) ++ " + " ++ show(nb) |
import Control.Monad.Writer | |
size :: [[a]] -> Int | |
size = foldr (\ xs n -> length xs + n) 0 | |
move :: [[Int]] -> (Int, Int) -> Writer [String] [[Int]] | |
move xss (from, to) = return([move_ xs y (from, to) i| (xs, i) <- zip xss [0..]]) | |
where (y:_) = xss !! from | |
move_ :: [Int] -> Int -> (Int, Int) -> Int -> [Int] | |
move_ [] y (from, to) i = if i == to then [y] else [] | |
move_ (x:xs) y (from, to) i |i == from = xs |
import Parsing (parse, line) | |
import System.IO | |
import System.Environment | |
import Data.Char | |
import Data.Map as M | |
import Data.Time.Clock | |
import Control.Monad.State | |
-- http://d.hatena.ne.jp/mzp/20090308/bench | |
bench f = do from <- getCurrentTime |
ldf :: Int -> Int -> Maybe Int | |
ldf k n | k ^ 2 > n = Nothing | |
| rem n k == 0 = Just k | |
| otherwise = ldf (k+1) n | |
prime :: Int -> Bool | |
prime n = case (ldf 2 n) of | |
Just m -> m == n | |
Nothing -> True |
$ sqlite3 test.db | |
SQLite version 3.7.9 2011-11-01 00:52:41 | |
Enter ".help" for instructions | |
Enter SQL statements terminated with a ";" | |
sqlite> create table fruits(name string, value integer); | |
sqlite> insert into fruits values('apple', 100); | |
sqlite> insert into fruits values('orange', 130); | |
sqlite> .q |
commit 917538814d304a01b750db8c84d3fe0e08c9e435 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 09:12:22 2012 +0900 | |
initial commit | |
diff --git a/src/unit.rb b/src/unit.rb | |
new file mode 100644 | |
index 0000000..e69de29 |
wiki2htmlはlivedoor wikiのような記法で書かれた テキストファイルをHTMLに変換するツールです。以下の方針に従って開発しています。
module Concern | |
def self.extended(base) | |
base.instance_variable_set("@dependencies", []) | |
end | |
def append_features(base) | |
if base.instance_variable_defined?("@dependencies") | |
base.instance_variable_get("@dependencies") << self | |
else | |
super | |
@dependencies.each {|dep| base.send(:include, dep)} |
class Class | |
def class_attribute name | |
class_eval <<-RUBY, __FILE__, __LINE__ + 1 | |
def self.#{name}() nil end | |
def self.#{name}=(val) | |
singleton_class.class_eval { | |
undef_method :#{name} | |
define_method(:#{name}) { val } | |
} | |
val |
require 'erb' | |
class ERB | |
def self.call(source) | |
new(source, nil, nil, '@output_buffer').src | |
end | |
end | |
class Template | |
def initialize(source, path) | |
@path = path | |
@source = source |