wparser 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.0.2 2010-06-12
2
+ 雛形のまま登録していたのを、ちゃんと使えるようにした。
3
+
1
4
  === 0.0.1 2010-06-12
2
5
 
3
6
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -5,10 +5,24 @@ README.rdoc
5
5
  Rakefile
6
6
  bin/wparser
7
7
  lib/wparser.rb
8
+ lib/wparser/block/block.rb
9
+ lib/wparser/block/blocks.rb
10
+ lib/wparser/block/list_nonumber.rb
11
+ lib/wparser/block/list_number.rb
12
+ lib/wparser/break.rb
8
13
  lib/wparser/cli.rb
14
+ lib/wparser/inline/deleted.rb
15
+ lib/wparser/inline/heading.rb
16
+ lib/wparser/inline/http.rb
17
+ lib/wparser/inline/inline.rb
18
+ lib/wparser/inline/italic.rb
19
+ lib/wparser/inline/strong.rb
20
+ lib/wparser/inline/underLine.rb
21
+ lib/wparser/parser.rb
9
22
  script/console
10
23
  script/destroy
11
24
  script/generate
25
+ script/makemanifest.rb
12
26
  spec/spec.opts
13
27
  spec/spec_helper.rb
14
28
  spec/wparser_cli_spec.rb
data/README.rdoc CHANGED
@@ -4,15 +4,18 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- FIX (describe your package)
7
+ This package is Wiki Format Parser.
8
+ Wiki => html
8
9
 
9
10
  == FEATURES/PROBLEMS:
10
11
 
11
- * FIX (list of features or problems)
12
12
 
13
13
  == SYNOPSIS:
14
14
 
15
- FIX (code sample of usage)
15
+ require 'wparser'
16
+
17
+ parser = WParser.parser.new
18
+ parser.parse(text)
16
19
 
17
20
  == REQUIREMENTS:
18
21
 
@@ -20,7 +23,7 @@ FIX (describe your package)
20
23
 
21
24
  == INSTALL:
22
25
 
23
- * FIX (sudo gem install, anything else)
26
+ gem install wparser
24
27
 
25
28
  == LICENSE:
26
29
 
@@ -45,4 +48,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
48
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
49
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
50
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/wparser.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ #require File.join(directory, 'wparser', 'Parser')
5
+ require 'wparser/parser'
4
6
  module Wparser
5
- VERSION = '0.0.1'
6
- end
7
+ VERSION = '0.0.2'
8
+
9
+ def Wparser.new
10
+ Parser.new
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'wparser/block/blocks'
2
+ require 'wparser/block/list_number'
3
+ require 'wparser/block/list_nonumber'
4
+
5
+ module Block
6
+ include Blocks
7
+ include List_number
8
+ include List_nonumber
9
+
10
+ def parse text
11
+ parse_text = Blocks.parse(text)
12
+ parse_text = List_number.parse(parse_text)
13
+ parse_text = List_nonumber.parse(parse_text)
14
+ end
15
+
16
+ module_function :parse
17
+ end
@@ -0,0 +1,26 @@
1
+ module Blocks
2
+ BLOCK_TABLE = {
3
+ ">>" => '<blockquote>',
4
+ "<<" => '</blockquote>',
5
+ ">||" => '<pre>',
6
+ "||<" => '</pre>',
7
+ ">|code|" => '<pre class="prettyprint">',
8
+ "|code|<" => '</pre>'
9
+ }
10
+
11
+ def parse text
12
+ block_rex = %r!
13
+ (^>>)|(^<<) # blockquote
14
+ |
15
+ (^>\|\|)|(^\|\|<) # pre
16
+ |
17
+ (^\>\|code\|)|(^\|code\|\<) # google-code-prettify
18
+ !x
19
+
20
+ parse_text = text.gsub(block_rex){|s| BLOCK_TABLE[s]}
21
+ return text if parse_text == nil
22
+ parse_text
23
+ end
24
+
25
+ module_function :parse
26
+ end
@@ -0,0 +1,22 @@
1
+ module List_nonumber
2
+ def parse text
3
+ start_ul_rex = %r!
4
+ ^\s*$\n # 空行 => \n<ul>\n
5
+ ^\*\s(\w*)\n # * list_start => <li>list_start</li>\n
6
+ !x
7
+ parse_text = text.gsub(start_ul_rex){|s| "\n<ul>\n<li>#$1</li>\n"}
8
+
9
+ end_ul_rex = %r!
10
+ ^\*\s(\w*)\n # * list_end => <li>list_end</li>\n
11
+ ^\s*$\n # 空行 => </ul>\n\n
12
+ !x
13
+ parse_text = parse_text.gsub(end_ul_rex){|s| "<li>#$1</li>\n</ul>\n\n"}
14
+
15
+ # * list => <li>list</li>
16
+ parse_text = parse_text.gsub(/^\*\s(\w*)\n/){|s| "<li>#$1</li>\n"}
17
+ return text if parse_text == nil
18
+ parse_text
19
+ end
20
+
21
+ module_function :parse
22
+ end
@@ -0,0 +1,22 @@
1
+ module List_number
2
+ def parse text
3
+ start_ul_rex = %r!
4
+ ^\s*$\n # 空行 => \n<ul>\n
5
+ ^\#\s(\w*)\n # # list_start => <li>list_start</li>\n
6
+ !x
7
+ parse_text = text.gsub(start_ul_rex){|s| "\n<ol>\n<li>#$1</li>\n"}
8
+
9
+ end_ul_rex = %r!
10
+ ^\#\s(\w*)\n # # list_end => <li>list_end</li>\n
11
+ ^\s*$\n # 空行 => </ol>\n\n
12
+ !x
13
+ parse_text = parse_text.gsub(end_ul_rex){|s| "<li>#$1</li>\n</ol>\n\n"}
14
+
15
+ # * list => <li>list</li>
16
+ parse_text = parse_text.gsub(/^\#\s(\w*)\n/){|s| "<li>#$1</li>\n"}
17
+ return text if parse_text == nil
18
+ parse_text
19
+ end
20
+
21
+ module_function :parse
22
+ end
@@ -0,0 +1,10 @@
1
+ module Break
2
+ def parse text
3
+ parse_text = text.gsub(/\r/, "\n").gsub(/\r\n/, "\n")
4
+
5
+ return text if parse_text ==nil
6
+ parse_text
7
+ end
8
+
9
+ module_function :parse
10
+ end
@@ -0,0 +1,9 @@
1
+ module Deleted
2
+ def parse line
3
+ parse_line = line.sub(/-\b(\w*)\b-/){|s| "<S>#$1</S>"}
4
+ return line if parse_line == nil
5
+ parse_line
6
+ end
7
+
8
+ module_function :parse
9
+ end
@@ -0,0 +1,9 @@
1
+ module Heading
2
+ def parse line
3
+ parse_line = line.sub(/^h([1-6])\.\s(.*)\n/){|s| "<h#$1>#$2</h#$1>\n" }
4
+ return line if parse_line == nil
5
+ parse_line
6
+ end
7
+
8
+ module_function :parse
9
+ end
@@ -0,0 +1,19 @@
1
+ module Http
2
+ # (?<![.,?\!]) 1.8.7では後読みが出来ない、どーするか。
3
+ def parse text
4
+ url_rex = %r!
5
+ \b
6
+ (
7
+ http:// [-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info|net) \b
8
+ (
9
+ / [-a-z0-9_:\@&?=+,.\!/~*'%\$]*[^.,?\!]
10
+ )?
11
+ )
12
+ !x
13
+ parse_text = text.gsub(url_rex){|s| "<a href=\"#$1\">#$1</a>"}
14
+ return text if parse_text == nil
15
+ parse_text
16
+ end
17
+
18
+ module_function :parse
19
+ end
@@ -0,0 +1,34 @@
1
+ require 'wparser/inline/heading'
2
+ require 'wparser/inline/strong'
3
+ require 'wparser/inline/italic'
4
+ require 'wparser/inline/underLine'
5
+ require 'wparser/inline/deleted'
6
+ require 'wparser/inline/http'
7
+
8
+ module Inline
9
+ include Heading
10
+ include Strong
11
+ include Italic
12
+ include UnderLine
13
+ include Deleted
14
+ include Http
15
+
16
+ def parse text
17
+ parse_text = ""
18
+
19
+ text.each do |line|
20
+ parse_line = Heading.parse(line)
21
+ parse_line = Strong.parse(parse_line)
22
+ parse_line = Italic.parse(parse_line)
23
+ parse_line = UnderLine.parse(parse_line)
24
+ parse_line = Deleted.parse(parse_line)
25
+
26
+ parse_text << parse_line
27
+ end
28
+
29
+ parse_text = Http.parse(parse_text)
30
+ parse_text
31
+ end
32
+
33
+ module_function :parse
34
+ end
@@ -0,0 +1,9 @@
1
+ module Italic
2
+ def parse line
3
+ parse_line = line.sub(/\b_(\w*)_\b/){|s| "<I>#$1</I>"}
4
+ return line if parse_line == nil
5
+ parse_line
6
+ end
7
+
8
+ module_function :parse
9
+ end
@@ -0,0 +1,9 @@
1
+ module Strong
2
+ def parse line
3
+ parse_line = line.sub(/\*\b(\w*)\b\*/){|s| "<strong>#$1</strong>"}
4
+ return line if parse_line == nil
5
+ parse_line
6
+ end
7
+
8
+ module_function :parse
9
+ end
@@ -0,0 +1,9 @@
1
+ module UnderLine
2
+ def parse line
3
+ parse_line = line.sub(/\+\b(\w*)\b\+/){|s| "<U>#$1</U>"}
4
+ return line if parse_line == nil
5
+ parse_line
6
+ end
7
+
8
+ module_function :parse
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'wparser/break'
2
+ require 'wparser/inline/inline'
3
+ require 'wparser/block/block'
4
+
5
+ class Parser
6
+ def parse text
7
+ text = Break.parse(text)
8
+ text = Inline.parse(text)
9
+ text = Block.parse(text)
10
+
11
+ #html = text.to_html
12
+ text
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base_dir = File.join(File.dirname(__FILE__), "..")
4
+ glob_pattern = File.join("**", "*")
5
+ exclude_patterns = [
6
+ /^pkg/,/^doc/,
7
+ ]
8
+
9
+ Dir.chdir(base_dir)
10
+ files = Dir.glob(glob_pattern).delete_if do |fname|
11
+ File.directory?(fname) or
12
+ exclude_patterns.find do |pattern|
13
+ pattern =~ fname
14
+ end
15
+ end
16
+ manifest = File.new("Manifest.txt", "w")
17
+ manifest.puts files.sort.join("\n")
18
+ manifest.close
19
+
20
+ puts "Manifest.txt updated"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wparser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - iori
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-12 00:00:00 +09:00
18
+ date: 2010-06-13 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,9 @@ dependencies:
50
50
  version: 2.6.1
51
51
  type: :development
52
52
  version_requirements: *id002
53
- description: FIX (describe your package)
53
+ description: |-
54
+ This package is Wiki Format Parser.
55
+ Wiki => html
54
56
  email:
55
57
  - iori.nishizawa@gmail.com
56
58
  executables:
@@ -69,10 +71,24 @@ files:
69
71
  - Rakefile
70
72
  - bin/wparser
71
73
  - lib/wparser.rb
74
+ - lib/wparser/block/block.rb
75
+ - lib/wparser/block/blocks.rb
76
+ - lib/wparser/block/list_nonumber.rb
77
+ - lib/wparser/block/list_number.rb
78
+ - lib/wparser/break.rb
72
79
  - lib/wparser/cli.rb
80
+ - lib/wparser/inline/deleted.rb
81
+ - lib/wparser/inline/heading.rb
82
+ - lib/wparser/inline/http.rb
83
+ - lib/wparser/inline/inline.rb
84
+ - lib/wparser/inline/italic.rb
85
+ - lib/wparser/inline/strong.rb
86
+ - lib/wparser/inline/underLine.rb
87
+ - lib/wparser/parser.rb
73
88
  - script/console
74
89
  - script/destroy
75
90
  - script/generate
91
+ - script/makemanifest.rb
76
92
  - spec/spec.opts
77
93
  - spec/spec_helper.rb
78
94
  - spec/wparser_cli_spec.rb
@@ -112,6 +128,6 @@ rubyforge_project: wparser
112
128
  rubygems_version: 1.3.7
113
129
  signing_key:
114
130
  specification_version: 3
115
- summary: FIX (describe your package)
131
+ summary: This package is Wiki Format Parser
116
132
  test_files: []
117
133