testytest2 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +7 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/lib/testytest2.rb +12 -0
- data/testytest2.gemspec +23 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2920c6897fa438edd927dff5c6e8959dccd9313
|
4
|
+
data.tar.gz: ba655425ed5c59068fdd791a79e6100d9cf4fc29
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8a4c5a27f2faf9e4b0cd8e55099dbbebd6a840e6c892dce883b14182cafabe3d191fd0078a0494e3a9469c4591cccc80601db40bb8faca2ced394ccf32406ff
|
7
|
+
data.tar.gz: 9f46b53919dd7e577044168c8061420145b90eb98834c6782280b665fd1e4fa67ffcb9f41a181d5101829d41133c2e31f1eeff73b5431d4e8f8a4f26d385a5b5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Caleb Spare
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
ruby-dedent
|
2
|
+
===========
|
3
|
+
|
4
|
+
Installation
|
5
|
+
------------
|
6
|
+
|
7
|
+
gem install dedent
|
8
|
+
|
9
|
+
Only tested with Ruby 1.9.2 and 1.8.7.
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
This is a tiny gem that adds the `dedent` method to String. This method strips leading whitespace from each
|
15
|
+
line, preserving indentation. So, the line with the least amount of leading whitespace will have all leading
|
16
|
+
whitespace removed, while other lines will have whitespace relative to that line's offset.
|
17
|
+
|
18
|
+
The main use of this is with heredocs. It can be annoying because even with the `<<-` form of heredocs, all
|
19
|
+
the initial whitespace on each line of the string is preserved, so if you keep the string in the same
|
20
|
+
indentation as the code, you end up with a bunch of extra space.
|
21
|
+
|
22
|
+
Here's an example of using dedent with heredocs:
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
# Suppose we're already at some indentation within the code.
|
26
|
+
foo = <<-EOS.dedent
|
27
|
+
This might be a usage banner for a cli tool. Or, it might be some javascript. Or maybe shell code.
|
28
|
+
for f in $(ls /foo/bar/); do
|
29
|
+
cat $f >> $myfile;
|
30
|
+
done
|
31
|
+
EOS
|
32
|
+
```
|
33
|
+
|
34
|
+
Now the `foo` variable contains the following string:
|
35
|
+
|
36
|
+
```
|
37
|
+
This might be a usage banner for a cli tool. Or, it might be some javascript. Or maybe shell code.
|
38
|
+
for f in $(ls /foo/bar/); do
|
39
|
+
cat $f >> $myfile;
|
40
|
+
done
|
41
|
+
```
|
42
|
+
|
43
|
+
One thing to note is that lines with no non-whitespaces characters are not considered when determining the
|
44
|
+
indentation of a text block:
|
45
|
+
|
46
|
+
```
|
47
|
+
"\n foo".dedent # => "\nfoo"
|
48
|
+
```
|
49
|
+
|
50
|
+
Author
|
51
|
+
------
|
52
|
+
|
53
|
+
This gem was written by Caleb Spare ([cespare](https://github.com/cespare) on github). It was inspired by
|
54
|
+
[Coffeescript's heredocs](http://jashkenas.github.com/coffee-script/#strings).
|
55
|
+
|
56
|
+
License
|
57
|
+
-------
|
58
|
+
|
59
|
+
This project is release under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/testytest2.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class String
|
2
|
+
def dedent
|
3
|
+
lines = split "\n"
|
4
|
+
return self if lines.empty?
|
5
|
+
indents = lines.map do |line|
|
6
|
+
line =~ /\S/ ? (line.start_with?(" ") ? line.match(/^ +/).offset(0)[1] : 0) : nil
|
7
|
+
end
|
8
|
+
min_indent = indents.compact.min
|
9
|
+
return self if min_indent.zero?
|
10
|
+
lines.map { |line| line =~ /\S/ ? line.gsub(/^ {#{min_indent}}/, "") : line }.join "\n"
|
11
|
+
end
|
12
|
+
end
|
data/testytest2.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "testytest2"
|
6
|
+
s.version = "0.0.3"
|
7
|
+
s.authors = ["Caleb Spare"]
|
8
|
+
s.email = ["cespare@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/cespare/ruby-dedent"
|
10
|
+
s.summary = %q{Adds a dedent method to String.}
|
11
|
+
s.description = <<-EOS
|
12
|
+
This gem adds a dedent method to strings to strip leading spaces from each line while preserving indentation.
|
13
|
+
EOS
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
# s.add_development_dependency "rspec"
|
22
|
+
# s.add_runtime_dependency "rest-client"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testytest2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Spare
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
This gem adds a dedent method to strings to strip leading spaces from each line while preserving indentation.
|
15
|
+
email:
|
16
|
+
- cespare@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/testytest2.rb
|
27
|
+
- testytest2.gemspec
|
28
|
+
homepage: https://github.com/cespare/ruby-dedent
|
29
|
+
licenses: []
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.0.0
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Adds a dedent method to String.
|
51
|
+
test_files: []
|