typedown 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/typedown/section.rb +3 -2
- data/lib/typedown/shorthand.rb +57 -0
- data/lib/typedown.rb +1 -0
- data/test/data/example3.tpd +14 -0
- data/test/test_section.rb +2 -2
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/typedown/section.rb
CHANGED
@@ -6,12 +6,13 @@ module Typedown
|
|
6
6
|
@body = ""
|
7
7
|
@sections = []
|
8
8
|
if body
|
9
|
-
@body, @sections = sectionize(body)
|
9
|
+
@body, @sections = sectionize(Shorthand.process(body))
|
10
|
+
puts body
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
def dummy?
|
14
|
-
(title.strip.empty?) && (!@body || @body.strip.empty?)
|
15
|
+
subsections.length == 1 && (title.strip.empty? || title.tr("!","").strip == subsections[0].title.tr("!","").strip) && (!@body || @body.strip.empty?)
|
15
16
|
end
|
16
17
|
|
17
18
|
def title
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Typedown
|
2
|
+
|
3
|
+
class Shorthand
|
4
|
+
|
5
|
+
def self.process body
|
6
|
+
# Find all occurences mathcing the shorthand syntax
|
7
|
+
# 'action/param1[/param2]
|
8
|
+
offset = 0
|
9
|
+
while(match = body[offset..-1].match(/\'\w+[\/\w+]+/)) do
|
10
|
+
m = match[0]
|
11
|
+
res = self.resolve m
|
12
|
+
body.gsub!(m, res) if res
|
13
|
+
offset += match.begin(0) + (res || m).length
|
14
|
+
end
|
15
|
+
body
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.resolve m
|
22
|
+
begin
|
23
|
+
params = m.tr("'", "").split("/")
|
24
|
+
action = params.shift
|
25
|
+
|
26
|
+
if self.shorthands[ action.downcase ]
|
27
|
+
self.shorthands[ action.downcase ].resolve action, params
|
28
|
+
else
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
# Something wrong with parameters
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.shorthands
|
38
|
+
@shorthands = {} unless @shorthands
|
39
|
+
@shorthands
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def self.add_shorthand name, obj
|
44
|
+
self.shorthands[ name.downcase ] = obj
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize name
|
48
|
+
Shorthand.add_shorthand(name, self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def resolve action, params
|
52
|
+
raise "Please subclass and override this method."
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/typedown.rb
CHANGED
data/test/test_section.rb
CHANGED
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestSection < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@doc = File.read("test/data/
|
5
|
+
@doc = File.read("test/data/example3.tpd")
|
6
6
|
end
|
7
7
|
|
8
8
|
def teardown
|
@@ -23,7 +23,7 @@ class TestSection < Test::Unit::TestCase
|
|
23
23
|
should "reassemble doc with no exceptions using self.sectionize" do
|
24
24
|
assert_nothing_raised do
|
25
25
|
s = Typedown::Section.sectionize @doc, "Mail subject"
|
26
|
-
puts "\n\n", s.doc
|
26
|
+
#puts "\n\n", s.doc
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typedown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- wrimle
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-04 00:00:00 +02:00
|
19
19
|
default_executable: typedown
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,10 +51,12 @@ files:
|
|
51
51
|
- lib/typedown.rb
|
52
52
|
- lib/typedown/document.rb
|
53
53
|
- lib/typedown/section.rb
|
54
|
+
- lib/typedown/shorthand.rb
|
54
55
|
- script/console
|
55
56
|
- script/destroy
|
56
57
|
- script/generate
|
57
58
|
- test/data/example.tpd
|
59
|
+
- test/data/example3.tpd
|
58
60
|
- test/helper.rb
|
59
61
|
- test/test_document.rb
|
60
62
|
- test/test_section.rb
|