linesetter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/LICENSE +24 -0
- data/README.md +33 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/linesetter +6 -0
- data/extras/Linesetter.tmCommand +24 -0
- data/lib/linesetter.rb +29 -0
- data/spec/linesetter_spec.rb +57 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +78 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Brad Fults.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
6
|
+
obtaining a copy of this software and associated documentation
|
7
|
+
files (the "Software"), to deal in the Software without
|
8
|
+
restriction, including without limitation the rights to use,
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the
|
11
|
+
Software is furnished to do so, subject to the following
|
12
|
+
conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Linesetter helps you reformat your paragraphs.
|
2
|
+
|
3
|
+
If you start out with ugly long lines of text, or unsightly short ones with a
|
4
|
+
ragged right edge, linesetter will whip your text back into shape by putting
|
5
|
+
as many words on each line that will fit in 78 characters, while retaining a
|
6
|
+
left-side indent of spaces.
|
7
|
+
|
8
|
+
## Example
|
9
|
+
|
10
|
+
### Before
|
11
|
+
|
12
|
+
We the People of the United States
|
13
|
+
in Order to form a more perfect Union, establish Justice, insure domestic Tranquility,
|
14
|
+
provide for the common defence, promote the general
|
15
|
+
Welfare
|
16
|
+
|
17
|
+
### After
|
18
|
+
|
19
|
+
We the People of the United States in Order to form a more perfect Union,
|
20
|
+
establish Justice, insure domestic Tranquility, provide for the common
|
21
|
+
defence, promote the general Welfare
|
22
|
+
|
23
|
+
Simple, easy, effective.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
gem install linesetter
|
28
|
+
|
29
|
+
## Optional TextMate Command
|
30
|
+
|
31
|
+
You can drag the `Linesetter.tmCommand` file from `extras/` into TextMate's
|
32
|
+
Bundle Editor to get a handy command that runs `linesetter` from TextMate. It's
|
33
|
+
set up with a default keyboard shortcut of `⌘+` (`⌘⇧=`).
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "linesetter"
|
8
|
+
gem.summary = %Q{A paragraph (re)formatter for text editing.}
|
9
|
+
gem.description = %Q{Reformats a given paragraph to fit on
|
10
|
+
78-character-wide lines, retaining the left indent in spaces.}
|
11
|
+
gem.email = "bfults@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/h3h/linesetter"
|
13
|
+
gem.authors = ["Brad Fults"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
$stderr.puts "Install jeweler if you want fancier rake tasks. Don't if not."
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
task :default => :spec
|
36
|
+
rescue LoadError
|
37
|
+
$stderr.puts "RSpec required to run tests."
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "linesetter #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
50
|
+
rescue LoadError
|
51
|
+
$stderr.puts "Rake::RDocTask required to build RDocs."
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/linesetter
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>beforeRunningCommand</key>
|
6
|
+
<string>nop</string>
|
7
|
+
<key>bundleUUID</key>
|
8
|
+
<string>DA8BC897-04C8-49E0-8B2F-441FF360034F</string>
|
9
|
+
<key>command</key>
|
10
|
+
<string>linesetter</string>
|
11
|
+
<key>fallbackInput</key>
|
12
|
+
<string>none</string>
|
13
|
+
<key>input</key>
|
14
|
+
<string>selection</string>
|
15
|
+
<key>keyEquivalent</key>
|
16
|
+
<string>@+</string>
|
17
|
+
<key>name</key>
|
18
|
+
<string>Reformat Paragraph with Linesetter (⌘+)</string>
|
19
|
+
<key>output</key>
|
20
|
+
<string>replaceSelectedText</string>
|
21
|
+
<key>uuid</key>
|
22
|
+
<string>FABD348C-2554-4501-ABE8-43655F0EB7B2</string>
|
23
|
+
</dict>
|
24
|
+
</plist>
|
data/lib/linesetter.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Linesetter is a paragraph (re)formatter for text editing.
|
4
|
+
# 2010-01-03 / Brad Fults <bfults@gmail.com>
|
5
|
+
# See LICENSE for license info.
|
6
|
+
|
7
|
+
module Linesetter
|
8
|
+
BOUNDARY = 78
|
9
|
+
|
10
|
+
def self.format(text)
|
11
|
+
indent = (text.match(/\A\s+/).to_s || '').length
|
12
|
+
text.gsub!(/\s*\n\s*/, ' ')
|
13
|
+
|
14
|
+
i = 0
|
15
|
+
lines = []
|
16
|
+
words = text.split(' ')
|
17
|
+
while words.size > 0
|
18
|
+
lines[i] ||= (' ' * indent)
|
19
|
+
if words.first.length + lines[i].length <= BOUNDARY
|
20
|
+
lines[i] << words.shift + ' '
|
21
|
+
else
|
22
|
+
i += 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
lines.map! {|line| line.rstrip}
|
27
|
+
return lines.join("\n")
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Linesetter do
|
4
|
+
|
5
|
+
it "should only trim trailing whitespace on a single-line input" do
|
6
|
+
Linesetter.format(" test ").should == " test"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should make a single line of > 78 chars into 2 lines" do
|
10
|
+
long_line = "We the People of the United States, in Order to form a more " +
|
11
|
+
"perfect Union, establish Justice,"
|
12
|
+
two_lines = "We the People of the United States, in Order to form a more " +
|
13
|
+
"perfect Union,\nestablish Justice,"
|
14
|
+
Linesetter.format(long_line).should == two_lines
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should make a single line of > 156 chars into 3 lines" do
|
18
|
+
long_line = "We the People of the United States, in Order to form a more " +
|
19
|
+
"perfect Union, establish Justice, insure domestic Tranquility, provide " +
|
20
|
+
"for the common defence,"
|
21
|
+
two_lines = "We the People of the United States, in Order to form a more " +
|
22
|
+
"perfect Union,\nestablish Justice, insure domestic Tranquility, provide " +
|
23
|
+
"for the common\ndefence,"
|
24
|
+
Linesetter.format(long_line).should == two_lines
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should make many lines of > 78 chars into many lines" do
|
28
|
+
long_line = "We the People of the United States, in Order to form a more " +
|
29
|
+
"perfect Union, establish\nJustice, insure domestic Tranquility, provide " +
|
30
|
+
"for the common defence, promote\nthe general Welfare, and secure the " +
|
31
|
+
"Blessings of Liberty to ourselves\nand our Posterity, do ordain and " +
|
32
|
+
"establish this Constitution for the United States of\nAmerica."
|
33
|
+
many_lines = "We the People of the United States, in Order to form a more "+
|
34
|
+
"perfect Union,\nestablish Justice, insure domestic Tranquility, provide " +
|
35
|
+
"for the common\ndefence, promote the general Welfare, and secure the " +
|
36
|
+
"Blessings of Liberty to\nourselves and our Posterity, do ordain and " +
|
37
|
+
"establish this Constitution for the\nUnited States of America."
|
38
|
+
Linesetter.format(long_line).should == many_lines
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should make many lines of > 78 chars with indentation into many lines" do
|
42
|
+
long_line = " We the People of the United States, in Order to form a " +
|
43
|
+
"more perfect Union, establish\n Justice, insure domestic " +
|
44
|
+
"Tranquility, provide for the common defence, promote\n the general " +
|
45
|
+
"Welfare, and secure the Blessings of Liberty to ourselves\n and our " +
|
46
|
+
"Posterity, do ordain and establish this Constitution for the United " +
|
47
|
+
"States of\n America."
|
48
|
+
many_lines = " We the People of the United States, in Order to form a " +
|
49
|
+
"more perfect Union,\n establish Justice, insure domestic " +
|
50
|
+
"Tranquility, provide for the common\n defence, promote the general " +
|
51
|
+
"Welfare, and secure the Blessings of Liberty\n to ourselves and our " +
|
52
|
+
"Posterity, do ordain and establish this Constitution\n for the " +
|
53
|
+
"United States of America."
|
54
|
+
Linesetter.format(long_line).should == many_lines
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linesetter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Fults
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-09 00:00:00 -08:00
|
13
|
+
default_executable: linesetter
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: |-
|
26
|
+
Reformats a given paragraph to fit on
|
27
|
+
78-character-wide lines, retaining the left indent in spaces.
|
28
|
+
email: bfults@gmail.com
|
29
|
+
executables:
|
30
|
+
- linesetter
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- VERSION
|
42
|
+
- bin/linesetter
|
43
|
+
- extras/Linesetter.tmCommand
|
44
|
+
- lib/linesetter.rb
|
45
|
+
- spec/linesetter_spec.rb
|
46
|
+
- spec/spec.opts
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/h3h/linesetter
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: A paragraph (re)formatter for text editing.
|
76
|
+
test_files:
|
77
|
+
- spec/linesetter_spec.rb
|
78
|
+
- spec/spec_helper.rb
|