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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0aff1fc1d5b6df303b1221c09d509fe654b6ae55
4
- data.tar.gz: 80586e91ec5f5d8d34e11ed4b1532ce78a3d5325
3
+ metadata.gz: f3604dcb701cdcc745821cd93eba990f766af7d9
4
+ data.tar.gz: adec3550f1f4825773a7acd621ad4a66dcca123e
5
5
  SHA512:
6
- metadata.gz: a0e88fe9b17696df7a54e8d5b1b8ac8d02d0a31ee20e0edfb8c283e0122d28c5a076b77703978d23739f2e42eb8ee6ebeb827953cd57944bda9b959ffda29ad9
7
- data.tar.gz: 226f84963e9f90b00874f2e50a51a5b6054a606ee982e22521e3f3ce4b53e414daf93fd3d2a364ddc7d61266ba9e97725173037119f1e6a08a9ef8f806accb9b
6
+ metadata.gz: b5cb1dfa1c6f411a440c527d7e48cf6dae3d505ca54ece2be80e607bb9bd027024dcbbaa2ba936507263a31e58813044c8376b3167a76878cd2e8fc529013a60
7
+ data.tar.gz: 598c0d654f2b642d3c016ba061f0ff4aa6613d26c9aa65518799a83c1af914afc8e96f939d03d75a4ae19634d9b0ad89919e9fa6be3436413a903789d6ea5f20
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.0 2013-04-07
2
+
3
+ * add samples
4
+ * create GyazzMarkup::Markup instance
5
+
1
6
  === 0.0.2 2013-04-07
2
7
 
3
8
  * use bundler gem template
data/README.md CHANGED
@@ -17,15 +17,19 @@ Usage
17
17
  ```ruby
18
18
  require 'rubygems'
19
19
  require 'gyazz-markup'
20
- puts GyazzMarkup.markup(open("input.txt").read)
21
- ```
20
+ str = File.open("input.txt").read
22
21
 
23
- or
22
+ gm = GyazzMarkup::Markup.new
23
+ puts gm.markup str
24
+ ```
24
25
 
26
+ config
25
27
  ```ruby
26
- puts GyazzMarkup.markup(open("input.txt").read, "shokai")
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, base = ARGV[0..1]
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, base)
17
+ puts GyazzMarkup::Markup.new(:wiki => wiki).markup(open(input).read)
data/lib/gyazz-markup.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'gyazz-markup/version'
2
+ require 'gyazz-markup/options'
2
3
  require 'gyazz-markup/markup'
3
4
 
4
5
  module GyazzMarkup
@@ -1,53 +1,63 @@
1
1
  module GyazzMarkup
2
2
 
3
- def self.markup(txt, base="test")
4
- lines = txt.split(/[\r\n]/).delete_if{|line|
5
- line.to_s.size < 1
6
- }
7
-
8
- pats = [
9
- [ /\[{2,3}(https?:\/\/.+)\.(png|jpe?g|gif|bmp)\]{2,3}/, "<a href=\"#{$1}.#{$2}\"><img src=\"#{$1}.#{$2}\"></a>"],
10
- [ /\[{2}(https?:\/\/.+)\]{2}/, "<a href=\"#{$1}\">#{$1}</a>"],
11
- [ /\[\[(.+)\]\]/, "<a href=\"http://gyazz.com/#{base}/#{$1}\">#{$1}</a>"]
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
- def self.markup_image(str)
25
- pat = /\[{2,3}(https?:\/\/[^\s]+)\.(png|jpe?g|gif|bmp)\]{2,3}/
26
- str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}.#{$2}\"><img src=\"#{$1}.#{$2}\"></a>")
27
- end
14
+ def options
15
+ @opts
16
+ end
28
17
 
29
- def self.markup_url(str)
30
- pat = /\[{2}(https?:\/\/[^\s]+)\]{2}/
31
- str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\">#{$1}</a>")
32
- end
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
- def self.markup_inner_link(str, base='test')
35
- pat = /\[{2}(.+)\]{2}/
36
- str !~ pat ? str : str.gsub(pat, "<a href=\"http://gyazz.com/#{base}/#{$1}\">#{$1}</a>")
37
- end
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
- def self.markup_strong(str)
40
- pat = /\[{3}(.+)\]{3}/
41
- str !~ pat ? str : str.gsub(pat, "<strong>#{$1}</strong>")
42
- end
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
- def self.markup_url_with_title(str)
45
- pat = /\[{2}(https?:\/\/[^\s]+)\s(.+)\]{2}/
46
- str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\">#{$2}</a>")
47
- end
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
- def self.markup_url_with_image(str)
50
- pat = /\[{2}(https?:\/\/[^\s]+)\s(https?:\/\/[^\s]+)\.(png|jpe?g|gif|bmp)\]{2}/
51
- str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\"><img src=\"#{$2}.#{$3}\"></a>")
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
@@ -0,0 +1,12 @@
1
+ module GyazzMarkup
2
+ class Options
3
+
4
+ def self.default
5
+ {
6
+ :host => 'http://gyazz.com',
7
+ :wiki => 'test'
8
+ }
9
+ end
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module GyazzMarkup
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
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
@@ -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
@@ -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 GyazzMarkup::markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'png image'
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 GyazzMarkup::markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'jpg image'
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 GyazzMarkup::markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'jpeg image'
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 GyazzMarkup::markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'bmp image'
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 GyazzMarkup::markup_image("[[#{img_url}]]") == "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'gif image'
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 GyazzMarkup::markup_image("[[#{img_url}]]") != "<a href=\"#{img_url}\"><img src=\"#{img_url}\"></a>", 'not image'
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 GyazzMarkup::markup_url("[[#{url}]]") == "<a href=\"#{url}\">#{url}</a>", 'http url'
26
+ assert @gm.markup_url("[[#{url}]]") == "<a href=\"#{url}\">#{url}</a>", 'http url'
23
27
  url = "https://example.com"
24
- assert GyazzMarkup::markup_url("[[#{url}]]") == "<a href=\"#{url}\">#{url}</a>", 'https url'
28
+ assert @gm.markup_url("[[#{url}]]") == "<a href=\"#{url}\">#{url}</a>", 'https url'
25
29
  url = "ftp://example.com"
26
- assert GyazzMarkup::markup_url("[[#{url}]]") != "<a href=\"#{url}\">#{url}</a>", 'not url'
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 GyazzMarkup::markup_inner_link("[[foo bar]]") == "<a href=\"http://gyazz.com/test/foo bar\">foo bar</a>", "inner link without gyazz-name"
31
- assert GyazzMarkup::markup_inner_link("[[foo bar]]", "baz") == "<a href=\"http://gyazz.com/baz/foo bar\">foo bar</a>", "inner link with gyazz-name"
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 GyazzMarkup::markup_strong("[[[foo]]]") == "<strong>foo</strong>", "strong"
36
- assert GyazzMarkup::markup_strong("[[[foo bar baz]]]") == "<strong>foo bar baz</strong>", "strong with space"
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 GyazzMarkup::markup_url_with_title("[[http://example.com mypage]]") == "<a href=\"http://example.com\">mypage</a>", "url with title"
41
- assert GyazzMarkup::markup_url_with_title("[[http://example.com my page]]") == "<a href=\"http://example.com\">my page</a>", "space in title"
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 GyazzMarkup::markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with png image"
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 GyazzMarkup::markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with jpg image"
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 GyazzMarkup::markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with jpeg image"
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 GyazzMarkup::markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with gif image"
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 GyazzMarkup::markup_url_with_image("[[#{url} #{img_url}]]") == "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with bmp image"
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 GyazzMarkup::markup_url_with_image("[[#{url} #{img_url}]]") != "<a href=\"#{url}\"><img src=\"#{img_url}\"></a>", "url with not image"
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.2
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