format-stuff 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +23 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/format-stuff +51 -0
- data/bin/setup +8 -0
- data/format-stuff.gemspec +26 -0
- data/lib/format/stuff/version.rb +5 -0
- data/lib/format/stuff.rb +59 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2636c4bf09df48307ddce8abcbd58d1e8ffc04c7
|
4
|
+
data.tar.gz: 7f649db3dbc36025dfbf149f49513df991f7ec1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1fd90dfbdaa75c7a24c4c7f195c0e1ac93d4b80adff0597671ca7c97a640c29464fdb467118163953e2bc5f6eb4c45d6d45197dbd88a2df015d6fc28a428c241
|
7
|
+
data.tar.gz: f96be03c116b87b11bbaf373e13234120db1c9cec388a302c5b432edfaf3ca32cca97ea8f43190669d81e318633a74fbe73959ebc50bb6778c386fbaa48ebb72
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
format-stuff
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Format::Stuff
|
2
|
+
|
3
|
+
Format stuff is meant as a minimal tool to format source-code like files.
|
4
|
+
It does not understand languages, but only indentations.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Simply do `gem install format-stuff`.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Please check `format-stuff -h` for the commandline.
|
13
|
+
|
14
|
+
## Development
|
15
|
+
|
16
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
17
|
+
|
18
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/format-stuff.
|
23
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "format/stuff"
|
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/format-stuff
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
4
|
+
|
5
|
+
require 'format/stuff'
|
6
|
+
|
7
|
+
begin
|
8
|
+
if ARGV.size == 2
|
9
|
+
indent = ' '
|
10
|
+
input = ARGV[0]
|
11
|
+
output = ARGV[1]
|
12
|
+
elsif ARGV.size == 3
|
13
|
+
indent = ARGV[0]
|
14
|
+
indent = indent.split('=')
|
15
|
+
raise 'indent must have =' unless indent.size == 2
|
16
|
+
raise 'indent must start with --indent' unless indent.first == '--indent'
|
17
|
+
indent = indent.last
|
18
|
+
input = ARGV[1]
|
19
|
+
output = ARGV[2]
|
20
|
+
else
|
21
|
+
raise 'cannot understand'
|
22
|
+
end
|
23
|
+
rescue
|
24
|
+
puts [
|
25
|
+
"Usage: #{__FILE__} [--indent=string] input output",
|
26
|
+
" --indent=string, indent defaults to two spaces.",
|
27
|
+
" Note, you can escape a tab in bash by ctrl-vTAB with sourrounding \" e.g. \"--input= \"",
|
28
|
+
" input, filename or '-' for stdin",
|
29
|
+
" output, filename, '-' for stdout, '--' for same as input file"
|
30
|
+
].join("\n")
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
data =
|
35
|
+
if input == '-'
|
36
|
+
STDIN.read
|
37
|
+
else
|
38
|
+
File.read(input)
|
39
|
+
end
|
40
|
+
|
41
|
+
out =
|
42
|
+
if output == '-'
|
43
|
+
STDOUT
|
44
|
+
elsif output == '--'
|
45
|
+
out = input == STDIN ? STDOUT : File.open(input, 'w')
|
46
|
+
else
|
47
|
+
File.open(output, 'w')
|
48
|
+
end
|
49
|
+
|
50
|
+
include Format::Stuff
|
51
|
+
run_format(data, out, indent)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'format/stuff/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "format-stuff"
|
8
|
+
spec.version = Format::Stuff::VERSION
|
9
|
+
spec.authors = ["Christian Köstlin"]
|
10
|
+
spec.email = ["christian.koestlin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Formats your stuff}
|
13
|
+
spec.description = %q{Formats your stuff.}
|
14
|
+
spec.homepage = "https://github.com/gizmomogwai/format-stuff"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
data/lib/format/stuff.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "format/stuff/version"
|
2
|
+
|
3
|
+
module Format
|
4
|
+
module Stuff
|
5
|
+
def count(l, stuff)
|
6
|
+
stuff
|
7
|
+
.map { |s| l.scan(s).size }
|
8
|
+
.reduce(:+)
|
9
|
+
end
|
10
|
+
|
11
|
+
def count_tmp_indent(l, tmp_indent)
|
12
|
+
(tmp_indent.map{ |i| l.match(i) ? 1 : 0} + [0])
|
13
|
+
.reduce(:+)
|
14
|
+
end
|
15
|
+
|
16
|
+
#def ruby_open
|
17
|
+
# ["def", "begin", "(", "[", "{"]
|
18
|
+
#end
|
19
|
+
#def ruby_close
|
20
|
+
# ["end", ")", "]", "}"]
|
21
|
+
#end
|
22
|
+
#def ruby_tmp_indent
|
23
|
+
# [/^\./, /^\|\|/, /^&&/]
|
24
|
+
#end
|
25
|
+
def gradle_open
|
26
|
+
["{"]
|
27
|
+
end
|
28
|
+
def gradle_close
|
29
|
+
["}"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_format(data, output, indent, open=['(', '[', '{'], close=[')', ']', '}'], tmp_indent=[])
|
33
|
+
indent_level = 0
|
34
|
+
data.each_line do |l|
|
35
|
+
l.strip!
|
36
|
+
# STDERR.puts "working on '#{l}'"
|
37
|
+
opening = count(l, open)
|
38
|
+
# STDERR.puts "opening #{opening}"
|
39
|
+
closing = count(l, close)
|
40
|
+
# STDERR.puts "closing #{closing}"
|
41
|
+
old_indent_level = indent_level
|
42
|
+
indent_level = indent_level + opening - closing
|
43
|
+
prefix =
|
44
|
+
if indent_level > old_indent_level
|
45
|
+
indent * old_indent_level
|
46
|
+
else
|
47
|
+
indent * indent_level
|
48
|
+
end
|
49
|
+
tmp_indent_level = count_tmp_indent(l, tmp_indent)
|
50
|
+
# STDERR.puts "tmp_indent #{tmp_indent_level}"
|
51
|
+
# STDERR.puts "prefix '#{prefix}'"
|
52
|
+
prefix = prefix + (indent * tmp_indent_level)
|
53
|
+
# STDERR.puts "prefix '#{prefix}'"
|
54
|
+
output.puts((prefix + l).rstrip)
|
55
|
+
end
|
56
|
+
output.close
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: format-stuff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Köstlin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Formats your stuff.
|
56
|
+
email:
|
57
|
+
- christian.koestlin@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/format-stuff
|
72
|
+
- bin/setup
|
73
|
+
- format-stuff.gemspec
|
74
|
+
- lib/format/stuff.rb
|
75
|
+
- lib/format/stuff/version.rb
|
76
|
+
homepage: https://github.com/gizmomogwai/format-stuff
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.5.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Formats your stuff
|
99
|
+
test_files: []
|