wikiwah 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'wikiwah/flow'
2
+ require 'wikiwah/subst'
3
+
4
+ module WikiWah
5
+
6
+ class Converter
7
+
8
+ attr_writer :link_translator
9
+
10
+ def initialize
11
+ @link_translator = proc do |link| link end
12
+ init_transformer
13
+ end
14
+
15
+ # Convert WikiWah text to HTML.
16
+ def convert(text)
17
+ Flow.convert(text) do |paragraph|
18
+ @transformer.transform(paragraph)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def translate_link(link)
25
+ @link_translator.call(link)
26
+ end
27
+
28
+ def init_transformer
29
+ @transformer = WikiWah::Subst.new
30
+ @transformer.add_transformation(/""(.+)""/) do |match|
31
+ # Double-double-quoted
32
+ CGI.escapeHTML(match[1])
33
+ end
34
+ @transformer.add_transformation(/\\(.)/) do |match|
35
+ # Backslash-quoted
36
+ match[1]
37
+ end
38
+ @transformer.add_transformation(/\<(.+?)\>/m) do |match|
39
+ # In-line HTML
40
+ match[0]
41
+ end
42
+ @transformer.add_transformation(/\{(.+?)\}(@(\S*[\w\/]))?/m) do |match|
43
+ # Distinuished link
44
+ label = @transformer.transform(match[1])
45
+ location = translate_link(match[3] || match[1])
46
+ if location
47
+ "<a href='#{location}'>#{label}</a>"
48
+ else
49
+ "{#{label}}"
50
+ end
51
+ end
52
+ @transformer.add_transformation(/\b[a-z]+:[\w\/]\S*[\w\/]/) do |match|
53
+ # URL
54
+ "<a href='#{match[0]}'>#{match[0]}</a>"
55
+ end
56
+ @transformer.add_transformation(%r[(^|\W)([*+_/])([*+_/]*\w.*?\w[*+_/]*)\2(?!\w)]) do |match|
57
+ # Bold/italic/etc.
58
+ tag = case match[2]
59
+ when '*'; 'strong'
60
+ when '+'; 'tt'
61
+ when '/'; 'em'
62
+ when '_'; 'u'
63
+ end
64
+ content = @transformer.transform(match[3])
65
+ (match[1] + '<' + tag + '>' + content + '</' + tag + '>')
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
data/lib/wikiwah/flow.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'cgi' # for escapeHTML
4
4
 
5
- class WikiWah
5
+ module WikiWah
6
6
 
7
7
  # Flow deals with block-level formatting in WikiWah. Input text is split
8
8
  # into paragraphs, separated by blank lines. A list-item bullet also
data/lib/wikiwah/subst.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- class WikiWah
3
+ module WikiWah
4
4
 
5
5
  # Subst handles text-transformation using a series of regular-expression
6
6
  # substitutions. It encapsulates a number of "patterns", and associated
@@ -0,0 +1,20 @@
1
+ require "tilt"
2
+ require "wikiwah"
3
+
4
+ module WikiWah
5
+
6
+ class Template < Tilt::Template
7
+
8
+ def prepare
9
+ @output = nil
10
+ end
11
+
12
+ def evaluate(scope, locals, &block)
13
+ @output ||= WikiWah.convert(data)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ Tilt.register 'wah', WikiWah::Template
@@ -1,3 +1,3 @@
1
- class WikiWah
2
- VERSION = "0.0.1"
1
+ module WikiWah
2
+ VERSION = "0.0.2".freeze
3
3
  end
data/lib/wikiwah.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'wikiwah/flow'
2
- require 'wikiwah/subst'
1
+ require 'wikiwah/converter'
3
2
  require 'wikiwah/version'
4
3
 
5
4
  # A formatter for turning Wiki-esque text into HTML.
@@ -32,72 +31,12 @@ require 'wikiwah/version'
32
31
  # - "{LABEL}@LOCATION" creates a link to LOCATION, with the specified
33
32
  # LABEL.
34
33
  #
35
- class WikiWah
34
+ module WikiWah
36
35
 
37
- attr_writer :link_translator
38
-
39
- def initialize
40
- @link_translator = proc do |link| link end
41
- init_transformer
42
- end
43
-
44
- # Convert WikiWah text to HTML.
45
- def to_html(text)
46
- Flow.convert(text) do |paragraph|
47
- @transformer.transform(paragraph)
48
- end
49
- end
50
-
51
- def self.to_html(text)
52
- self.new.to_html(text)
53
- end
54
-
55
- private
56
-
57
- def translate_link(link)
58
- @link_translator.call(link)
59
- end
60
-
61
- def init_transformer
62
- @transformer = WikiWah::Subst.new
63
- @transformer.add_transformation(/""(.+)""/) do |match|
64
- # Double-double-quoted
65
- CGI.escapeHTML(match[1])
66
- end
67
- @transformer.add_transformation(/\\(.)/) do |match|
68
- # Backslash-quoted
69
- match[1]
70
- end
71
- @transformer.add_transformation(/\<(.+?)\>/m) do |match|
72
- # In-line HTML
73
- match[0]
74
- end
75
- @transformer.add_transformation(/\{(.+?)\}(@(\S*[\w\/]))?/m) do |match|
76
- # Distinuished link
77
- label = @transformer.transform(match[1])
78
- location = translate_link(match[3] || match[1])
79
- if location
80
- "<a href='#{location}'>#{label}</a>"
81
- else
82
- "{#{label}}"
83
- end
84
- end
85
- @transformer.add_transformation(/\b[a-z]+:[\w\/]\S*[\w\/]/) do |match|
86
- # URL
87
- "<a href='#{match[0]}'>#{match[0]}</a>"
88
- end
89
- @transformer.add_transformation(%r[(^|\W)([*+_/])([*+_/]*\w.*?\w[*+_/]*)\2(?!\w)]) do |match|
90
- # Bold/italic/etc.
91
- tag = case match[2]
92
- when '*'; 'strong'
93
- when '+'; 'tt'
94
- when '/'; 'em'
95
- when '_'; 'u'
96
- end
97
- content = @transformer.transform(match[3])
98
- (match[1] + '<' + tag + '>' + content + '</' + tag + '>')
99
- end
36
+ def self.convert(text)
37
+ Converter.new.convert(text)
100
38
  end
101
39
 
102
40
  end
103
41
 
42
+ Wikiwah = WikiWah
@@ -401,7 +401,7 @@ after
401
401
  </p>
402
402
  END_OF_TESTS
403
403
 
404
- class WikiWah
404
+ module WikiWah
405
405
  class FlowTests < Test::Unit::TestCase
406
406
 
407
407
  TESTS.split(/\n====.*\n/).each_with_index do |test, i|
@@ -3,7 +3,7 @@
3
3
  require 'wikiwah/subst'
4
4
  require 'test/unit'
5
5
 
6
- class WikiWah
6
+ module WikiWah
7
7
 
8
8
  class Subst_Tests < Test::Unit::TestCase
9
9
 
@@ -5,12 +5,8 @@ require 'test/unit'
5
5
 
6
6
  class WikiWahTests < Test::Unit::TestCase
7
7
 
8
- def setup
9
- @wikiwah = WikiWah.new
10
- end
11
-
12
8
  def assert_wikiwah(expected, input)
13
- assert_equal(expected, @wikiwah.to_html(input))
9
+ assert_equal(expected, Wikiwah.convert(input))
14
10
  end
15
11
 
16
12
  def test_empty
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikiwah
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
  - Mike Williams
@@ -15,12 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-30 00:00:00 +10:00
18
+ date: 2010-10-28 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
22
  description: |
23
- Wikiwah is a text-to-HTML converter, along the lines of Markdown.
23
+ WikiWah is a text-to-HTML converter, along the lines of Markdown.
24
24
 
25
25
  This isn't the markup language you're looking for.
26
26
  It offers no improvements on Markdown, Textile, etc.
@@ -34,10 +34,12 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
 
36
36
  files:
37
+ - lib/wikiwah/converter.rb
37
38
  - lib/wikiwah/flow.rb
38
39
  - lib/wikiwah/flow.rb~
39
40
  - lib/wikiwah/subst.rb
40
41
  - lib/wikiwah/subst.rb~
42
+ - lib/wikiwah/tilt_integration.rb
41
43
  - lib/wikiwah/version.rb
42
44
  - lib/wikiwah/version.rb~
43
45
  - lib/wikiwah.rb