typedown 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,3 +22,10 @@ rescue LoadError
22
22
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
23
  end
24
24
 
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,9 +1,6 @@
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/section'
4
5
  require 'typedown/document'
5
6
 
6
- module Typedown
7
- VERSION = '0.0.1'
8
- end
9
-
@@ -1,4 +1,4 @@
1
- require 'rubygems'
1
+ #require 'rubygems'
2
2
  #require 'kramdown'
3
3
  require 'bluecloth'
4
4
 
@@ -0,0 +1,69 @@
1
+
2
+
3
+ module Typedown
4
+ class Section < String
5
+ def initialize title, body
6
+ @title = (title || "").strip
7
+ @body = ""
8
+ @sections = []
9
+ if body
10
+ @body, @sections = sectionize(body)
11
+ end
12
+ end
13
+
14
+ def dummy?
15
+ (@title.empty?) && @body.empty? && subsections.length == 1
16
+ end
17
+
18
+ def title
19
+ @title
20
+ end
21
+
22
+ def body
23
+ b = Document.new @body
24
+ b << "\n\n"
25
+ subsections.each do |s|
26
+ b << s.doc
27
+ end
28
+ b
29
+ end
30
+
31
+ def doc
32
+ d = Document.new "! #{title}\n\n"
33
+ d << body.gsub(/^(!+ )/, '!\0')
34
+ d
35
+ end
36
+
37
+ def subsections
38
+ @sections
39
+ end
40
+
41
+ def self.sectionize body, title = nil
42
+ s = nil
43
+ if title
44
+ s = Section.new title, body
45
+ else
46
+ s = Section.new "", body
47
+ s.dummy? ? s.subsections[0] : s
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def sectionize v
54
+ body, rest = v.split(/^! /, 2)
55
+ sections = []
56
+
57
+ if rest
58
+ rest.strip.split(/^! /).each do |s|
59
+ title, rest = s.split(/$/, 2)
60
+ rest.gsub!(/^!(!+ )/, "\\1")
61
+
62
+ sections << Section.new(title.strip, rest)
63
+ end
64
+ end
65
+
66
+ [ body.strip, sections ]
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'typedown'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class TestDocument < Test::Unit::TestCase
4
+ def setup
5
+ @doc = File.read("test/data/example.tpd")
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ should "parse with no exceptions" do
12
+ assert_nothing_raised do
13
+ Typedown::Document.new @doc
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ class TestSection < Test::Unit::TestCase
4
+ def setup
5
+ @doc = File.read("test/data/example.tpd")
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ should "parse with no exceptions" do
12
+ assert_nothing_raised do
13
+ s = Typedown::Section.new "Mail subject", @doc
14
+ end
15
+ end
16
+
17
+ should "reassemble doc with no exceptions using new" do
18
+ assert_nothing_raised do
19
+ s = Typedown::Section.new "Mail subject", @doc
20
+ end
21
+ end
22
+
23
+ should "reassemble doc with no exceptions using self.sectionize" do
24
+ assert_nothing_raised do
25
+ s = Typedown::Section.sectionize @doc, "Mail subject"
26
+ puts "\n\n", s.doc
27
+ end
28
+ end
29
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{typedown}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["wrimle"]
@@ -26,12 +26,14 @@ Gem::Specification.new do |s|
26
26
  "bin/typedown",
27
27
  "lib/typedown.rb",
28
28
  "lib/typedown/document.rb",
29
+ "lib/typedown/section.rb",
29
30
  "script/console",
30
31
  "script/destroy",
31
32
  "script/generate",
32
33
  "test/data/example.tpd",
33
- "test/test_helper.rb",
34
- "test/test_typedown.rb",
34
+ "test/helper.rb",
35
+ "test/test_document.rb",
36
+ "test/test_section.rb",
35
37
  "typedown.gemspec"
36
38
  ]
37
39
  s.homepage = %q{http://github.com/wrimle/typedown}
@@ -40,8 +42,9 @@ Gem::Specification.new do |s|
40
42
  s.rubygems_version = %q{1.3.7}
41
43
  s.summary = %q{A markdown dialect optimized for fast typing on mobile devices}
42
44
  s.test_files = [
43
- "test/test_helper.rb",
44
- "test/test_typedown.rb"
45
+ "test/test_document.rb",
46
+ "test/helper.rb",
47
+ "test/test_section.rb"
45
48
  ]
46
49
 
47
50
  if s.respond_to? :specification_version then
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: 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
  - wrimle
@@ -51,12 +51,14 @@ files:
51
51
  - bin/typedown
52
52
  - lib/typedown.rb
53
53
  - lib/typedown/document.rb
54
+ - lib/typedown/section.rb
54
55
  - script/console
55
56
  - script/destroy
56
57
  - script/generate
57
58
  - test/data/example.tpd
58
- - test/test_helper.rb
59
- - test/test_typedown.rb
59
+ - test/helper.rb
60
+ - test/test_document.rb
61
+ - test/test_section.rb
60
62
  - typedown.gemspec
61
63
  has_rdoc: true
62
64
  homepage: http://github.com/wrimle/typedown
@@ -93,5 +95,6 @@ signing_key:
93
95
  specification_version: 3
94
96
  summary: A markdown dialect optimized for fast typing on mobile devices
95
97
  test_files:
96
- - test/test_helper.rb
97
- - test/test_typedown.rb
98
+ - test/test_document.rb
99
+ - test/helper.rb
100
+ - test/test_section.rb
@@ -1,3 +0,0 @@
1
- require 'stringio'
2
- require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/typedown'
@@ -1,11 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestTypedown < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end