mamemose 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -10
- data/bin/mamemose +28 -1
- data/lib/mamemose/version.rb +1 -1
- data/lib/mamemose.rb +39 -15
- data/mamemose.gemspec +1 -0
- metadata +19 -3
data/README.md
CHANGED
@@ -9,19 +9,25 @@ mamemose: Markdown memo server
|
|
9
9
|
- Markdown など軽量マークアップ言語で書かれたドキュメントを
|
10
10
|
コマンド操作無しで勝手に HTML に変換してくれる
|
11
11
|
- Sphinx などをそのまま使うのはコマンドを打つ手間があるので嫌だった
|
12
|
+
- ローカルに余計なファイルができてほしくない
|
13
|
+
- Markdown から静的な HTML ファイルを生成するのは嬉しくない。
|
14
|
+
邪魔なファイルが増えるし、変換が自動化されていたとしても
|
15
|
+
何かの拍子に Markdown ファイルと HTML ファイルの同期が取れなくなりそうな気もする。
|
12
16
|
- 複数マシンで内容を共有できる (Dropbox 等を使ってもよい)
|
17
|
+
- マルチプラットフォーム (少なくとも Mac, Linux は必須)
|
13
18
|
- 使い慣れたエディタを使える
|
14
19
|
- 検索できる
|
15
|
-
-
|
16
|
-
-
|
20
|
+
- GitHub Flavored Markdown でシンタックスハイライトもしてほしい
|
21
|
+
- LaTeX で数式も書きたい
|
17
22
|
|
18
23
|
環境
|
19
24
|
----
|
20
25
|
|
26
|
+
- Ruby 製
|
21
27
|
- おもに Mac OS X 10.8 上の Ruby 1.9.3 でテスト
|
22
28
|
- Ruby 1.8.7 でも動くようにした
|
23
|
-
- Linux
|
24
|
-
- Windows
|
29
|
+
- Linux は大丈夫
|
30
|
+
- Windows も Cygwin 上でなら動くことは確認した
|
25
31
|
|
26
32
|
インストール方法
|
27
33
|
----
|
@@ -39,13 +45,15 @@ $ gem install mamemose
|
|
39
45
|
使い方
|
40
46
|
----
|
41
47
|
|
42
|
-
設定ファイル (後述)
|
48
|
+
設定ファイル (後述) を書いたら以下で起動。
|
49
|
+
もしかしたら `~/.gem/*/bin` とか `/Library/Ruby/Gems/1.8/*/bin` あたりに
|
50
|
+
パスを通す必要があるかも。
|
43
51
|
|
44
52
|
```bash
|
45
53
|
$ mamemose &> /dev/null &
|
46
54
|
```
|
47
55
|
|
48
|
-
|
56
|
+
するとローカルで HTTP サーバが立ち上がります。その後ブラウザから
|
49
57
|
|
50
58
|
```
|
51
59
|
http://localhost:PORT/
|
@@ -54,12 +62,28 @@ http://localhost:PORT/
|
|
54
62
|
にアクセスすればおk
|
55
63
|
|
56
64
|
`DOCUMENT_ROOT` 以下の Markdown で書かれたテキストを勝手にHTMLに変換して表示します。
|
57
|
-
一覧ページでは Markdown ドキュメントの1行目をタイトルとして読み込みます。
|
58
|
-
|
59
65
|
`DOCUMENT_ROOT` を Dropbox 以下のディレクトリに指定しておけば、どのマシンからでも
|
60
66
|
メモにアクセスできるようになります。
|
61
67
|
|
62
|
-
|
68
|
+
- 一覧ページでは Markdown ドキュメントの1行目をタイトルとして読み込みます。
|
69
|
+
- 文字コードは UTF-8 で書くようにしてください。
|
70
|
+
- コマンドラインオプションは `mamemose help` で出ます。一応。
|
71
|
+
|
72
|
+
### 一時ファイル閲覧
|
73
|
+
|
74
|
+
一時的に `DOCUMENT_ROOT` で指定したディレクトリ以外にあるファイルを
|
75
|
+
ブラウザで Markdown プレビューする機能があります。
|
76
|
+
|
77
|
+
```bash
|
78
|
+
$ mamemose s /path/to/file 8000
|
79
|
+
```
|
80
|
+
|
81
|
+
などとして `localhost:8000` にアクセスすると、
|
82
|
+
`/path/to/file` を Mamemose サーバでレンダリングした HTML をブラウザから
|
83
|
+
見ることができます。
|
84
|
+
これによって GitHub などに置く Markdown ファイルを push する前に
|
85
|
+
試しにブラウザから見ることができ、
|
86
|
+
レンダリングの崩れなどがないかチェックできます。
|
63
87
|
|
64
88
|
### シンタックスハイライト
|
65
89
|
|
@@ -245,5 +269,12 @@ Jim | 47
|
|
245
269
|
Harry | 32
|
246
270
|
```
|
247
271
|
|
248
|
-
-
|
272
|
+
- 定義リスト、 definition list, dl を書きたいんだけど
|
249
273
|
- 無理らしいです。 HTML 直接書いてください。
|
274
|
+
|
275
|
+
その他
|
276
|
+
----
|
277
|
+
|
278
|
+
ブログ的なエントリ
|
279
|
+
|
280
|
+
- <http://daimatz.hateblo.jp/entry/2012/12/01/152725>
|
data/bin/mamemose
CHANGED
@@ -4,4 +4,31 @@ $:.unshift File.expand_path("../../lib", __FILE__)
|
|
4
4
|
|
5
5
|
load 'mamemose.rb'
|
6
6
|
|
7
|
-
|
7
|
+
require 'rubygems'
|
8
|
+
require 'thor'
|
9
|
+
|
10
|
+
class Mamemose::CLI < Thor
|
11
|
+
desc "server", "run the mamemose server"
|
12
|
+
desc "server filename port", "run the mamemose server for specified file"
|
13
|
+
def server(filename=nil, port=nil)
|
14
|
+
mamemose = Mamemose::Server.new(port)
|
15
|
+
if !filename && !port
|
16
|
+
mamemose.start
|
17
|
+
elsif filename && port
|
18
|
+
mamemose.file(filename)
|
19
|
+
else
|
20
|
+
puts "please specify filename and port"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "s", "alias of server"
|
25
|
+
alias :s :server
|
26
|
+
|
27
|
+
desc "version", "print version"
|
28
|
+
def version
|
29
|
+
puts Mamemose::VERSION
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
args = ARGV == [] ? ["s"] : ARGV
|
34
|
+
Mamemose::CLI.start(args)
|
data/lib/mamemose/version.rb
CHANGED
data/lib/mamemose.rb
CHANGED
@@ -35,8 +35,13 @@ class HTMLwithSyntaxHighlighter < Redcarpet::Render::XHTML
|
|
35
35
|
end
|
36
36
|
|
37
37
|
class Mamemose::Server
|
38
|
-
def initialize
|
39
|
-
@server = WEBrick::HTTPServer.new({ :Port => PORT })
|
38
|
+
def initialize(port)
|
39
|
+
@server = WEBrick::HTTPServer.new({ :Port => port ? port.to_i : PORT })
|
40
|
+
trap(:INT){@server.shutdown}
|
41
|
+
trap(:TERM){@server.shutdown}
|
42
|
+
end
|
43
|
+
|
44
|
+
def start
|
40
45
|
@server.mount_proc('/') do |req, res|
|
41
46
|
res['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
42
47
|
res['Pragma'] = 'no-cache'
|
@@ -47,23 +52,30 @@ class Mamemose::Server
|
|
47
52
|
elsif File.directory?(fullpath(req.path)) then
|
48
53
|
res = req_index(req, res)
|
49
54
|
elsif File.exists?(fullpath(req.path))
|
50
|
-
res = req_file(req, res)
|
55
|
+
res = req_file(fullpath(req.path), res, false)
|
51
56
|
else
|
52
57
|
res.status = WEBrick::HTTPStatus::RC_NOT_FOUND
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
|
-
|
57
|
-
trap(:TERM){@server.shutdown}
|
61
|
+
@server.start
|
58
62
|
end
|
59
63
|
|
60
|
-
def
|
64
|
+
def file(filename)
|
65
|
+
@server.mount_proc('/') do |req, res|
|
66
|
+
res['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
67
|
+
res['Pragma'] = 'no-cache'
|
68
|
+
res['Expires'] = '0'
|
69
|
+
res = req_file(File.absolute_path(filename), res, true)
|
70
|
+
res.content_type = CONTENT_TYPE
|
71
|
+
end
|
72
|
+
|
61
73
|
@server.start
|
62
74
|
end
|
63
75
|
|
64
76
|
private
|
65
77
|
|
66
|
-
def header_html(title, path
|
78
|
+
def header_html(title, path)
|
67
79
|
html = <<HTML
|
68
80
|
<!DOCTYPE HTML>
|
69
81
|
<html>
|
@@ -214,6 +226,10 @@ function copy(text) {
|
|
214
226
|
<body>
|
215
227
|
#{CUSTOM_BODY}
|
216
228
|
HTML
|
229
|
+
return html
|
230
|
+
end
|
231
|
+
|
232
|
+
def search_form(path, q="")
|
217
233
|
link_str = ""
|
218
234
|
uri = ""
|
219
235
|
path.split('/').each do |s|
|
@@ -231,7 +247,7 @@ HTML
|
|
231
247
|
<input type="submit" value="search" />
|
232
248
|
</form>
|
233
249
|
HTML
|
234
|
-
return
|
250
|
+
return "<div id=\"header\">#{link_str}#{search_form}</div>"
|
235
251
|
end
|
236
252
|
|
237
253
|
def footer_html(filepath=nil)
|
@@ -272,7 +288,10 @@ HTML
|
|
272
288
|
value.each {|v| body += link_list(v[0], v[1])}
|
273
289
|
end
|
274
290
|
|
275
|
-
res.body = header_html(title, uri(path)
|
291
|
+
res.body = header_html(title, uri(path))\
|
292
|
+
+ search_form(uri(path), q)\
|
293
|
+
+ markdown(body)\
|
294
|
+
+ footer_html
|
276
295
|
res.content_type = CONTENT_TYPE
|
277
296
|
return res
|
278
297
|
end
|
@@ -302,22 +321,27 @@ HTML
|
|
302
321
|
body += File.read(index)
|
303
322
|
end
|
304
323
|
|
305
|
-
res.body = header_html(title, req.path)
|
324
|
+
res.body = header_html(title, req.path)\
|
325
|
+
+ search_form(uri(req.path))\
|
326
|
+
+ markdown(body)\
|
327
|
+
+ footer_html(index)
|
306
328
|
res.content_type = CONTENT_TYPE
|
307
329
|
return res
|
308
330
|
end
|
309
331
|
|
310
|
-
def req_file(
|
311
|
-
filename = fullpath(req.path)
|
332
|
+
def req_file(filename, res, fileonly)
|
312
333
|
open(filename) do |file|
|
313
|
-
if markdown?(
|
334
|
+
if markdown?(filename)
|
314
335
|
str = file.read
|
315
336
|
title = get_title(filename, str)
|
316
|
-
|
337
|
+
body = header_html(title, filename)
|
338
|
+
body += search_form(uri(filename)) if !fileonly
|
339
|
+
body += markdown(str) + footer_html(filename)
|
340
|
+
res.body = body
|
317
341
|
res.content_type = CONTENT_TYPE
|
318
342
|
else
|
319
343
|
res.body = file.read
|
320
|
-
res.content_type = WEBrick::HTTPUtils.mime_type(
|
344
|
+
res.content_type = WEBrick::HTTPUtils.mime_type(filename, WEBrick::HTTPUtils::DefaultMimeTypes)
|
321
345
|
res.content_length = File.stat(filename).size
|
322
346
|
end
|
323
347
|
end
|
data/mamemose.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mamemose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redcarpet
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 4.3.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: thor
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: Markdown memo server
|
47
63
|
email:
|
48
64
|
- dai@daimatz.net
|
@@ -82,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
98
|
version: '0'
|
83
99
|
requirements: []
|
84
100
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.8.
|
101
|
+
rubygems_version: 1.8.23
|
86
102
|
signing_key:
|
87
103
|
specification_version: 3
|
88
104
|
summary: Markdown memo server
|