Walt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/README.md +44 -0
- data/Rakefile +3 -0
- data/Walt.gemspec +30 -0
- data/lib/Walt/version.rb +1 -0
- data/lib/Walt.rb +55 -0
- data/spec/Walt.rb +30 -0
- data/spec/bin.rb +13 -0
- data/spec/lib/main.rb +41 -0
- metadata +151 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
Walt
|
3
|
+
================
|
4
|
+
|
5
|
+
A Ruby gem providing simple line and blockquote parsing (w/o paragraphs):
|
6
|
+
|
7
|
+
This is a line.
|
8
|
+
This is a line with a block:
|
9
|
+
|
10
|
+
I am a block.
|
11
|
+
|
12
|
+
# -->
|
13
|
+
[
|
14
|
+
[ String, nil],
|
15
|
+
[ String, "I am a block"]
|
16
|
+
]
|
17
|
+
|
18
|
+
Installation
|
19
|
+
------------
|
20
|
+
|
21
|
+
gem install Walt
|
22
|
+
|
23
|
+
Usage
|
24
|
+
------
|
25
|
+
|
26
|
+
require "Walt"
|
27
|
+
|
28
|
+
Walt str
|
29
|
+
|
30
|
+
|
31
|
+
Run Tests
|
32
|
+
---------
|
33
|
+
|
34
|
+
git clone git@github.com:da99/Walt.git
|
35
|
+
cd Walt
|
36
|
+
bundle update
|
37
|
+
bundle exec bacon spec/lib/main.rb
|
38
|
+
|
39
|
+
Know of a better way?
|
40
|
+
-----------------------------
|
41
|
+
|
42
|
+
If you know of existing software that makes the above redundant,
|
43
|
+
please tell me.
|
44
|
+
|
data/Rakefile
ADDED
data/Walt.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "Walt/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "Walt"
|
8
|
+
s.version = Walt_Version
|
9
|
+
s.authors = ["da99"]
|
10
|
+
s.email = ["i-hate-spam-45671204@mailinator.com"]
|
11
|
+
s.homepage = "https://github.com/da99/Walt"
|
12
|
+
s.summary = %q{Parse line and blockquotes.}
|
13
|
+
s.description = %q{
|
14
|
+
Parse lines and blockquotes. (No paragraphs.)
|
15
|
+
}
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'bacon'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'Bacon_Colored'
|
25
|
+
s.add_development_dependency 'pry'
|
26
|
+
|
27
|
+
# Specify any dependencies here; for example:
|
28
|
+
s.add_runtime_dependency 'Split_Lines'
|
29
|
+
s.add_runtime_dependency 'indentation'
|
30
|
+
end
|
data/lib/Walt/version.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Walt_Version = "0.1.0"
|
data/lib/Walt.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'Walt/version'
|
2
|
+
require 'Split_Lines'
|
3
|
+
require 'indentation'
|
4
|
+
|
5
|
+
module Kernel
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
WALT_HEAD_WHITE_SPACE = %r!\A\s!
|
10
|
+
def Walt str
|
11
|
+
lines = str.reset_indentation.split("\n")
|
12
|
+
|
13
|
+
i = -1
|
14
|
+
in_block = false
|
15
|
+
arr = []
|
16
|
+
while i < lines.size-1 do
|
17
|
+
i+=1
|
18
|
+
|
19
|
+
next if lines[i].strip.empty? && !in_block
|
20
|
+
|
21
|
+
if lines[i].index(WALT_HEAD_WHITE_SPACE) == 0 || lines[i].empty?
|
22
|
+
|
23
|
+
if in_block
|
24
|
+
# do nothing. all set.
|
25
|
+
else
|
26
|
+
arr.last[0] = arr.last[0].sub(%r!:\Z!, '')
|
27
|
+
in_block = arr.last
|
28
|
+
in_block[1] = []
|
29
|
+
end
|
30
|
+
|
31
|
+
in_block[1] << lines[i]
|
32
|
+
|
33
|
+
else
|
34
|
+
in_block = nil
|
35
|
+
arr << [ lines[i], nil ]
|
36
|
+
|
37
|
+
end # === if
|
38
|
+
|
39
|
+
end # === while
|
40
|
+
|
41
|
+
|
42
|
+
arr.map { |pair|
|
43
|
+
|
44
|
+
first = pair.first
|
45
|
+
last = pair.last
|
46
|
+
|
47
|
+
if last
|
48
|
+
last = last.join("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
[ first, last ]
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
end # === Kernel
|
data/spec/Walt.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
describe "Walt" do
|
3
|
+
|
4
|
+
it "parses lines" do
|
5
|
+
Walt(%@
|
6
|
+
This is A.
|
7
|
+
This is B.
|
8
|
+
@).should == [["This is A.", nil], ["This is B.", nil]]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "parses blocks surrounded by empty lines of spaces with irregular indentation." do
|
12
|
+
Walt(%@
|
13
|
+
This is A.
|
14
|
+
This is B:
|
15
|
+
|
16
|
+
Block
|
17
|
+
|
18
|
+
@).should == [["This is A.", nil], ["This is B", " Block\n "] ]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "does not remove last colon if line has no block." do
|
22
|
+
Walt(%@
|
23
|
+
This is A.
|
24
|
+
This is :memory:
|
25
|
+
This is B.
|
26
|
+
@).should == ["This is A.", "This is :memory:", "This is B."].zip([nil, nil, nil])
|
27
|
+
end
|
28
|
+
|
29
|
+
end # === Walt
|
30
|
+
|
data/spec/bin.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
bins = Dir.glob("bin/*")
|
3
|
+
|
4
|
+
unless bins.empty?
|
5
|
+
describe "permissions of bin/" do
|
6
|
+
bins.each { |file|
|
7
|
+
it "should chmod 755 for: #{file}" do
|
8
|
+
`stat -c %a #{file}`.strip
|
9
|
+
.should.be == "755"
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end # === permissions of bin/
|
13
|
+
end # === unless bins.empty?
|
data/spec/lib/main.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.print e.message, "\n"
|
8
|
+
$stderr.print "Run `bundle install` to install missing gems\n"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'bacon'
|
13
|
+
Bacon.summary_on_exit
|
14
|
+
|
15
|
+
require 'Walt'
|
16
|
+
require 'Bacon_Colored'
|
17
|
+
require 'pry'
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
# ======== Custom code.
|
22
|
+
|
23
|
+
# Nothing yet.
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
# ======== Include the tests.
|
29
|
+
target_files = ARGV[1, ARGV.size - 1].select { |a| File.file?(a) }
|
30
|
+
|
31
|
+
if target_files.empty?
|
32
|
+
|
33
|
+
# include all files
|
34
|
+
Dir.glob('./spec/*.rb').each { |file|
|
35
|
+
require file.sub('.rb', '') if File.file?(file)
|
36
|
+
}
|
37
|
+
|
38
|
+
else
|
39
|
+
# Do nothing. Bacon grabs the file.
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Walt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- da99
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: Bacon_Colored
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: Split_Lines
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: indentation
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: ! "\n Parse lines and blockquotes. (No paragraphs.)\n "
|
111
|
+
email:
|
112
|
+
- i-hate-spam-45671204@mailinator.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- Walt.gemspec
|
122
|
+
- lib/Walt.rb
|
123
|
+
- lib/Walt/version.rb
|
124
|
+
- spec/Walt.rb
|
125
|
+
- spec/bin.rb
|
126
|
+
- spec/lib/main.rb
|
127
|
+
homepage: https://github.com/da99/Walt
|
128
|
+
licenses: []
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.8.23
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: Parse line and blockquotes.
|
151
|
+
test_files: []
|