ruby-beautify 0.9.0 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,2 +1 @@
1
- *.orig
2
- *.pyc
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-beautify.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ernie Brodeur
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 CHANGED
@@ -1,5 +1,50 @@
1
- About
2
- =====
3
- This is a CLI bin to help print pretty ruby text to console.
1
+ # RBeautify
4
2
 
5
- This is a modifitcation of the sublime-text2 plugin provided by https://github.com/CraigWilliams/BeautifyRuby/blob/master/lib/rbeautify.rb
3
+ This gem provides a cli binary named 'rbeautify' that will pretty up ruby code.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruby-beautify'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruby-beautify
18
+
19
+ ## Usage
20
+
21
+ To Pretty up a file:
22
+
23
+ $ rbeautify filename
24
+
25
+ It can take mulitple filenames:
26
+
27
+ $ rbeautify a b c
28
+
29
+ Without a filename it reads from STDIN, suitable for piping:
30
+
31
+ $ curl 'http://example.org/ugly-file.rb' | rbeautify
32
+
33
+ It has help:
34
+
35
+ $ rbeautify -h
36
+
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
45
+
46
+ # History
47
+
48
+ The original analyzer is available at: http://www.arachnoid.com/ruby/rubyBeautifier.html.
49
+
50
+ My work is based off of this sublime-text2 plugin: https://github.com/CraigWilliams/BeautifyRuby but cleaned up and made suitable for use directly in a shell.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/rbeautify CHANGED
@@ -1,12 +1,8 @@
1
1
  #!/usr/bin/ruby
2
- require 'rbeautify'
3
- require 'app'
4
- require 'cli'
5
- require 'filemagic'
2
+ require 'ruby-beautify'
6
3
 
7
- include ErnieBrodeur
4
+ include RBeautify
8
5
 
9
- App.version = "0.9.0"
10
6
  App.banner = "Usage: print ruby into a pretty format, or break trying."
11
7
 
12
8
  Options.parse!
@@ -1,13 +1,18 @@
1
- require 'rbeautify/block_start'
2
- require 'rbeautify/block_end'
3
- require 'rbeautify/block_matcher'
4
- require 'rbeautify/language'
5
- require 'rbeautify/line'
1
+ require 'yajl'
2
+ require 'sys/proctable'
6
3
 
7
- require 'rbeautify/config/ruby'
4
+ require 'ruby-beautify/app'
5
+ require 'ruby-beautify/cli'
6
+ require 'ruby-beautify/filemagic'
7
+ require "ruby-beautify/version"
8
+ require 'ruby-beautify/block_start'
9
+ require 'ruby-beautify/block_end'
10
+ require 'ruby-beautify/block_matcher'
11
+ require 'ruby-beautify/language'
12
+ require 'ruby-beautify/line'
13
+ require 'ruby-beautify/config/ruby'
8
14
 
9
15
  module RBeautify
10
-
11
16
  def self.beautify_string(language, source, use_tabs=false)
12
17
  dest = ""
13
18
  block = nil
@@ -0,0 +1,14 @@
1
+ module RBeautify
2
+ class Application
3
+ attr_accessor :banner
4
+ attr_accessor :long_description
5
+
6
+ # return the name of the app, for now this is just the cmd ran, later it will be
7
+ # something generated but more unique.
8
+ def name
9
+ $0.split("/").last
10
+ end
11
+ end
12
+
13
+ App = RBeautify::Application.new
14
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,56 @@
1
+ require 'optparse'
2
+
3
+ module RBeautify
4
+ class OptBlob
5
+ def initialize
6
+ @options = {}
7
+
8
+ @parser = OptionParser.new do |opts|
9
+ opts.banner = App.banner
10
+
11
+ opts.on("-V", "--version", "Print version") { |version| @options[:version] = true}
12
+ end
13
+ end
14
+
15
+ #TODO figure out a more dynamic way to include the parser and hash table.
16
+ def []=(key, value)
17
+ @options[key] = value
18
+ end
19
+
20
+ def [](key)
21
+ @options[key]
22
+ end
23
+
24
+ # This will build an on/off option with a default value set to false.
25
+ def bool_on(word, description = "")
26
+ Options[word.to_sym] = false
27
+ @parser.on "-#{word.chars.first}", "--[no]#{word}", description do |o|
28
+ Options[word.to_sym] == o
29
+ end
30
+ end
31
+
32
+ # This is the parser value on lifted up.
33
+ def on(*opts, &block)
34
+ @parser.on(*opts, &block)
35
+ end
36
+
37
+ def parse!
38
+ @parser.banner = App.banner
39
+ @parser.parse!
40
+
41
+ if @options[:version]
42
+ puts App.version
43
+ exit 0
44
+ end
45
+ end
46
+
47
+ def on_pry
48
+ if @options[:pry]
49
+ require 'pry'
50
+ binding.pry
51
+ end
52
+ end
53
+ end
54
+
55
+ Options = OptBlob.new
56
+ end
File without changes
@@ -1,4 +1,4 @@
1
- module ErnieBrodeur
1
+ module RBeautify
2
2
  # Add some basic filemagic types.
3
3
  class FileMagic
4
4
  def self.mime_type(file)
@@ -9,5 +9,4 @@ module ErnieBrodeur
9
9
  end
10
10
  end
11
11
  end
12
- App.plugins.push 'filemagic'
13
12
  end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module RBeautify
2
+ VERSION = "0.91.0"
3
+ end
@@ -1,6 +1,7 @@
1
+ require File.expand_path('../lib/ruby-beautify/version', __FILE__)
2
+
1
3
  Gem::Specification.new do |gem|
2
4
  gem.name = 'ruby-beautify'
3
- gem.version = '0.9.0'
4
5
  gem.summary = "a cli tool (and module) to beautify ruby code."
5
6
  gem.description = gem.summary
6
7
  gem.authors = ["Ernie Brodeur", "Craig Williams", "Joel Chippindale", "Paul Lutus"]
@@ -8,8 +9,11 @@ Gem::Specification.new do |gem|
8
9
  gem.homepage = "https://github.com/erniebrodeur/ruby-beautify"
9
10
 
10
11
  gem.add_development_dependency "rspec"
12
+ gem.add_runtime_dependency "yajl-ruby"
13
+ gem.add_runtime_dependency "sys-proctable"
11
14
  gem.files = `git ls-files`.split("\n")
12
15
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
16
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
17
  gem.require_paths = ["lib"]
18
+ gem.version = RBeautify::VERSION
15
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-beautify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.91.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-07-08 00:00:00.000000000 Z
15
+ date: 2012-07-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec
@@ -30,6 +30,38 @@ dependencies:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: yajl-ruby
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: sys-proctable
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
33
65
  description: a cli tool (and module) to beautify ruby code.
34
66
  email: ebrodeur@ujami.net
35
67
  executables:
@@ -38,21 +70,24 @@ extensions: []
38
70
  extra_rdoc_files: []
39
71
  files:
40
72
  - .gitignore
73
+ - Gemfile
74
+ - LICENSE
41
75
  - README.md
76
+ - Rakefile
42
77
  - bin/rbeautify
43
- - lib/app.rb
44
78
  - lib/beautifier.rb
45
- - lib/cli.rb
46
- - lib/filemagic.rb
47
- - lib/rbeautify.rb
48
- - lib/rbeautify/block_end.rb
49
- - lib/rbeautify/block_matcher.rb
50
- - lib/rbeautify/block_start.rb
51
- - lib/rbeautify/config/ruby.rb
52
- - lib/rbeautify/language.rb
53
- - lib/rbeautify/line.rb
54
- - license.txt
55
- - rbeautify.gemspec
79
+ - lib/ruby-beautify.rb
80
+ - lib/ruby-beautify/app.rb
81
+ - lib/ruby-beautify/block_end.rb
82
+ - lib/ruby-beautify/block_matcher.rb
83
+ - lib/ruby-beautify/block_start.rb
84
+ - lib/ruby-beautify/cli.rb
85
+ - lib/ruby-beautify/config/ruby.rb
86
+ - lib/ruby-beautify/filemagic.rb
87
+ - lib/ruby-beautify/language.rb
88
+ - lib/ruby-beautify/line.rb
89
+ - lib/ruby-beautify/version.rb
90
+ - ruby-beautify.gemspec
56
91
  - spec/fixtures/ruby.yml
57
92
  - spec/rbeautify/block_matcher_spec.rb
58
93
  - spec/rbeautify/block_start_spec.rb
data/lib/app.rb DELETED
@@ -1,79 +0,0 @@
1
- $:.push '/home/ebrodeur/Projects/bin_snippets/lib'
2
-
3
- # Some requires, they don't fit elsewhere.
4
- require 'yajl'
5
- require 'sys/proctable'
6
- module ErnieBrodeur
7
-
8
- class Application
9
- attr_accessor :version
10
- attr_accessor :banner
11
- attr_accessor :long_description
12
- attr_accessor :plugins
13
-
14
- # return the name of the app, for now this is just the cmd ran, later it will be
15
- # something generated but more unique.
16
- def name
17
- $0.split("/").last
18
- end
19
-
20
- def cache_dir
21
- "#{Dir.home}/.cache/erniebrodeur/#{App.name}/"
22
- end
23
-
24
- def config_dir
25
- "#{Dir.home}/.config/erniebrodeur/#{App.name}/"
26
- end
27
-
28
- def pids
29
- a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{App.name}.*-[dD].*/}.map {|x| x.pid}
30
- a.delete $$
31
- return a if a.any?
32
- nil
33
- end
34
-
35
- def initialize
36
- @version = '0.0.0'
37
- @banner = 'A bin snippet by Ernie Brodeur that does . . . something.'
38
- @long_description = ''
39
- @plugins = []
40
- end
41
-
42
- def daemonize(*params, &block)
43
- if params[0] && !params[0][:multiple_pids] && pids
44
- puts_or_log :info, "#{App.name} appears to be running (#{pids}), only one allowed, exiting."
45
- exit
46
- end
47
- puts_or_log :info, "Forking to background."
48
-
49
- Process.daemon
50
- block.call
51
- end
52
-
53
- def kill_daemon
54
- if !pids
55
- puts_or_log :fatal, "No pids found, exiting."
56
- end
57
-
58
- pids.each do |p|
59
- puts_or_log :info, "Killing #{p}"
60
- %x[kill -TERM #{p}]
61
- end
62
- end
63
- private
64
- def puts_or_log(l, s)
65
- if App.plugins.include? 'logging'
66
- Log.send l, s
67
- else
68
- puts s
69
- exit if l.to_sym == :fatal
70
- end
71
- end
72
- end
73
-
74
- App = Application.new
75
-
76
- # This will load a helper, if it exists.
77
- f = "#{$:.last}/helpers/#{App.name}.rb"
78
- require f if File.exist? f
79
- end
data/lib/cli.rb DELETED
@@ -1,81 +0,0 @@
1
- # This library is to reduce the amount of effort I need to build a binary with option parsing
2
- # and sensable defaults. It is not intended to be convient for anybody but me, their
3
- # are a host of good @options out there if you want cli tools.
4
- require 'optparse'
5
-
6
- module ErnieBrodeur
7
- class OptBlob
8
- def initialize
9
- @options = {}
10
-
11
- @parser = OptionParser.new do |opts|
12
- opts.banner = ErnieBrodeur::App.banner
13
-
14
- opts.on("-V", "--version", "Print version") { |version| @options[:version] = true}
15
- opts.on("-p", "--pry", "open a pry shell.") { |pry| @options[:pry] = true}
16
- if App.plugins.include? 'logging'
17
- opts.on("-l", "--log-level LEVEL", "Change the log level, default is debug.") { |level| ErnieBrodeur::Log.level level }
18
- opts.on("--log-file FILE", "What file to output to, default is STDOUT") { |file| ErnieBrodeur::Log.filename file }
19
- end
20
- end
21
- end
22
-
23
- #TODO figure out a more dynamic way to include the parser and hash table.
24
- def []=(key, value)
25
- @options[key] = value
26
- end
27
-
28
- def [](key)
29
- @options[key]
30
- end
31
-
32
- # This will build an on/off option with a default value set to false.
33
- def bool_on(word, description = "")
34
- Options[word.to_sym] = false
35
- @parser.on "-#{word.chars.first}", "--[no]#{word}", description do |o|
36
- Options[word.to_sym] == o
37
- end
38
- end
39
-
40
- # This is the parser value on lifted up.
41
- def on(*opts, &block)
42
- @parser.on(*opts, &block)
43
- end
44
-
45
- def on_tail(*opts, &block)
46
- @parser.on(*opts, &block)
47
- end
48
-
49
- def on_head(*opts, &block)
50
- @parser.on(*opts, &block)
51
- end
52
-
53
- def parse!
54
- @parser.banner = ErnieBrodeur::App.banner
55
- @parser.parse!
56
-
57
- if @options[:version]
58
- puts ErnieBrodeur::App.version
59
- exit 0
60
- end
61
-
62
- # we need to mash in our config array. To do this we want to make config
63
- # options that don't overwrite cli options.
64
- if App.plugins.include? 'config'
65
- Config.each do |k,v|
66
- @options[k] = v if !@options[k]
67
- end
68
- end
69
- end
70
-
71
- def on_pry
72
- if @options[:pry]
73
- require 'pry'
74
- binding.pry
75
- end
76
- end
77
- end
78
-
79
- App.plugins.push "cli"
80
- Options = OptBlob.new
81
- end
data/license.txt DELETED
@@ -1,77 +0,0 @@
1
- All software in this package is covered by the MIT license and beerware (rev42).
2
-
3
- Copyright (c) 2011 Ernie Brodeur
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.
25
-
26
- /*
27
- * ----------------------------------------------------------------------------
28
- * "THE BEER-WARE LICENSE" (Revision 42):
29
- * Ernie Brodeur wrote this package. As long as you retain this notice you
30
- * can do whatever you want with his stuff. If we meet some day, and you think
31
- * this stuff is worth it, you can buy me a beer in return.
32
- * ----------------------------------------------------------------------------
33
- */
34
-
35
- Further supported by: https://github.com/CraigWilliams/BeautifyRuby/blob/master/lib/rbeautify.rb
36
-
37
- All of BeautifyRuby is licensed under the MIT license.
38
-
39
- Copyright (c) 2011 Craig Williams <cwilliams.allancraig@gmail.com>
40
-
41
- Permission is hereby granted, free of charge, to any person obtaining a copy
42
- of this software and associated documentation files (the "Software"), to deal
43
- in the Software without restriction, including without limitation the rights
44
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45
- copies of the Software, and to permit persons to whom the Software is
46
- furnished to do so, subject to the following conditions:
47
-
48
- The above copyright notice and this permission notice shall be included in
49
- all copies or substantial portions of the Software.
50
-
51
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
- THE SOFTWARE.
58
-
59
- Pieces provided originally by: http://www.arachnoid.com/ruby/rubyBeautifier.html
60
-
61
- /***************************************************************************
62
- * Copyright (C) 2008, Joel Chippindale, Paul Lutus *
63
- * *
64
- * This program is free software: you can redistribute it and/or modify *
65
- * it under the terms of the GNU General Public License as published by *
66
- * the Free Software Foundation, either version 3 of the License, or *
67
- * (at your option) any later version. *
68
- * *
69
- * This program is distributed in the hope that it will be useful, *
70
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
71
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
72
- * GNU General Public License for more details. *
73
- * *
74
- * You should have received a copy of the GNU General Public License *
75
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
76
- * *
77
- ***************************************************************************/