gyazz-markup 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +5 -0
- data/README.md +8 -4
- data/bin/gyazz-markup +2 -2
- data/lib/gyazz-markup.rb +1 -0
- data/lib/gyazz-markup/markup.rb +52 -42
- data/lib/gyazz-markup/options.rb +12 -0
- data/lib/gyazz-markup/version.rb +1 -1
- data/samples/sample.rb +15 -0
- data/samples/sample.txt +12 -0
- data/test/test_gyazz-markup.rb +32 -21
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3604dcb701cdcc745821cd93eba990f766af7d9
|
4
|
+
data.tar.gz: adec3550f1f4825773a7acd621ad4a66dcca123e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5cb1dfa1c6f411a440c527d7e48cf6dae3d505ca54ece2be80e607bb9bd027024dcbbaa2ba936507263a31e58813044c8376b3167a76878cd2e8fc529013a60
|
7
|
+
data.tar.gz: 598c0d654f2b642d3c016ba061f0ff4aa6613d26c9aa65518799a83c1af914afc8e96f939d03d75a4ae19634d9b0ad89919e9fa6be3436413a903789d6ea5f20
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -17,15 +17,19 @@ Usage
|
|
17
17
|
```ruby
|
18
18
|
require 'rubygems'
|
19
19
|
require 'gyazz-markup'
|
20
|
-
|
21
|
-
```
|
20
|
+
str = File.open("input.txt").read
|
22
21
|
|
23
|
-
|
22
|
+
gm = GyazzMarkup::Markup.new
|
23
|
+
puts gm.markup str
|
24
|
+
```
|
24
25
|
|
26
|
+
config
|
25
27
|
```ruby
|
26
|
-
|
28
|
+
gm = GyazzMarkup::Markup.new(:host => 'http://gyazz.com', :wiki => 'shokai')
|
29
|
+
puts gm.markup str
|
27
30
|
```
|
28
31
|
|
32
|
+
|
29
33
|
Contributing
|
30
34
|
------------
|
31
35
|
|
data/bin/gyazz-markup
CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
|
|
5
5
|
|
6
6
|
require 'gyazz-markup'
|
7
7
|
|
8
|
-
input,
|
8
|
+
input, wiki = ARGV[0..1]
|
9
9
|
unless input
|
10
10
|
STDERR.puts "== gyazz-markup v#{GyazzMarkup::VERSION}"
|
11
11
|
STDERR.puts
|
@@ -14,4 +14,4 @@ unless input
|
|
14
14
|
exit 1
|
15
15
|
end
|
16
16
|
|
17
|
-
puts GyazzMarkup.markup(open(input).read
|
17
|
+
puts GyazzMarkup::Markup.new(:wiki => wiki).markup(open(input).read)
|
data/lib/gyazz-markup.rb
CHANGED
data/lib/gyazz-markup/markup.rb
CHANGED
@@ -1,53 +1,63 @@
|
|
1
1
|
module GyazzMarkup
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
]
|
13
|
-
|
14
|
-
lines.map do |line|
|
15
|
-
line = self.markup_url_with_image line
|
16
|
-
line = self.markup_image line
|
17
|
-
line = self.markup_strong line
|
18
|
-
line = self.markup_url_with_title line
|
19
|
-
line = self.markup_url line
|
20
|
-
line = self.markup_inner_link(line, base)
|
3
|
+
class Markup
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
@opts = GyazzMarkup::Options.default
|
7
|
+
opts.each do |k,v|
|
8
|
+
next unless @opts.has_key? k
|
9
|
+
next unless v
|
10
|
+
@opts[k] = v
|
11
|
+
end
|
21
12
|
end
|
22
|
-
end
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
14
|
+
def options
|
15
|
+
@opts
|
16
|
+
end
|
28
17
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
def markup(txt)
|
19
|
+
lines = txt.split(/[\r\n]/).delete_if{|line|
|
20
|
+
line.empty?
|
21
|
+
}
|
22
|
+
|
23
|
+
lines.map do |line|
|
24
|
+
line = markup_url_with_image line
|
25
|
+
line = markup_image line
|
26
|
+
line = markup_strong line
|
27
|
+
line = markup_url_with_title line
|
28
|
+
line = markup_url line
|
29
|
+
line = markup_inner_link line
|
30
|
+
end
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def markup_image(str)
|
34
|
+
pat = /\[{2,3}(https?:\/\/[^\s]+)\.(png|jpe?g|gif|bmp)\]{2,3}/
|
35
|
+
str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}.#{$2}\"><img src=\"#{$1}.#{$2}\"></a>")
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
def markup_url(str)
|
39
|
+
pat = /\[{2}(https?:\/\/[^\s]+)\]{2}/
|
40
|
+
str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\">#{$1}</a>")
|
41
|
+
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
def markup_inner_link(str)
|
44
|
+
pat = /\[{2}(.+)\]{2}/
|
45
|
+
str !~ pat ? str : str.gsub(pat, "<a href=\"#{options[:host]}/#{options[:wiki]}/#{$1}\">#{$1}</a>")
|
46
|
+
end
|
47
|
+
|
48
|
+
def markup_strong(str)
|
49
|
+
pat = /\[{3}(.+)\]{3}/
|
50
|
+
str !~ pat ? str : str.gsub(pat, "<strong>#{$1}</strong>")
|
51
|
+
end
|
52
|
+
|
53
|
+
def markup_url_with_title(str)
|
54
|
+
pat = /\[{2}(https?:\/\/[^\s]+)\s(.+)\]{2}/
|
55
|
+
str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\">#{$2}</a>")
|
56
|
+
end
|
48
57
|
|
49
|
-
|
50
|
-
|
51
|
-
|
58
|
+
def markup_url_with_image(str)
|
59
|
+
pat = /\[{2}(https?:\/\/[^\s]+)\s(https?:\/\/[^\s]+)\.(png|jpe?g|gif|bmp)\]{2}/
|
60
|
+
str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\"><img src=\"#{$2}.#{$3}\"></a>")
|
61
|
+
end
|
52
62
|
end
|
53
63
|
end
|
data/lib/gyazz-markup/version.rb
CHANGED
data/samples/sample.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
3
|
+
require 'rubygems'
|
4
|
+
require 'gyazz-markup'
|
5
|
+
|
6
|
+
if ARGV.empty?
|
7
|
+
fname = File.expand_path 'sample.txt', File.dirname(__FILE__)
|
8
|
+
else
|
9
|
+
fname = ARGV.shift
|
10
|
+
end
|
11
|
+
|
12
|
+
str = File.open(fname).read
|
13
|
+
gm = GyazzMarkup::Markup.new :host => 'http://gyazz.com', :wiki => 'test'
|
14
|
+
|
15
|
+
puts gm.markup str
|
data/samples/sample.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
[[[強く表示]]]
|
2
|
+
[[http://gyazo.com/f7b9ad3035e91e7c9d91aaa082ddb7f2.png]] こうすると、画像が入れられます
|
3
|
+
新しいページへのリンクも作れる → [[ごはん]]
|
4
|
+
URLをリンク [[http://shokai.org]]
|
5
|
+
タイトル付きURLリンク → [[htts:/example.com 私のホームページ]]
|
6
|
+
画像つきURLリンク [[https://shokai.org http://gyazo.com/b2c551db20c7ef6ad598b89e66be6517.png]]
|
7
|
+
インデント
|
8
|
+
aaa
|
9
|
+
aaa1
|
10
|
+
aaa2
|
11
|
+
bbb
|
12
|
+
bbb2
|
data/test/test_gyazz-markup.rb
CHANGED
@@ -2,64 +2,75 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
2
|
|
3
3
|
class TestGyazzMarkup < MiniTest::Unit::TestCase
|
4
4
|
|
5
|
+
def setup
|
6
|
+
@gm = GyazzMarkup::Markup.new
|
7
|
+
end
|
8
|
+
|
5
9
|
def test_markup_image
|
6
10
|
img_url = "http://example.com/foo.png"
|
7
|
-
assert
|
11
|
+
assert @gm.markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'png image'
|
8
12
|
img_url = "http://example.com/foo.jpg"
|
9
|
-
assert
|
13
|
+
assert @gm.markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'jpg image'
|
10
14
|
img_url = "http://example.com/foo.jpeg"
|
11
|
-
assert
|
15
|
+
assert @gm.markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'jpeg image'
|
12
16
|
img_url = "http://example.com/foo.bmp"
|
13
|
-
assert
|
17
|
+
assert @gm.markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'bmp image'
|
14
18
|
img_url = "http://example.com/foo.gif"
|
15
|
-
assert
|
19
|
+
assert @gm.markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'gif image'
|
16
20
|
img_url = "http://example.com/foo.baaarrr"
|
17
|
-
assert
|
21
|
+
assert @gm.markup_image("[[#{img_url}]]") != "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'not image'
|
18
22
|
end
|
19
23
|
|
20
24
|
def test_markup_url
|
21
25
|
url = "http://example.com"
|
22
|
-
assert
|
26
|
+
assert @gm.markup_url("[[#{url}]]") == "<a href=\"#{url}\">#{url}</a>", 'http url'
|
23
27
|
url = "https://example.com"
|
24
|
-
assert
|
28
|
+
assert @gm.markup_url("[[#{url}]]") == "<a href=\"#{url}\">#{url}</a>", 'https url'
|
25
29
|
url = "ftp://example.com"
|
26
|
-
assert
|
30
|
+
assert @gm.markup_url("[[#{url}]]") != "<a href=\"#{url}\">#{url}</a>", 'not url'
|
27
31
|
end
|
28
32
|
|
29
33
|
def test_markup_inner_link
|
30
|
-
assert
|
31
|
-
|
34
|
+
assert @gm.markup_inner_link("[[foo bar]]") == "<a href=\"http://gyazz.com/test/foo bar\">foo bar</a>", "inner link without gyazz-name"
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_markup_inner_link_with_opts
|
38
|
+
gm = GyazzMarkup::Markup.new :wiki => 'baz'
|
39
|
+
assert gm.markup_inner_link("[[foo bar]]") == "<a href=\"http://gyazz.com/baz/foo bar\">foo bar</a>", "inner link with gyazz-name"
|
40
|
+
|
41
|
+
gm = GyazzMarkup::Markup.new :host => 'http://mygyazz.com', :wiki => 'shokai'
|
42
|
+
assert gm.markup_inner_link("[[foo bar]]") == "<a href=\"http://mygyazz.com/shokai/foo bar\">foo bar</a>", "inner link with gyazz-name"
|
32
43
|
end
|
33
44
|
|
34
45
|
def test_markup_strong
|
35
|
-
assert
|
36
|
-
assert
|
46
|
+
assert @gm.markup_strong("[[[foo]]]") == "<strong>foo</strong>", "strong"
|
47
|
+
assert @gm.markup_strong("[[[foo bar baz]]]") == "<strong>foo bar baz</strong>", "strong with space"
|
37
48
|
end
|
38
49
|
|
39
50
|
def test_markup_url_with_title
|
40
|
-
assert
|
41
|
-
assert
|
51
|
+
assert @gm.markup_url_with_title("[[http://example.com mypage]]") == "<a href=\"http://example.com\">mypage</a>", "url with title"
|
52
|
+
assert @gm.markup_url_with_title("[[http://example.com my page]]") == "<a href=\"http://example.com\">my page</a>", "space in title"
|
42
53
|
end
|
43
54
|
|
44
55
|
def test_markup_url_with_image
|
45
56
|
img_url = "http://example.com/foo.png"
|
46
57
|
url = "http://example.com"
|
47
|
-
assert
|
58
|
+
assert @gm.markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with png image"
|
48
59
|
img_url = "http://example.com/foo.jpg"
|
49
60
|
url = "http://example.com"
|
50
|
-
assert
|
61
|
+
assert @gm.markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with jpg image"
|
51
62
|
img_url = "http://example.com/foo.jpeg"
|
52
63
|
url = "http://example.com"
|
53
|
-
assert
|
64
|
+
assert @gm.markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with jpeg image"
|
54
65
|
img_url = "http://example.com/foo.gif"
|
55
66
|
url = "http://example.com"
|
56
|
-
assert
|
67
|
+
assert @gm.markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with gif image"
|
57
68
|
img_url = "http://example.com/foo.bmp"
|
58
69
|
url = "http://example.com"
|
59
|
-
assert
|
70
|
+
assert @gm.markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with bmp image"
|
60
71
|
img_url = "http://example.com/foo.baz"
|
61
72
|
url = "http://example.com"
|
62
|
-
assert
|
73
|
+
assert @gm.markup_url_with_image("[[#{url} #{img_url}]]") != "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with not image"
|
63
74
|
end
|
64
75
|
|
65
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gyazz-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
@@ -70,7 +70,10 @@ files:
|
|
70
70
|
- gyazz-markup.gemspec
|
71
71
|
- lib/gyazz-markup.rb
|
72
72
|
- lib/gyazz-markup/markup.rb
|
73
|
+
- lib/gyazz-markup/options.rb
|
73
74
|
- lib/gyazz-markup/version.rb
|
75
|
+
- samples/sample.rb
|
76
|
+
- samples/sample.txt
|
74
77
|
- test/test_gyazz-markup.rb
|
75
78
|
- test/test_helper.rb
|
76
79
|
homepage: https://github.com/shokai/gyazz-markup
|