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 CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -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?) && subsections.length == 1
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
@@ -1,6 +1,7 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ require 'typedown/shorthand'
4
5
  require 'typedown/section'
5
6
  require 'typedown/document'
6
7
 
@@ -0,0 +1,14 @@
1
+ ! Heading
2
+
3
+ //. A lead-in saying what the article is about.
4
+ Some more lead-in.
5
+ And more.
6
+
7
+ Some body copy.
8
+
9
+ !! Subheading
10
+
11
+ More body copy.
12
+
13
+ ('vg/10036000)
14
+ 'amazon/B000JMLFLW
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/example.tpd")
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
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-08-23 00:00:00 +02:00
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