manilla 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/manilla.rb +50 -0
- data/lib/manilla/folder.rb +47 -0
- data/lib/manilla/unfolder.rb +11 -0
- data/lib/manilla/version.rb +5 -0
- data/manilla.gemspec +31 -0
- metadata +110 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Anthony Smith
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# Manilla
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sticksnleaves/manilla.svg?branch=master)](https://travis-ci.org/sticksnleaves/manilla)
|
4
|
+
|
5
|
+
Text folding for the Rubyist
|
6
|
+
|
7
|
+
Go from this:
|
8
|
+
|
9
|
+
```
|
10
|
+
Hello, world!
|
11
|
+
```
|
12
|
+
|
13
|
+
to this:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Manilla.fold('Hello, world!', 8, "\r\n\s", :word)
|
17
|
+
# => Hello,
|
18
|
+
# world!
|
19
|
+
```
|
20
|
+
|
21
|
+
and back again:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Manilla.unfold("Hello,\r\n world!", "\r\n\s")
|
25
|
+
# => Hello, world!
|
26
|
+
```
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'manilla'
|
34
|
+
```
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
Or install it yourself as:
|
41
|
+
|
42
|
+
$ gem install manilla
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
Manilla provides two methods for folding text: **character** and **word**
|
47
|
+
|
48
|
+
### Character Folding
|
49
|
+
|
50
|
+
Folding on character will instruct Manilla to insert a fold at a specific width.
|
51
|
+
It will not pay attention to word boundaries or any other delimiter. Character
|
52
|
+
folding is the default folding method.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Manilla.fold('Hello, world!', 8, "\r\n\s")
|
56
|
+
# => Hello, w
|
57
|
+
# orld!
|
58
|
+
```
|
59
|
+
|
60
|
+
### Word Folding
|
61
|
+
|
62
|
+
Word folding will cause Manilla to break text at word boundaries.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
Manilla.fold('Hello, world!', 8, "\r\n\s", :word)
|
66
|
+
# => Hello,
|
67
|
+
# world!
|
68
|
+
```
|
69
|
+
|
70
|
+
If a word is longer than the specified max width it will be folded at max width.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Manilla.fold('Hello, world!', 2, "\r\n\s", :word)
|
74
|
+
# => He
|
75
|
+
# ll
|
76
|
+
# o,
|
77
|
+
#
|
78
|
+
# wo
|
79
|
+
# rl
|
80
|
+
# d!
|
81
|
+
```
|
82
|
+
|
83
|
+
### Unfolding
|
84
|
+
|
85
|
+
Unfolding is the process of reversing a fold. It will treat delimiters as blank
|
86
|
+
strings.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
folded_text = Manilla.fold('Hello, world!', 8, "\r\n\s", :word)
|
90
|
+
|
91
|
+
Manilla.unfold(folded_text, "\r\n\s")
|
92
|
+
# => Hello, world!
|
93
|
+
```
|
94
|
+
|
95
|
+
## API
|
96
|
+
|
97
|
+
### ```Manilla.fold(text, maxwidth, delimiter, break_on)```
|
98
|
+
|
99
|
+
Fold text using the specified delimiter at a maximum width. Folding can occur on
|
100
|
+
```:char``` or ```:word```.
|
101
|
+
|
102
|
+
### ```Manilla.unfold(text, delimiter)```
|
103
|
+
|
104
|
+
Unfold text using a specified delimiter.
|
105
|
+
|
106
|
+
## Development
|
107
|
+
|
108
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
109
|
+
|
110
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
1. Fork it ( https://github.com/[my-github-username]/manilla/fork )
|
115
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
116
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
117
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
118
|
+
5. Create a new Pull Request
|
119
|
+
|
120
|
+
## Credits
|
121
|
+
|
122
|
+
[![Sticksnleaves](https://s3.amazonaws.com/sticksnleaves-assets/snl-logo-116x116.png)](http://www.sticksnleaves.com)
|
123
|
+
|
124
|
+
Manilla is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com)
|
125
|
+
|
126
|
+
Thanks to all of our [contributors](https://github.com/sticksnleaves/manilla/graphs/contributors)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'manilla'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/manilla.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'manilla/folder'
|
2
|
+
require 'manilla/unfolder'
|
3
|
+
|
4
|
+
require 'manilla/version'
|
5
|
+
|
6
|
+
module Manilla
|
7
|
+
#
|
8
|
+
# Breaks long lines of text into multiple delimited representations.
|
9
|
+
#
|
10
|
+
# @example Fold text on character
|
11
|
+
# Manilla.fold('Hello, world!', 8, "\r\n\s")
|
12
|
+
# => Hello, w
|
13
|
+
# orld!
|
14
|
+
#
|
15
|
+
# @example Fold text on word
|
16
|
+
# Manilla.fold('Hello, world!', 8, "\r\n\s", :word)
|
17
|
+
# => Hello,
|
18
|
+
# world!
|
19
|
+
#
|
20
|
+
# @param text [String] The text to be folded
|
21
|
+
# @param maxwidth [Integer] The maximum length of a line of text
|
22
|
+
# @param delimiter [String] String used to denote line boundaries
|
23
|
+
# @param break_on [Symbol] Specifies whether to fold text on a character
|
24
|
+
# (`:char`) or word (`:word`) (default: `:char`)
|
25
|
+
#
|
26
|
+
def self.fold(text, maxwidth, delimiter, break_on = :char)
|
27
|
+
Manilla::Folder.call(text, maxwidth, delimiter, break_on)
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Moves from a folded delimited representation to a single line
|
32
|
+
# representation by treating delimiters as blank strings.
|
33
|
+
#
|
34
|
+
# @example Unfold text
|
35
|
+
# text = "Hello, world!"
|
36
|
+
#
|
37
|
+
# folded_text = Manilla.fold(text, 8, "\r\n", :word)
|
38
|
+
# => Hello,
|
39
|
+
# world!
|
40
|
+
#
|
41
|
+
# Manilla.unfold(folded_text, "\r\n")
|
42
|
+
# => Hello, world!
|
43
|
+
#
|
44
|
+
# @param text [String] Text to be unfolded
|
45
|
+
# @param delimiter [String] String used to denote line boundaries
|
46
|
+
#
|
47
|
+
def self.unfold(text, delimiter)
|
48
|
+
Manilla::Unfolder.call(text, delimiter)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Manilla
|
2
|
+
#
|
3
|
+
# Breaks long logical lines of text into multiple delimited representations.
|
4
|
+
# Lines can be folded into a set width of octets excluding line breaks.
|
5
|
+
#
|
6
|
+
module Folder
|
7
|
+
def self.call(text, maxwidth, delimiter, break_on)
|
8
|
+
lines = []
|
9
|
+
|
10
|
+
value = text.strip
|
11
|
+
value = value.gsub(/\n+/, '')
|
12
|
+
value = value.gsub(/\s{2,}/, '')
|
13
|
+
|
14
|
+
while value.size > maxwidth
|
15
|
+
count = maxwidth
|
16
|
+
|
17
|
+
while count
|
18
|
+
break_index = nil
|
19
|
+
break_pos = nil
|
20
|
+
line = value[0, count]
|
21
|
+
|
22
|
+
if break_on == :word
|
23
|
+
break_index = line.rindex(/\s/)
|
24
|
+
break_pos = break_index + 1 if break_index
|
25
|
+
line = line[0, break_pos] if break_pos
|
26
|
+
|
27
|
+
count = break_pos || maxwidth
|
28
|
+
end
|
29
|
+
|
30
|
+
oct = line.size
|
31
|
+
|
32
|
+
if oct > maxwidth
|
33
|
+
count -= oct - maxwidth
|
34
|
+
else
|
35
|
+
lines << line
|
36
|
+
value = value[count, value.size]
|
37
|
+
break
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
lines << value unless value.strip.empty?
|
43
|
+
|
44
|
+
lines.join(delimiter)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/manilla.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'manilla/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'manilla'
|
8
|
+
spec.version = Manilla::VERSION
|
9
|
+
spec.authors = ['Anthony Smith']
|
10
|
+
spec.email = ['anthony@sticksnleaves.com']
|
11
|
+
|
12
|
+
spec.summary = 'Keep your text nice and tidy'
|
13
|
+
spec.description = 'Break long logical lines of text into multiple
|
14
|
+
delimited representations'
|
15
|
+
spec.homepage = 'https://github.com/sticksnleaves/manilla.git'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = (
|
19
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(/^(test|spec|features)\//)
|
21
|
+
end
|
22
|
+
)
|
23
|
+
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rspec'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: manilla
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anthony Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
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: rspec
|
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
|
+
description: ! "Break long logical lines of text into multiple\n delimited
|
63
|
+
representations"
|
64
|
+
email:
|
65
|
+
- anthony@sticksnleaves.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- .travis.yml
|
73
|
+
- CODE_OF_CONDUCT.md
|
74
|
+
- Gemfile
|
75
|
+
- LICENSE.txt
|
76
|
+
- README.md
|
77
|
+
- Rakefile
|
78
|
+
- bin/console
|
79
|
+
- bin/setup
|
80
|
+
- lib/manilla.rb
|
81
|
+
- lib/manilla/folder.rb
|
82
|
+
- lib/manilla/unfolder.rb
|
83
|
+
- lib/manilla/version.rb
|
84
|
+
- manilla.gemspec
|
85
|
+
homepage: https://github.com/sticksnleaves/manilla.git
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.23.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Keep your text nice and tidy
|
110
|
+
test_files: []
|