vim_printer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/.yardopts +2 -0
- data/01-seoul256-input.png +0 -0
- data/01-seoul256-output.png +0 -0
- data/02-Tomorrow-Night-input.png +0 -0
- data/02-Tomorrow-Night-output.png +0 -0
- data/Gemfile +7 -0
- data/Guardfile +15 -0
- data/LICENSE +22 -0
- data/README.md +192 -0
- data/Rakefile +19 -0
- data/bin/vim_printer +4 -0
- data/lib/vim_printer/cli.rb +119 -0
- data/lib/vim_printer/core_ext/hash.rb +56 -0
- data/lib/vim_printer/logger.rb +10 -0
- data/lib/vim_printer/utility.rb +87 -0
- data/lib/vim_printer/version.rb +3 -0
- data/lib/vim_printer.rb +7 -0
- data/test/fixtures/inputs/demo1.xxx.rb +1 -0
- data/test/fixtures/inputs/demo1.yyy.rb +1 -0
- data/test/fixtures/inputs/demo2.xxx.rb +1 -0
- data/test/fixtures/inputs/demo2.yyy.rb +1 -0
- data/test/fixtures/inputs/java/demo3.xxx.java +1 -0
- data/test/fixtures/inputs/java/demo3.yyy.java +1 -0
- data/test/fixtures/inputs/java/demo4.xxx.java +1 -0
- data/test/fixtures/inputs/java/demo4.yyy.java +1 -0
- data/test/fixtures/inputs/noexts1_zzz +1 -0
- data/test/fixtures/inputs/noexts2_zzz +1 -0
- data/test/fixtures/outputs/demo1.xxx.rb.xhtml +91 -0
- data/test/fixtures/outputs/demo1.yyy.rb.xhtml +91 -0
- data/test/fixtures/outputs/demo2.xxx.rb.xhtml +91 -0
- data/test/fixtures/outputs/demo2.yyy.rb.xhtml +91 -0
- data/test/fixtures/outputs/java/demo3.xxx.java.xhtml +91 -0
- data/test/fixtures/outputs/java/demo3.yyy.java.xhtml +91 -0
- data/test/fixtures/outputs/java/demo4.xxx.java.xhtml +91 -0
- data/test/fixtures/outputs/java/demo4.yyy.java.xhtml +91 -0
- data/test/lib/vim_printer/test_utility.rb +48 -0
- data/test/test_helper.rb +12 -0
- data/vim_printer.gemspec +34 -0
- metadata +289 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e5a86cef7010bb8114f742c4591e7b6067aed22
|
4
|
+
data.tar.gz: 7d275164d3fe3e242ad70e5bb190e3f9de84d198
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 681876c8a44e88a6611020a5b040acf27697736bb96557322f2f20bfe78db2e9aeb47d16f41b35b9765ae3240fbba04e309d55866d6c7c490b181faa30e529bd
|
7
|
+
data.tar.gz: ac5e1c4c46079a4a893bcfeccc2f6f07f8a0c19eda485f1e0d9426cb3dd5927c33b43ae465968117f7c51a89452eba2b90f5cb7d351192d4ccf65a7314b8315a
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# Custom ignore files
|
20
|
+
TODOs.md
|
21
|
+
output.tar.gz
|
22
|
+
output.tgz
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
guard 'minitest' do
|
4
|
+
|
5
|
+
# with Minitest::Unit
|
6
|
+
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
|
7
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
8
|
+
watch(%r|^test/test_helper\.rb|) { "test" }
|
9
|
+
|
10
|
+
# with Minitest::Spec
|
11
|
+
# watch(%r|^spec/(.*)_spec\.rb|)
|
12
|
+
# watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
13
|
+
# watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
14
|
+
|
15
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Burin Choomnuan
|
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
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
## vim_printer
|
2
|
+
|
3
|
+
Print any files to html using the power of Vim. Output will be saved to `output.tar.gz` and ready for
|
4
|
+
extract and viewing in your favourite browser.
|
5
|
+
|
6
|
+
- Unlimited support for [vim colorschemes][] if enabled, or `default` colorscheme that comes with Vim.
|
7
|
+
- Can print any files in any languages that you can open with Vim.
|
8
|
+
- Use the power of [Vim][] to print the code without any other tools.
|
9
|
+
- Tested in Linux/OSX and should also works with Windows.
|
10
|
+
|
11
|
+
[![Gem Version](https://badge.fury.io/rb/vim_printer.svg)](http://badge.fury.io/rb/vim_printer)
|
12
|
+
|
13
|
+
### Example Outputs:
|
14
|
+
|
15
|
+
- The original input using [seoul256.vim][] colorscheme in Vim
|
16
|
+
|
17
|
+
![](https://github.com/agilecreativity/vim_printer/raw/master/01-seoul256-input.png)
|
18
|
+
|
19
|
+
The html output as rendered in the browser
|
20
|
+
|
21
|
+
![](https://github.com/agilecreativity/vim_printer/raw/master/01-seoul256-output.png)
|
22
|
+
|
23
|
+
- The original input using `Tomorrow-Night` colorscheme from [Tomorrow-theme][] in Vim
|
24
|
+
|
25
|
+
![](https://github.com/agilecreativity/vim_printer/raw/master/02-Tomorrow-Night-input.png)
|
26
|
+
|
27
|
+
The html output as renderd in the browser
|
28
|
+
|
29
|
+
![](https://github.com/agilecreativity/vim_printer/raw/master/02-Tomorrow-Night-output.png)
|
30
|
+
|
31
|
+
### Requirements
|
32
|
+
|
33
|
+
- [Vim][] - any recent version should be ok.
|
34
|
+
|
35
|
+
- Any decent `~/.vimrc` should do
|
36
|
+
|
37
|
+
* There are so many great vim dotfiles in github repos.
|
38
|
+
|
39
|
+
* [NeoBundle][] is a very good start if you are new to Vim.
|
40
|
+
|
41
|
+
* If you like you can use [my dotvim][] which is based on the [NeoBundle][].
|
42
|
+
|
43
|
+
* Use any [vim colorschemes][] if not the `default` scheme will be used.
|
44
|
+
|
45
|
+
My personal favourite are [seoul256.vim][] and [Tomorrow-Theme][]
|
46
|
+
|
47
|
+
- Any valid file types that are supported by Vim will be shown proper color in the output.
|
48
|
+
|
49
|
+
* By default Vim comes with supported for major languages so you should see the proper syntax with color in the output.
|
50
|
+
|
51
|
+
* On newer language like [Elixir][], you may have to first install [vim-elixir][] to see the proper syntax in the output.
|
52
|
+
If this is not installed then you will get the output but will not have the beautiful color syntax.
|
53
|
+
|
54
|
+
### Sample session
|
55
|
+
|
56
|
+
- Run with the sample fixture files
|
57
|
+
|
58
|
+
```sh
|
59
|
+
vim_printer print -b test/fixtures/inputs -e rb java -r
|
60
|
+
```
|
61
|
+
|
62
|
+
Will produce the file `output.tar.gz` with the following result on the screen.
|
63
|
+
|
64
|
+
```
|
65
|
+
FYI: your options {:base_dir=>"test/fixtures/inputs/", :exts=>["rb", "java"], :non_exts=>[], :inc_words=>[], :exc_words=>[], :ignore_case=>true, :recursive=>true, :version=>false, :theme=>"default"}
|
66
|
+
|
67
|
+
FYI: process file 1 of 8 : test/fixtures/inputs/demo1.xxx.rb
|
68
|
+
FYI: process file 2 of 8 : test/fixtures/inputs/demo1.yyy.rb
|
69
|
+
FYI: process file 3 of 8 : test/fixtures/inputs/demo2.xxx.rb
|
70
|
+
FYI: process file 4 of 8 : test/fixtures/inputs/demo2.yyy.rb
|
71
|
+
FYI: process file 5 of 8 : test/fixtures/inputs/java/demo3.xxx.java
|
72
|
+
FYI: process file 6 of 8 : test/fixtures/inputs/java/demo3.yyy.java
|
73
|
+
FYI: process file 7 of 8 : test/fixtures/inputs/java/demo4.xxx.java
|
74
|
+
FYI: process file 8 of 8 : test/fixtures/inputs/java/demo4.yyy.java
|
75
|
+
|
76
|
+
Your result should be available at `output.tar.gz`
|
77
|
+
|
78
|
+
```
|
79
|
+
|
80
|
+
### Usage
|
81
|
+
|
82
|
+
- Install the gem for your version of ruby
|
83
|
+
|
84
|
+
e.g. for rbenv your session will be something like
|
85
|
+
|
86
|
+
```sh
|
87
|
+
rbenv local 2.1.1 # or whatever the version of you ruby
|
88
|
+
rbenv rehash
|
89
|
+
gem install vim_printer
|
90
|
+
```
|
91
|
+
- Print any files using the gem
|
92
|
+
|
93
|
+
```sh
|
94
|
+
vim_printer
|
95
|
+
```
|
96
|
+
- Print any files that you like using the simple command
|
97
|
+
|
98
|
+
The following command will print out all java, and ruby files recursively
|
99
|
+
using the `solarized` colorscheme.
|
100
|
+
|
101
|
+
```sh
|
102
|
+
vim_printer print --base-dir ./test/fixtures \
|
103
|
+
--exts rb \
|
104
|
+
--theme solarized
|
105
|
+
```
|
106
|
+
|
107
|
+
Your output will be saved to the default `output.tar.gz` in the directory where you run this command.
|
108
|
+
To see the output in your browser just type:
|
109
|
+
|
110
|
+
```sh
|
111
|
+
mkdir -p ~/Desktop/vim_printer
|
112
|
+
mv output.tar.gz ~/Desktop/vim_printer
|
113
|
+
cd ~/Desktop/vim_printer
|
114
|
+
tar zxvf output.tar.gz
|
115
|
+
```
|
116
|
+
|
117
|
+
- Print only files that contain the word `xxx` in the title
|
118
|
+
|
119
|
+
```sh
|
120
|
+
vim_printer print --base-dir ./test/fixtures \
|
121
|
+
--exts java \
|
122
|
+
--theme solarized \
|
123
|
+
--n xxx
|
124
|
+
```
|
125
|
+
|
126
|
+
- For help in using the gem just type `vim_printer` without any parameter
|
127
|
+
You should see something like the following:
|
128
|
+
|
129
|
+
```
|
130
|
+
Usage:
|
131
|
+
vim_printer print [OPTIONS]
|
132
|
+
|
133
|
+
Options:
|
134
|
+
-b, [--base-dir=BASE_DIR] # Base directory
|
135
|
+
# Default: . (current directory)
|
136
|
+
-e, [--exts=one two three] # List of extensions to search for
|
137
|
+
-f, [--non-exts=one two three] # List of files without extension to search for
|
138
|
+
-n, [--inc-words=one two three] # List of words to be included in the result if any
|
139
|
+
-x, [--exc-words=one two three] # List of words to be excluded from the result if any
|
140
|
+
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
141
|
+
# Default: true
|
142
|
+
-r, [--recursive], [--no-recursive] # Search for files recursively
|
143
|
+
# Default: true
|
144
|
+
-v, [--version], [--no-version] # Display version information
|
145
|
+
-t, [--theme=THEME] # Vim colorscheme to use
|
146
|
+
# Default: default
|
147
|
+
|
148
|
+
Print the list of files
|
149
|
+
```
|
150
|
+
|
151
|
+
### Development/Testing
|
152
|
+
|
153
|
+
```sh
|
154
|
+
git clone https://github.com/agilecreativity/vim_printer.git
|
155
|
+
cd vim_printer
|
156
|
+
bundle
|
157
|
+
# run default test
|
158
|
+
rake
|
159
|
+
```
|
160
|
+
### Known Issues
|
161
|
+
|
162
|
+
- Will be listed here if any.
|
163
|
+
|
164
|
+
### Disclaimers
|
165
|
+
|
166
|
+
- This is still early release of the gem, I may make several changes to the API.
|
167
|
+
- If you find any issues please let me know.
|
168
|
+
- Pull request is always welcome.
|
169
|
+
|
170
|
+
### Changelog
|
171
|
+
|
172
|
+
#### 0.0.1
|
173
|
+
|
174
|
+
- Initial release
|
175
|
+
|
176
|
+
### Contributing
|
177
|
+
|
178
|
+
1. Fork it
|
179
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
180
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
181
|
+
4. Make sure that you add the tests and ensure that all tests are passed
|
182
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
183
|
+
6. Create new Pull Request
|
184
|
+
|
185
|
+
[NeoBundle]: https://github.com/Shougo/neobundle.vim
|
186
|
+
[Vim]: https://www.vim.org
|
187
|
+
[my dotvim]: https://github.com/agilecreativity/dotvim
|
188
|
+
[Elixir]: http://elixir-lang.org
|
189
|
+
[vim-elixir]: https://github.com/elixir-lang/vim-elixir
|
190
|
+
[vim colorschemes]: https://github.com/flazz/vim-colorschemes/tree/master/colors
|
191
|
+
[seoul256.vim]: https://github.com/junegunn/seoul256.vim
|
192
|
+
[Tomorrow-theme]: https://github.com/ChrisKempson/Tomorrow-Theme
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'lib/vim_printer'
|
6
|
+
t.test_files = FileList['test/lib/vim_printer/test_*.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
task :pry do
|
13
|
+
require 'pry'
|
14
|
+
require 'awesome_print'
|
15
|
+
require 'vim_printer'
|
16
|
+
include VimPrinter
|
17
|
+
ARGV.clear
|
18
|
+
Pry.start
|
19
|
+
end
|
data/bin/vim_printer
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'code_lister'
|
2
|
+
require_relative '../vim_printer'
|
3
|
+
|
4
|
+
module VimPrinter
|
5
|
+
|
6
|
+
class CLI < CodeLister::BaseCLI
|
7
|
+
|
8
|
+
desc 'print', 'Print the list of files'
|
9
|
+
|
10
|
+
shared_options
|
11
|
+
|
12
|
+
method_option :theme,
|
13
|
+
aliases: "-t",
|
14
|
+
desc: "Vim colorscheme to use",
|
15
|
+
default: "default"
|
16
|
+
def print
|
17
|
+
opts = options.symbolize_keys
|
18
|
+
if opts[:version]
|
19
|
+
puts "You are using VimPrinter version #{VimPrinter::VERSION}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
puts "FYI: your options #{opts}"
|
23
|
+
execute(opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "usage", "Display help screen"
|
27
|
+
def usage
|
28
|
+
puts <<-EOS
|
29
|
+
Usage:
|
30
|
+
vim_printer print
|
31
|
+
|
32
|
+
Options:
|
33
|
+
-b, [--base-dir=BASE_DIR] # Base directory
|
34
|
+
# Default: /home/bchoomnuan/Dropbox/spikes/vim_printer
|
35
|
+
-e, [--exts=one two three] # List of extensions to search for
|
36
|
+
-f, [--non-exts=one two three] # List of files without extension to search for
|
37
|
+
-n, [--inc-words=one two three] # List of words to be included in the result if any
|
38
|
+
-x, [--exc-words=one two three] # List of words to be excluded from the result if any
|
39
|
+
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
40
|
+
# Default: true
|
41
|
+
-r, [--recursive], [--no-recursive] # Search for files recursively
|
42
|
+
# Default: true
|
43
|
+
-v, [--version], [--no-version] # Display version information
|
44
|
+
-t, [--theme=THEME] # Vim colorscheme to use
|
45
|
+
# Default: default
|
46
|
+
|
47
|
+
Print the list of files
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
|
51
|
+
default_task :usage
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# @param args [Hash<Symbol, Object>] options argument
|
56
|
+
def execute(options = {})
|
57
|
+
|
58
|
+
input_files = CodeLister.files(options)
|
59
|
+
|
60
|
+
if input_files.empty?
|
61
|
+
puts "No file found for your option: #{options}"
|
62
|
+
return
|
63
|
+
end
|
64
|
+
to_htmls(input_files, options)
|
65
|
+
|
66
|
+
# search for files that we created
|
67
|
+
generated_files = VimPrinter::Utility.find(options[:base_dir])
|
68
|
+
|
69
|
+
# tar.gzip them for user
|
70
|
+
VimPrinter::Utility.tar_gzip_files(generated_files, 'output.tar.gz')
|
71
|
+
|
72
|
+
# cleanup after ourself
|
73
|
+
VimPrinter::Utility.delete(generated_files)
|
74
|
+
|
75
|
+
# report the result
|
76
|
+
puts "Your result should be available at `output.tar.gz`"
|
77
|
+
end
|
78
|
+
|
79
|
+
# convert multiple files to 'html'
|
80
|
+
def to_htmls(files, options = {})
|
81
|
+
files.each_with_index do |file, index|
|
82
|
+
puts "FYI: process file #{index + 1} of #{files.size} : #{file}"
|
83
|
+
to_html(file, options)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_html(filename, options = {})
|
88
|
+
opts = {
|
89
|
+
theme: 'seoul256-light'
|
90
|
+
}.merge(options)
|
91
|
+
|
92
|
+
raise "Invalid input file #{filename}" unless File.exists?(filename)
|
93
|
+
|
94
|
+
# sensible argument, see :help :TOhtml (from Vim)
|
95
|
+
command = [
|
96
|
+
"vim",
|
97
|
+
"-E",
|
98
|
+
"-c 'let g:html_expand_tabs = 1'",
|
99
|
+
"-c 'let g:html_use_css = 1'",
|
100
|
+
"-c 'let g:html_no_progress = 1'"
|
101
|
+
]
|
102
|
+
|
103
|
+
# set the colorscheme for the output
|
104
|
+
command.push("-c 'colorscheme #{opts[:theme]}'")
|
105
|
+
|
106
|
+
# closing arguments
|
107
|
+
args = [
|
108
|
+
"-c 'TOhtml'",
|
109
|
+
"-c 'w'",
|
110
|
+
"-c 'qa!'",
|
111
|
+
"#{filename}",
|
112
|
+
"> /dev/null"
|
113
|
+
]
|
114
|
+
|
115
|
+
# Note: have to run as system only
|
116
|
+
system(command.concat(args).join(" "))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# File activesupport/lib/active_support/core_ext/hash/keys.rb
|
4
|
+
#
|
5
|
+
# hash = { name: 'Rob', age: '28' }
|
6
|
+
# hash.transform_keys{ |key| key.to_s.upcase }
|
7
|
+
# => { "NAME" => "Rob", "AGE" => "28" }
|
8
|
+
def transform_keys
|
9
|
+
result = {}
|
10
|
+
each_key do |key|
|
11
|
+
result[yield(key)] = self[key]
|
12
|
+
end
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
def transform_keys!(&block)
|
17
|
+
keys.each do |key|
|
18
|
+
value = delete(key)
|
19
|
+
self[yield(key)] = value.is_a?(Hash) ? value.transform_keys!(&block) : value
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
# hash = { 'name' => 'Rob', 'age' => '28' }
|
25
|
+
# hash.symbolize_keys
|
26
|
+
# => { name: "Rob", age: "28" }
|
27
|
+
def symbolize_keys
|
28
|
+
transform_keys{ |key| key.to_sym rescue key }
|
29
|
+
end
|
30
|
+
|
31
|
+
# File activesupport/lib/active_support/core_ext/hash/keys.rb, line 135
|
32
|
+
def symbolize_keys!
|
33
|
+
transform_keys!{ |key| key.to_sym rescue key }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Merges the caller into +other_hash+. For example,
|
37
|
+
#
|
38
|
+
# options = options.reverse_merge(size: 25, velocity: 10)
|
39
|
+
#
|
40
|
+
# is equivalent to
|
41
|
+
#
|
42
|
+
# options = { size: 25, velocity: 10 }.merge(options)
|
43
|
+
#
|
44
|
+
# This is particularly useful for initializing an options hash
|
45
|
+
# with default values.
|
46
|
+
def reverse_merge(other_hash)
|
47
|
+
other_hash.merge(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Destructive +reverse_merge+.
|
51
|
+
def reverse_merge!(other_hash)
|
52
|
+
# right wins if there is no left
|
53
|
+
merge!(other_hash) { |key,left,right| left }
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
require 'stringio'
|
3
|
+
require 'find'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'archive/tar/minitar'
|
6
|
+
|
7
|
+
module VimPrinter
|
8
|
+
|
9
|
+
include Archive::Tar
|
10
|
+
include Archive::Tar::Minitar
|
11
|
+
|
12
|
+
module Utility
|
13
|
+
|
14
|
+
# @todo use me when you have to!
|
15
|
+
CustomError = Class.new(StandardError)
|
16
|
+
|
17
|
+
class << self
|
18
|
+
|
19
|
+
# Find list of files based on certain extension
|
20
|
+
# @param [String] bas_dir the starting directory
|
21
|
+
# @param [String] extension the file extension to search for
|
22
|
+
#
|
23
|
+
# @return [Array<String>] list of matching files or empty list
|
24
|
+
def find(base_dir, extension = 'xhtml')
|
25
|
+
file_paths = []
|
26
|
+
Find.find(base_dir) do |path|
|
27
|
+
file_paths << path if path =~ /.*\.#{extension}$/
|
28
|
+
end
|
29
|
+
file_paths || []
|
30
|
+
end
|
31
|
+
|
32
|
+
# Tar and gzip list of files
|
33
|
+
#
|
34
|
+
# @param [Array<String>] files list of input files
|
35
|
+
# @param [String] output the output file in .tar.gz format
|
36
|
+
def tar_gzip_files(files, output = 'output.tar.gz')
|
37
|
+
begin
|
38
|
+
sgz = Zlib::GzipWriter.new(File.open(output, 'wb'))
|
39
|
+
tar = Minitar::Output.new(sgz)
|
40
|
+
files.each do |file|
|
41
|
+
Minitar.pack_file(file, tar)
|
42
|
+
end
|
43
|
+
ensure
|
44
|
+
# Closes both tar and sgz.
|
45
|
+
tar.close unless tar.nil?
|
46
|
+
tar = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Delete the files from the given list
|
51
|
+
def delete(files)
|
52
|
+
# Note: should we remove the files and be done with it?
|
53
|
+
files.each do |file|
|
54
|
+
#puts "FYI: about to delete file #{file}"
|
55
|
+
FileUtils.rm_rf(file)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Add suffix to each extensions
|
60
|
+
#
|
61
|
+
# @param [Array<String>] extension list of extension
|
62
|
+
# @param [String] suffix the suffix string
|
63
|
+
#
|
64
|
+
# @return [Array<String>] new list with the suffix added to each element
|
65
|
+
def add_suffix(extensions = %w(rb pdf), suffix)
|
66
|
+
extensions.map {|e| "#{e}.#{suffix}" }
|
67
|
+
end
|
68
|
+
|
69
|
+
# Time the operation before and after the operation for tuning purpose
|
70
|
+
def time
|
71
|
+
beg_time = Time.now
|
72
|
+
yield
|
73
|
+
end_time = Time.now
|
74
|
+
end_time - beg_time
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if __FILE__ == $0
|
82
|
+
include VimPrinter::Utility
|
83
|
+
include Archive::Tar
|
84
|
+
include Archive::Tar::Minitar
|
85
|
+
files = VimPrinter::Utility.find('test/fixtures/inputs')
|
86
|
+
VimPrinter::Utility.tar_gzip_files(files, 'test/fixtures/output.tar.gz')
|
87
|
+
end
|
data/lib/vim_printer.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# file: spec/fixtures/demo1.xxx.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
# file: spec/fixtures/demo1.yyy.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
# file: spec/fixtures/demo2.xxx.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
# file: spec/fixtures/demo2.yyy.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
// file: test/fixtures/java/demo3.xxx.java
|
@@ -0,0 +1 @@
|
|
1
|
+
// file: test/fixtures/java/demo3.yyy.java
|
@@ -0,0 +1 @@
|
|
1
|
+
// file: test/fixtures/java/demo4.xxx.java
|
@@ -0,0 +1 @@
|
|
1
|
+
// file: test/fixtures/java/demo4.yyy.java
|
@@ -0,0 +1 @@
|
|
1
|
+
# file: spec/fixtures/noexts1_zzz
|
@@ -0,0 +1 @@
|
|
1
|
+
# file: spec/fixtures/noexts2_zzz
|