textweaver 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/CHANGELOG +8 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -165
- data/README.md +71 -0
- data/Rakefile +5 -90
- data/lib/text_weaver.rb +5 -17
- data/lib/text_weaver/error.rb +0 -14
- data/lib/text_weaver/insert_position.rb +0 -14
- data/lib/text_weaver/version.rb +1 -7
- data/test/helper.rb +5 -0
- data/test/test_insert_position.rb +35 -0
- data/test/test_text_weaver.rb +79 -0
- data/textweaver.gemspec +20 -0
- metadata +81 -24
- data/README +0 -84
- data/install.rb +0 -30
- data/test/insert_position_test.rb +0 -48
- data/test/test_helper.rb +0 -3
- data/test/text_weaver_test.rb +0 -92
data/.gitignore
ADDED
data/CHANGELOG
CHANGED
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,165 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
of this
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
by the Library, but which is not otherwise based on the Library.
|
24
|
-
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
-
of using an interface provided by the Library.
|
26
|
-
|
27
|
-
A "Combined Work" is a work produced by combining or linking an
|
28
|
-
Application with the Library. The particular version of the Library
|
29
|
-
with which the Combined Work was made is also called the "Linked
|
30
|
-
Version".
|
31
|
-
|
32
|
-
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
-
Corresponding Source for the Combined Work, excluding any source code
|
34
|
-
for portions of the Combined Work that, considered in isolation, are
|
35
|
-
based on the Application, and not on the Linked Version.
|
36
|
-
|
37
|
-
The "Corresponding Application Code" for a Combined Work means the
|
38
|
-
object code and/or source code for the Application, including any data
|
39
|
-
and utility programs needed for reproducing the Combined Work from the
|
40
|
-
Application, but excluding the System Libraries of the Combined Work.
|
41
|
-
|
42
|
-
1. Exception to Section 3 of the GNU GPL.
|
43
|
-
|
44
|
-
You may convey a covered work under sections 3 and 4 of this License
|
45
|
-
without being bound by section 3 of the GNU GPL.
|
46
|
-
|
47
|
-
2. Conveying Modified Versions.
|
48
|
-
|
49
|
-
If you modify a copy of the Library, and, in your modifications, a
|
50
|
-
facility refers to a function or data to be supplied by an Application
|
51
|
-
that uses the facility (other than as an argument passed when the
|
52
|
-
facility is invoked), then you may convey a copy of the modified
|
53
|
-
version:
|
54
|
-
|
55
|
-
a) under this License, provided that you make a good faith effort to
|
56
|
-
ensure that, in the event an Application does not supply the
|
57
|
-
function or data, the facility still operates, and performs
|
58
|
-
whatever part of its purpose remains meaningful, or
|
59
|
-
|
60
|
-
b) under the GNU GPL, with none of the additional permissions of
|
61
|
-
this License applicable to that copy.
|
62
|
-
|
63
|
-
3. Object Code Incorporating Material from Library Header Files.
|
64
|
-
|
65
|
-
The object code form of an Application may incorporate material from
|
66
|
-
a header file that is part of the Library. You may convey such object
|
67
|
-
code under terms of your choice, provided that, if the incorporated
|
68
|
-
material is not limited to numerical parameters, data structure
|
69
|
-
layouts and accessors, or small macros, inline functions and templates
|
70
|
-
(ten or fewer lines in length), you do both of the following:
|
71
|
-
|
72
|
-
a) Give prominent notice with each copy of the object code that the
|
73
|
-
Library is used in it and that the Library and its use are
|
74
|
-
covered by this License.
|
75
|
-
|
76
|
-
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
-
document.
|
78
|
-
|
79
|
-
4. Combined Works.
|
80
|
-
|
81
|
-
You may convey a Combined Work under terms of your choice that,
|
82
|
-
taken together, effectively do not restrict modification of the
|
83
|
-
portions of the Library contained in the Combined Work and reverse
|
84
|
-
engineering for debugging such modifications, if you also do each of
|
85
|
-
the following:
|
86
|
-
|
87
|
-
a) Give prominent notice with each copy of the Combined Work that
|
88
|
-
the Library is used in it and that the Library and its use are
|
89
|
-
covered by this License.
|
90
|
-
|
91
|
-
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
-
document.
|
93
|
-
|
94
|
-
c) For a Combined Work that displays copyright notices during
|
95
|
-
execution, include the copyright notice for the Library among
|
96
|
-
these notices, as well as a reference directing the user to the
|
97
|
-
copies of the GNU GPL and this license document.
|
98
|
-
|
99
|
-
d) Do one of the following:
|
100
|
-
|
101
|
-
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
-
License, and the Corresponding Application Code in a form
|
103
|
-
suitable for, and under terms that permit, the user to
|
104
|
-
recombine or relink the Application with a modified version of
|
105
|
-
the Linked Version to produce a modified Combined Work, in the
|
106
|
-
manner specified by section 6 of the GNU GPL for conveying
|
107
|
-
Corresponding Source.
|
108
|
-
|
109
|
-
1) Use a suitable shared library mechanism for linking with the
|
110
|
-
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
-
a copy of the Library already present on the user's computer
|
112
|
-
system, and (b) will operate properly with a modified version
|
113
|
-
of the Library that is interface-compatible with the Linked
|
114
|
-
Version.
|
115
|
-
|
116
|
-
e) Provide Installation Information, but only if you would otherwise
|
117
|
-
be required to provide such information under section 6 of the
|
118
|
-
GNU GPL, and only to the extent that such information is
|
119
|
-
necessary to install and execute a modified version of the
|
120
|
-
Combined Work produced by recombining or relinking the
|
121
|
-
Application with a modified version of the Linked Version. (If
|
122
|
-
you use option 4d0, the Installation Information must accompany
|
123
|
-
the Minimal Corresponding Source and Corresponding Application
|
124
|
-
Code. If you use option 4d1, you must provide the Installation
|
125
|
-
Information in the manner specified by section 6 of the GNU GPL
|
126
|
-
for conveying Corresponding Source.)
|
127
|
-
|
128
|
-
5. Combined Libraries.
|
129
|
-
|
130
|
-
You may place library facilities that are a work based on the
|
131
|
-
Library side by side in a single library together with other library
|
132
|
-
facilities that are not Applications and are not covered by this
|
133
|
-
License, and convey such a combined library under terms of your
|
134
|
-
choice, if you do both of the following:
|
135
|
-
|
136
|
-
a) Accompany the combined library with a copy of the same work based
|
137
|
-
on the Library, uncombined with any other library facilities,
|
138
|
-
conveyed under the terms of this License.
|
139
|
-
|
140
|
-
b) Give prominent notice with the combined library that part of it
|
141
|
-
is a work based on the Library, and explaining where to find the
|
142
|
-
accompanying uncombined form of the same work.
|
143
|
-
|
144
|
-
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
-
|
146
|
-
The Free Software Foundation may publish revised and/or new versions
|
147
|
-
of the GNU Lesser General Public License from time to time. Such new
|
148
|
-
versions will be similar in spirit to the present version, but may
|
149
|
-
differ in detail to address new problems or concerns.
|
150
|
-
|
151
|
-
Each version is given a distinguishing version number. If the
|
152
|
-
Library as you received it specifies that a certain numbered version
|
153
|
-
of the GNU Lesser General Public License "or any later version"
|
154
|
-
applies to it, you have the option of following the terms and
|
155
|
-
conditions either of that published version or of any later version
|
156
|
-
published by the Free Software Foundation. If the Library as you
|
157
|
-
received it does not specify a version number of the GNU Lesser
|
158
|
-
General Public License, you may choose any version of the GNU Lesser
|
159
|
-
General Public License ever published by the Free Software Foundation.
|
160
|
-
|
161
|
-
If the Library as you received it specifies that a proxy can decide
|
162
|
-
whether future versions of the GNU Lesser General Public License shall
|
163
|
-
apply, that proxy's public statement of acceptance of any version is
|
164
|
-
permanent authorization for you to choose that version for the
|
165
|
-
Library.
|
1
|
+
Copyright (c) 2012 Wybo Wiersma
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Text Weaver
|
2
|
+
"Weaves any string into any text"
|
3
|
+
|
4
|
+
Weaves html tags (or really anything) into a text at given
|
5
|
+
opening or closing positions. Inserted tags need to be aligned
|
6
|
+
(that is non-overlapping) in order to be inserted.
|
7
|
+
|
8
|
+
Opening and closing tags are inserted and kept in order.
|
9
|
+
|
10
|
+
Inspired by Ted Nelsons project Xanadu.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
First require it.
|
15
|
+
|
16
|
+
$ irb
|
17
|
+
|
18
|
+
> require 'rubygems'
|
19
|
+
> require 'textweaver'
|
20
|
+
|
21
|
+
You can create a TextWeaver with any text.
|
22
|
+
|
23
|
+
> w = TextWeaver.new("abcde")
|
24
|
+
|
25
|
+
Then add some openings and closings.
|
26
|
+
|
27
|
+
> w.add_opening(1, "(")
|
28
|
+
> w.add_closing(4, ")")
|
29
|
+
|
30
|
+
> w.weave
|
31
|
+
=> "a(bcd)e"
|
32
|
+
|
33
|
+
Possibly with additionally some different tag-types.
|
34
|
+
|
35
|
+
> w.next_set
|
36
|
+
|
37
|
+
> w.add_opening(1, "<")
|
38
|
+
> w.add_closing(4, ">")
|
39
|
+
|
40
|
+
> w.weave
|
41
|
+
=> "a(<bcd>)e"
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
Add this line to your application's Gemfile:
|
46
|
+
|
47
|
+
gem 'textweaver'
|
48
|
+
|
49
|
+
And then execute:
|
50
|
+
|
51
|
+
$ bundle
|
52
|
+
|
53
|
+
Or install it yourself as:
|
54
|
+
|
55
|
+
$ gem install textweaver
|
56
|
+
|
57
|
+
Feel free to report issues and to ask questions. For the latest news
|
58
|
+
on TextWeaver:
|
59
|
+
|
60
|
+
* http://foundation.logilogi.org/tags/TextWeaver
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
If you wish to contribute, please create a pull-request and remember
|
65
|
+
to update the corresponding unit test(s).
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,91 +1,6 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rake/rdoctask'
|
5
|
-
require 'rake/packagetask'
|
6
|
-
require 'rake/gempackagetask'
|
7
|
-
require 'rake/contrib/sshpublisher'
|
8
|
-
require File.join(File.dirname(__FILE__), 'lib', 'text_weaver', 'version')
|
9
|
-
|
10
|
-
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
11
|
-
PKG_NAME = 'textweaver'
|
12
|
-
PKG_VERSION = TextWeaver::VERSION::STRING + PKG_BUILD
|
13
|
-
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
14
|
-
|
15
|
-
RELEASE_NAME = "REL #{PKG_VERSION}"
|
16
|
-
|
17
|
-
RUBY_FORGE_PROJECT = "textweaver"
|
18
|
-
RUBY_FORGE_USER = "wybow"
|
19
|
-
|
20
|
-
desc "Default Task"
|
21
|
-
task :default => [ :test ]
|
22
|
-
|
23
|
-
# Run the unit tests
|
24
|
-
Rake::TestTask.new { |t|
|
25
|
-
t.libs << "test"
|
26
|
-
t.pattern = 'test/*_test.rb'
|
27
|
-
t.verbose = true
|
28
|
-
t.warning = false
|
29
|
-
}
|
30
|
-
|
31
|
-
# Generate the RDoc documentation
|
32
|
-
Rake::RDocTask.new { |rdoc|
|
33
|
-
rdoc.rdoc_dir = 'doc'
|
34
|
-
rdoc.title = "Text Weaver -- Weaves tags into text"
|
35
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
36
|
-
rdoc.options << '--charset' << 'utf-8'
|
37
|
-
rdoc.rdoc_files.include('README', 'CHANGELOG')
|
38
|
-
rdoc.rdoc_files.include('lib/text_weaver.rb')
|
39
|
-
rdoc.rdoc_files.include('lib/text_weaver/*.rb')
|
40
|
-
}
|
41
|
-
|
42
|
-
# Create compressed packages
|
43
|
-
spec = Gem::Specification.new do |s|
|
44
|
-
s.platform = Gem::Platform::RUBY
|
45
|
-
s.name = PKG_NAME
|
46
|
-
s.summary = "Weaves html tags into a text."
|
47
|
-
s.description = %q{Allows you to weave html tags into a text.}
|
48
|
-
s.version = PKG_VERSION
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
49
3
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
s.homepage = "http://textweaver.rubyforge.org"
|
54
|
-
|
55
|
-
s.has_rdoc = true
|
56
|
-
s.requirements << 'none'
|
57
|
-
s.require_path = 'lib'
|
58
|
-
|
59
|
-
s.files = [ "Rakefile", "install.rb", "README", "CHANGELOG", "LICENSE" ]
|
60
|
-
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
61
|
-
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
62
|
-
end
|
63
|
-
|
64
|
-
Rake::GemPackageTask.new(spec) do |p|
|
65
|
-
p.gem_spec = spec
|
66
|
-
p.need_tar = true
|
67
|
-
p.need_zip = true
|
68
|
-
end
|
69
|
-
|
70
|
-
desc "Publish the docs, gem, and release files"
|
71
|
-
task :deploy => [:release, :pdoc] do
|
72
|
-
puts 'Published gem'
|
73
|
-
end
|
74
|
-
|
75
|
-
desc "Publish the API documentation"
|
76
|
-
task :pdoc => [:rdoc] do
|
77
|
-
sh "rsync -azv --no-perms --no-times doc/*" +
|
78
|
-
" rubyforge.org:/var/www/gforge-projects/textweaver"
|
79
|
-
end
|
80
|
-
|
81
|
-
desc "Publish the release files to RubyForge."
|
82
|
-
task :release => [ :package ] do
|
83
|
-
require 'rubyforge'
|
84
|
-
require 'rake/contrib/rubyforgepublisher'
|
85
|
-
|
86
|
-
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
87
|
-
|
88
|
-
rubyforge = RubyForge.new.configure
|
89
|
-
rubyforge.login
|
90
|
-
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
|
91
|
-
end
|
4
|
+
task :default => :test
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new
|
data/lib/text_weaver.rb
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
#--#
|
2
|
-
# Copyright: (c)
|
2
|
+
# Copyright: (c) 2006-2012 Wybo Wiersma <mail@wybowiersma.net>
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# This file is part of the TextWeaver Library. TextWeaver is Free
|
6
|
-
# Software. You can run/distribute/modify TextWeaver under the terms
|
7
|
-
# of the GNU Affero General Public License version 3. The Affero GPL
|
8
|
-
# states that running a modified version or a derivative work also
|
9
|
-
# requires you to make the sourcecode of that work available to
|
10
|
-
# everyone that can interact with it. We chose the Affero GPL to
|
11
|
-
# ensure that TextWeaver remains open and libre (doc/LICENSE.txt
|
12
|
-
# contains the full text of the legally binding license).
|
4
|
+
# MIT Licensed
|
13
5
|
#++#
|
14
6
|
#
|
15
7
|
# TextWeaver allows one to insert tags in a running text.
|
@@ -20,19 +12,15 @@
|
|
20
12
|
# You should only add stuff to the weaver via add_opening and
|
21
13
|
# add_closing.
|
22
14
|
|
23
|
-
|
24
|
-
|
15
|
+
require 'text_weaver/version'
|
16
|
+
require 'text_weaver/error'
|
17
|
+
require 'text_weaver/insert_position'
|
25
18
|
|
26
19
|
class TextWeaver
|
27
20
|
### Attributes
|
28
21
|
|
29
22
|
attr_accessor :text
|
30
|
-
end
|
31
23
|
|
32
|
-
require 'text_weaver/error'
|
33
|
-
require 'text_weaver/insert_position'
|
34
|
-
|
35
|
-
class TextWeaver
|
36
24
|
### Constructors
|
37
25
|
|
38
26
|
# Initializes a new TextWeaver.
|
data/lib/text_weaver/error.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
#--#
|
2
|
-
# Copyright: (c) 2008 The LogiLogi Foundation <foundation@logilogi.org>
|
3
|
-
#
|
4
|
-
# License:
|
5
|
-
# This file is part of the TextWeaver Library. TextWeaver is Free
|
6
|
-
# Software. You can run/distribute/modify TextWeaver under the terms
|
7
|
-
# of the GNU Affero General Public License version 3. The Affero GPL
|
8
|
-
# states that running a modified version or a derivative work also
|
9
|
-
# requires you to make the sourcecode of that work available to
|
10
|
-
# everyone that can interact with it. We chose the Affero GPL to
|
11
|
-
# ensure that TextWeaver remains open and libre (doc/LICENSE.txt
|
12
|
-
# contains the full text of the legally binding license).
|
13
|
-
#++#
|
14
|
-
#
|
15
1
|
# This Error is raised if insert-positions err.
|
16
2
|
|
17
3
|
class TextWeaver::Error < StandardError
|
@@ -1,17 +1,3 @@
|
|
1
|
-
#--#
|
2
|
-
# Copyright: (c) 2008 The LogiLogi Foundation <foundation@logilogi.org>
|
3
|
-
#
|
4
|
-
# License:
|
5
|
-
# This file is part of the TextWeaver Library. TextWeaver is Free
|
6
|
-
# Software. You can run/distribute/modify TextWeaver under the terms
|
7
|
-
# of the GNU Affero General Public License version 3. The Affero GPL
|
8
|
-
# states that running a modified version or a derivative work also
|
9
|
-
# requires you to make the sourcecode of that work available to
|
10
|
-
# everyone that can interact with it. We chose the Affero GPL to
|
11
|
-
# ensure that TextWeaver remains open and libre (doc/LICENSE.txt
|
12
|
-
# contains the full text of the legally binding license).
|
13
|
-
#++#
|
14
|
-
#
|
15
1
|
# BodyPositions allow one to point to a position in a Logi, and insert
|
16
2
|
# some text there.
|
17
3
|
|
data/lib/text_weaver/version.rb
CHANGED
data/test/helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
['rubygems', 'require_relative'].each {|g| require g} if RUBY_VERSION =~ /1\.8/
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
class InsertPositionTest < Test::Unit::TestCase
|
5
|
+
### Initialization
|
6
|
+
|
7
|
+
def test_initialize
|
8
|
+
i_p = TextWeaver::InsertPosition.new(10,2,'mooo')
|
9
|
+
assert_equal 10, i_p.position
|
10
|
+
assert_equal 2, i_p.set
|
11
|
+
assert_equal 'mooo', i_p.text
|
12
|
+
end
|
13
|
+
|
14
|
+
### Methods
|
15
|
+
|
16
|
+
def test_compare
|
17
|
+
# positions
|
18
|
+
assert TextWeaver::InsertPosition.new(10,2,'a') > TextWeaver::InsertPosition.new(9,2,'a')
|
19
|
+
assert TextWeaver::InsertPosition.new(9,2,'a') < TextWeaver::InsertPosition.new(10,2,'a')
|
20
|
+
|
21
|
+
# sets
|
22
|
+
assert TextWeaver::InsertPosition.new(0,2,'a') > TextWeaver::InsertPosition.new(0,1,'a')
|
23
|
+
assert TextWeaver::InsertPosition.new(0,1,'a') < TextWeaver::InsertPosition.new(0,2,'a')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_exceptions
|
27
|
+
assert_raise(TextWeaver::Error) {
|
28
|
+
TextWeaver::InsertPosition.new(-1,2,'a')
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_raise(TextWeaver::Error) {
|
32
|
+
TextWeaver::InsertPosition.new(10,2,'a') > TextWeaver::InsertPosition.new(10,2,'a')
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
['rubygems', 'require_relative'].each {|g| require g} if RUBY_VERSION =~ /1\.8/
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
class TextWeaverTest < Test::Unit::TestCase
|
5
|
+
### Initialization
|
6
|
+
|
7
|
+
def test_initialize
|
8
|
+
w = TextWeaver.new('kukadopalala')
|
9
|
+
assert_equal 'kukadopalala', w.text
|
10
|
+
end
|
11
|
+
|
12
|
+
### Methods
|
13
|
+
|
14
|
+
def test_next_set
|
15
|
+
w = TextWeaver.new('abc')
|
16
|
+
w.add_opening(1, ';')
|
17
|
+
w.next_set
|
18
|
+
w.add_opening(1, ':')
|
19
|
+
assert_equal 'a;:bc', w.weave
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_add_opening
|
23
|
+
w = TextWeaver.new('abc')
|
24
|
+
w.add_opening(1, '1')
|
25
|
+
w.next_set
|
26
|
+
w.add_opening(1, '2')
|
27
|
+
assert_equal 'a12bc', w.weave
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_add_closing
|
31
|
+
w = TextWeaver.new('abc')
|
32
|
+
w.add_closing(1, '1')
|
33
|
+
w.next_set
|
34
|
+
w.add_closing(1, '2')
|
35
|
+
assert_equal 'a21bc', w.weave
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_weave
|
39
|
+
# simple
|
40
|
+
w = TextWeaver.new('abcde')
|
41
|
+
w.add_opening(1, '(')
|
42
|
+
w.add_closing(4, ')')
|
43
|
+
w.next_set
|
44
|
+
w.add_opening(1, '<')
|
45
|
+
w.add_closing(4, '>')
|
46
|
+
assert_equal 'a(<bcd>)e', w.weave
|
47
|
+
|
48
|
+
# side by side
|
49
|
+
w2 = TextWeaver.new('abcdef')
|
50
|
+
w2.add_opening(1, '(')
|
51
|
+
w2.add_closing(3, ')')
|
52
|
+
w2.add_opening(3, '<')
|
53
|
+
w2.add_closing(5, '>')
|
54
|
+
assert_equal 'a(bc)<de>f', w2.weave
|
55
|
+
|
56
|
+
# multi weave
|
57
|
+
w3 = TextWeaver.new('abcde')
|
58
|
+
w3.add_opening(1, '(')
|
59
|
+
w3.add_closing(4, ')')
|
60
|
+
assert_equal 'a(bcd)e', w3.weave
|
61
|
+
|
62
|
+
w3.next_set
|
63
|
+
w3.add_opening(1, '<')
|
64
|
+
w3.add_closing(4, '>')
|
65
|
+
assert_equal 'a(<bcd>)e', w3.weave
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_exceptions
|
69
|
+
w = TextWeaver.new('abc')
|
70
|
+
|
71
|
+
assert_raise(TextWeaver::Error) {
|
72
|
+
w.add_closing(-1, 'a')
|
73
|
+
}
|
74
|
+
|
75
|
+
assert_raise(TextWeaver::Error) {
|
76
|
+
w.add_opening(4, 'a')
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
data/textweaver.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/text_weaver/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Wybo Wiersma']
|
6
|
+
gem.email = ['mail@wybowiersma.net']
|
7
|
+
gem.description = 'Weaves html tags (or really anything) into a text at given opening or closing positions. Inserted tags need to be aligned (that is non-overlapping) in order to be inserted. Opening and closing tags are inserted and kept in order. Inspired by Ted Nelsons project Xanadu.'
|
8
|
+
gem.summary = 'Weaves tags into a text at given positions'
|
9
|
+
gem.homepage = 'http://github.com/wybo/textweaver'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.test_files = gem.files.grep(%r{^test/test_.*})
|
13
|
+
gem.name = 'textweaver'
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = TextWeaver::VERSION
|
16
|
+
|
17
|
+
gem.add_development_dependency 'rake'
|
18
|
+
gem.add_development_dependency 'test-unit'
|
19
|
+
gem.add_development_dependency 'require_relative'
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textweaver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 13
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 5
|
10
|
+
version: 0.6.5
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Wybo Wiersma
|
@@ -9,12 +15,54 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2012-06-25 00:00:00 -07:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
version_requirements: *id001
|
32
|
+
name: rake
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
version_requirements: *id002
|
46
|
+
name: test-unit
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
version_requirements: *id003
|
60
|
+
name: require_relative
|
61
|
+
prerelease: false
|
62
|
+
type: :development
|
63
|
+
description: Weaves html tags (or really anything) into a text at given opening or closing positions. Inserted tags need to be aligned (that is non-overlapping) in order to be inserted. Opening and closing tags are inserted and kept in order. Inspired by Ted Nelsons project Xanadu.
|
64
|
+
email:
|
65
|
+
- mail@wybowiersma.net
|
18
66
|
executables: []
|
19
67
|
|
20
68
|
extensions: []
|
@@ -22,21 +70,23 @@ extensions: []
|
|
22
70
|
extra_rdoc_files: []
|
23
71
|
|
24
72
|
files:
|
25
|
-
-
|
26
|
-
- install.rb
|
27
|
-
- README
|
73
|
+
- .gitignore
|
28
74
|
- CHANGELOG
|
75
|
+
- Gemfile
|
29
76
|
- LICENSE
|
30
|
-
-
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/text_weaver.rb
|
31
80
|
- lib/text_weaver/error.rb
|
32
81
|
- lib/text_weaver/insert_position.rb
|
82
|
+
- lib/text_weaver/version.rb
|
33
83
|
- lib/textweaver.rb
|
34
|
-
-
|
35
|
-
- test/
|
36
|
-
- test/
|
37
|
-
-
|
84
|
+
- test/helper.rb
|
85
|
+
- test/test_insert_position.rb
|
86
|
+
- test/test_text_weaver.rb
|
87
|
+
- textweaver.gemspec
|
38
88
|
has_rdoc: true
|
39
|
-
homepage: http://textweaver
|
89
|
+
homepage: http://github.com/wybo/textweaver
|
40
90
|
licenses: []
|
41
91
|
|
42
92
|
post_install_message:
|
@@ -45,23 +95,30 @@ rdoc_options: []
|
|
45
95
|
require_paths:
|
46
96
|
- lib
|
47
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
48
99
|
requirements:
|
49
100
|
- - ">="
|
50
101
|
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
51
105
|
version: "0"
|
52
|
-
version:
|
53
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
54
108
|
requirements:
|
55
109
|
- - ">="
|
56
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
57
114
|
version: "0"
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
rubygems_version: 1.3.4
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.6.2
|
63
119
|
signing_key:
|
64
120
|
specification_version: 3
|
65
|
-
summary: Weaves
|
66
|
-
test_files:
|
67
|
-
|
121
|
+
summary: Weaves tags into a text at given positions
|
122
|
+
test_files:
|
123
|
+
- test/test_insert_position.rb
|
124
|
+
- test/test_text_weaver.rb
|
data/README
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
= Text Weaver Gem documentation
|
2
|
-
"Weaves any-tag into any text"
|
3
|
-
|
4
|
-
Weaves html tags (or really anything) into a text at given
|
5
|
-
opening or closing positions. Inserted tags need to be aligned
|
6
|
-
(that is non-overlapping) in order to be inserted.
|
7
|
-
|
8
|
-
Opening and closing tags are inserted and kept in order.
|
9
|
-
|
10
|
-
TextWeaver is a library by the LogiLogi Foundation, extracted from
|
11
|
-
http://www.logilogi.org (http://foundation.logilogi.org).
|
12
|
-
|
13
|
-
== Usage
|
14
|
-
|
15
|
-
First require it.
|
16
|
-
|
17
|
-
$ irb
|
18
|
-
|
19
|
-
> require 'rubygems'
|
20
|
-
> require 'textweaver'
|
21
|
-
|
22
|
-
You can create a TextWeaver with any text.
|
23
|
-
|
24
|
-
> w = TextWeaver.new("abcde")
|
25
|
-
|
26
|
-
Then add some openings and closings.
|
27
|
-
|
28
|
-
> w.add_opening(1, "(")
|
29
|
-
> w.add_closing(4, ")")
|
30
|
-
|
31
|
-
> w.weave
|
32
|
-
=> "a(bcd)e"
|
33
|
-
|
34
|
-
Possibly with additionally some different tag-types.
|
35
|
-
|
36
|
-
> w.next_set
|
37
|
-
|
38
|
-
> w.add_opening(1, "<")
|
39
|
-
> w.add_closing(4, ">")
|
40
|
-
|
41
|
-
> w.weave
|
42
|
-
=> "a(<bcd>)e"
|
43
|
-
|
44
|
-
== Installation
|
45
|
-
|
46
|
-
You can install Text Weaver with the following command:
|
47
|
-
|
48
|
-
% [sudo] gem install textweaver
|
49
|
-
|
50
|
-
The latest version of Text Weaver can also be downloaded at:
|
51
|
-
|
52
|
-
* http://rubyforge.org/frs/?group_id=7566
|
53
|
-
|
54
|
-
And then from its distribution directory installed with:
|
55
|
-
|
56
|
-
% [sudo] ruby install.rb
|
57
|
-
|
58
|
-
== Support
|
59
|
-
|
60
|
-
The Text Weaver homepage is http://textweaver.rubyforge.org.
|
61
|
-
|
62
|
-
For the latest news on Text Weaver:
|
63
|
-
|
64
|
-
* http://foundation.logilogi.org/tags/TextWeaver
|
65
|
-
|
66
|
-
Feel free to submit commits or feature requests. If you send a patch,
|
67
|
-
remember to update the corresponding unit tests.
|
68
|
-
|
69
|
-
== This Documentation
|
70
|
-
|
71
|
-
This documentation can be browsed online at:
|
72
|
-
|
73
|
-
* http://textweaver.rubyforge.org
|
74
|
-
|
75
|
-
== Copyrights
|
76
|
-
|
77
|
-
Text Weaver and these docs are Copyright (c) 2006-2009 The LogiLogi
|
78
|
-
Foundation. Text Weaver is licensed under the {GNU Lesser General
|
79
|
-
Public License}[http://www.gnu.org/licenses/lgpl-3.0-standalone.html].
|
80
|
-
These docs are available under the {Creative Commons Attribution-Share
|
81
|
-
Alike License}[http://creativecommons.org/licenses/by-sa/3.0/].
|
82
|
-
|
83
|
-
You can use Text Weaver in an application that is not Free Software
|
84
|
-
but Text Weaver itself remains Free Software.
|
data/install.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'find'
|
3
|
-
require 'ftools'
|
4
|
-
|
5
|
-
include Config
|
6
|
-
|
7
|
-
# this was adapted from rdoc's install.rb by way of Log4r
|
8
|
-
|
9
|
-
$sitedir = CONFIG["sitelibdir"]
|
10
|
-
unless $sitedir
|
11
|
-
version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
|
12
|
-
$libdir = File.join(CONFIG["libdir"], "ruby", version)
|
13
|
-
$sitedir = $:.find {|x| x =~ /site_ruby/ }
|
14
|
-
if !$sitedir
|
15
|
-
$sitedir = File.join($libdir, "site_ruby")
|
16
|
-
elsif $sitedir !~ Regexp.quote(version)
|
17
|
-
$sitedir = File.join($sitedir, version)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# the actual gruntwork
|
22
|
-
Dir.chdir("lib")
|
23
|
-
|
24
|
-
Find.find("text_weaver", "text_weaver.rb") { |f|
|
25
|
-
if f[-3..-1] == ".rb"
|
26
|
-
File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
|
27
|
-
else
|
28
|
-
File::makedirs(File.join($sitedir, *f.split(/\//)))
|
29
|
-
end
|
30
|
-
}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
#--#
|
2
|
-
# Copyright: (c) 2006-2008 The LogiLogi Foundation <foundation@logilogi.org>
|
3
|
-
#
|
4
|
-
# License:
|
5
|
-
# This file is part of the TextWeaver Library. TextWeaver is Free Software.
|
6
|
-
# You can run/distribute/modify TextWeaver under the terms of the GNU
|
7
|
-
# Affero General Public License version 3. The Affero GPL states
|
8
|
-
# that running a modified version or a derivative work also requires
|
9
|
-
# you to make the sourcecode of that work available to everyone that
|
10
|
-
# can interact with it. We chose the Affero GPL to ensure that
|
11
|
-
# TextWeaver remains open and libre (doc/LICENSE.txt contains the full
|
12
|
-
# text of the legally binding license).
|
13
|
-
#++#
|
14
|
-
|
15
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
16
|
-
|
17
|
-
class InsertPositionTest < Test::Unit::TestCase
|
18
|
-
### Initialization
|
19
|
-
|
20
|
-
def test_initialize
|
21
|
-
i_p = TextWeaver::InsertPosition.new(10,2,"mooo")
|
22
|
-
assert_equal 10, i_p.position
|
23
|
-
assert_equal 2, i_p.set
|
24
|
-
assert_equal "mooo", i_p.text
|
25
|
-
end
|
26
|
-
|
27
|
-
### Methods
|
28
|
-
|
29
|
-
def test_compare
|
30
|
-
# positions
|
31
|
-
assert TextWeaver::InsertPosition.new(10,2,"a") > TextWeaver::InsertPosition.new(9,2,"a")
|
32
|
-
assert TextWeaver::InsertPosition.new(9,2,"a") < TextWeaver::InsertPosition.new(10,2,"a")
|
33
|
-
|
34
|
-
# sets
|
35
|
-
assert TextWeaver::InsertPosition.new(0,2,"a") > TextWeaver::InsertPosition.new(0,1,"a")
|
36
|
-
assert TextWeaver::InsertPosition.new(0,1,"a") < TextWeaver::InsertPosition.new(0,2,"a")
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_exceptions
|
40
|
-
assert_raise(TextWeaver::Error) {
|
41
|
-
TextWeaver::InsertPosition.new(-1,2,"a")
|
42
|
-
}
|
43
|
-
|
44
|
-
assert_raise(TextWeaver::Error) {
|
45
|
-
TextWeaver::InsertPosition.new(10,2,"a") > TextWeaver::InsertPosition.new(10,2,"a")
|
46
|
-
}
|
47
|
-
end
|
48
|
-
end
|
data/test/test_helper.rb
DELETED
data/test/text_weaver_test.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
#--#
|
2
|
-
# Copyright: (c) 2006-2008 The LogiLogi Foundation <foundation@logilogi.org>
|
3
|
-
#
|
4
|
-
# License:
|
5
|
-
# This file is part of the TextWeaver Library. TextWeaver is Free Software.
|
6
|
-
# You can run/distribute/modify TextWeaver under the terms of the GNU
|
7
|
-
# Affero General Public License version 3. The Affero GPL states
|
8
|
-
# that running a modified version or a derivative work also requires
|
9
|
-
# you to make the sourcecode of that work available to everyone that
|
10
|
-
# can interact with it. We chose the Affero GPL to ensure that
|
11
|
-
# TextWeaver remains open and libre (doc/LICENSE.txt contains the full
|
12
|
-
# text of the legally binding license).
|
13
|
-
#++#
|
14
|
-
|
15
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
16
|
-
|
17
|
-
class TextWeaverTest < Test::Unit::TestCase
|
18
|
-
### Initialization
|
19
|
-
|
20
|
-
def test_initialize
|
21
|
-
w = TextWeaver.new("kukadopalala")
|
22
|
-
assert_equal "kukadopalala", w.text
|
23
|
-
end
|
24
|
-
|
25
|
-
### Methods
|
26
|
-
|
27
|
-
def test_next_set
|
28
|
-
w = TextWeaver.new("abc")
|
29
|
-
w.add_opening(1, ";")
|
30
|
-
w.next_set
|
31
|
-
w.add_opening(1, ":")
|
32
|
-
assert_equal "a;:bc", w.weave
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_add_opening
|
36
|
-
w = TextWeaver.new("abc")
|
37
|
-
w.add_opening(1, "1")
|
38
|
-
w.next_set
|
39
|
-
w.add_opening(1, "2")
|
40
|
-
assert_equal "a12bc", w.weave
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_add_closing
|
44
|
-
w = TextWeaver.new("abc")
|
45
|
-
w.add_closing(1, "1")
|
46
|
-
w.next_set
|
47
|
-
w.add_closing(1, "2")
|
48
|
-
assert_equal "a21bc", w.weave
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_weave
|
52
|
-
# simple
|
53
|
-
w = TextWeaver.new("abcde")
|
54
|
-
w.add_opening(1, "(")
|
55
|
-
w.add_closing(4, ")")
|
56
|
-
w.next_set
|
57
|
-
w.add_opening(1, "<")
|
58
|
-
w.add_closing(4, ">")
|
59
|
-
assert_equal "a(<bcd>)e", w.weave
|
60
|
-
|
61
|
-
# side by side
|
62
|
-
w2 = TextWeaver.new("abcdef")
|
63
|
-
w2.add_opening(1, "(")
|
64
|
-
w2.add_closing(3, ")")
|
65
|
-
w2.add_opening(3, "<")
|
66
|
-
w2.add_closing(5, ">")
|
67
|
-
assert_equal "a(bc)<de>f", w2.weave
|
68
|
-
|
69
|
-
# multi weave
|
70
|
-
w3 = TextWeaver.new("abcde")
|
71
|
-
w3.add_opening(1, "(")
|
72
|
-
w3.add_closing(4, ")")
|
73
|
-
assert_equal "a(bcd)e", w3.weave
|
74
|
-
|
75
|
-
w3.next_set
|
76
|
-
w3.add_opening(1, "<")
|
77
|
-
w3.add_closing(4, ">")
|
78
|
-
assert_equal "a(<bcd>)e", w3.weave
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_exceptions
|
82
|
-
w = TextWeaver.new("abc")
|
83
|
-
|
84
|
-
assert_raise(TextWeaver::Error) {
|
85
|
-
w.add_closing(-1, "a")
|
86
|
-
}
|
87
|
-
|
88
|
-
assert_raise(TextWeaver::Error) {
|
89
|
-
w.add_opening(4, "a")
|
90
|
-
}
|
91
|
-
end
|
92
|
-
end
|