slimkeyfy 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 +34 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE +21 -0
- data/README.md +172 -0
- data/bin/slimkeyfy +5 -0
- data/lib/.DS_Store +0 -0
- data/lib/slimkeyfy/console/command_line.rb +90 -0
- data/lib/slimkeyfy/console/io_action.rb +30 -0
- data/lib/slimkeyfy/console/printer.rb +50 -0
- data/lib/slimkeyfy/console/translate.rb +101 -0
- data/lib/slimkeyfy/console.rb +8 -0
- data/lib/slimkeyfy/slimutils/file_utils.rb +61 -0
- data/lib/slimkeyfy/slimutils/hash_merging.rb +84 -0
- data/lib/slimkeyfy/slimutils/key_generator.rb +70 -0
- data/lib/slimkeyfy/slimutils/yaml_processor.rb +56 -0
- data/lib/slimkeyfy/slimutils.rb +8 -0
- data/lib/slimkeyfy/transformer/base_transformer.rb +42 -0
- data/lib/slimkeyfy/transformer/controller_transformer.rb +20 -0
- data/lib/slimkeyfy/transformer/slim_transformer.rb +92 -0
- data/lib/slimkeyfy/transformer/whitespacer.rb +48 -0
- data/lib/slimkeyfy/transformer/word.rb +49 -0
- data/lib/slimkeyfy/transformer.rb +9 -0
- data/lib/slimkeyfy/version.rb +3 -0
- data/lib/slimkeyfy.rb +12 -0
- data/slimkeyfy.gemspec +21 -0
- data/vendor/bundle/bin/htmldiff +25 -0
- data/vendor/bundle/bin/ldiff +25 -0
- data/vendor/bundle/bin/rspec +23 -0
- data/vendor/bundle/build_info/diff-lcs-1.2.5.info +1 -0
- data/vendor/bundle/build_info/rspec-3.0.0.info +1 -0
- data/vendor/bundle/build_info/rspec-core-3.0.2.info +1 -0
- data/vendor/bundle/build_info/rspec-expectations-3.0.2.info +1 -0
- data/vendor/bundle/build_info/rspec-mocks-3.0.2.info +1 -0
- data/vendor/bundle/build_info/rspec-support-3.0.2.info +1 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/.autotest +3 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/.gemtest +0 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/.hoerc +2 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/.rspec +2 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/.travis.yml +22 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/Contributing.rdoc +64 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/Gemfile +20 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/History.rdoc +152 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/License.rdoc +39 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/Manifest.txt +38 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/README.rdoc +85 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/Rakefile +41 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/autotest/discover.rb +1 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/bin/htmldiff +32 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/bin/ldiff +6 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/docs/COPYING.txt +339 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/docs/artistic.txt +127 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/array.rb +7 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/block.rb +37 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/callbacks.rb +322 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/change.rb +177 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/htmldiff.rb +149 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/hunk.rb +276 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/internals.rb +301 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/ldiff.rb +195 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/string.rb +5 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs.rb +805 -0
- data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff-lcs.rb +3 -0
- data/vendor/bundle/gems/rspec-3.0.0/License.txt +24 -0
- data/vendor/bundle/gems/rspec-3.0.0/README.md +47 -0
- data/vendor/bundle/gems/rspec-3.0.0/lib/rspec.rb +3 -0
- data/vendor/bundle/gems/rspec-core-3.0.2/.document +5 -0
- data/vendor/bundle/gems/rspec-core-3.0.2/.yardopts +7 -0
- data/vendor/bundle/gems/rspec-core-3.0.2/Changelog.md +1466 -0
- data/vendor/bundle/gems/rspec-core-3.0.2/License.txt +25 -0
- data/vendor/bundle/gems/rspec-core-3.0.2/README.md +243 -0
- data/vendor/bundle/gems/rspec-core-3.0.2/exe/rspec +4 -0
- data/vendor/bundle/gems/rspec-expectations-3.0.2/.document +5 -0
- data/vendor/bundle/gems/rspec-expectations-3.0.2/.yardopts +6 -0
- data/vendor/bundle/gems/rspec-expectations-3.0.2/Changelog.md +749 -0
- data/vendor/bundle/gems/rspec-expectations-3.0.2/License.txt +24 -0
- data/vendor/bundle/gems/rspec-expectations-3.0.2/README.md +278 -0
- data/vendor/bundle/gems/rspec-mocks-3.0.2/.document +5 -0
- data/vendor/bundle/gems/rspec-mocks-3.0.2/.yardopts +6 -0
- data/vendor/bundle/gems/rspec-mocks-3.0.2/Changelog.md +733 -0
- data/vendor/bundle/gems/rspec-mocks-3.0.2/License.txt +24 -0
- data/vendor/bundle/gems/rspec-mocks-3.0.2/README.md +380 -0
- data/vendor/bundle/gems/rspec-support-3.0.2/Changelog.md +30 -0
- data/vendor/bundle/gems/rspec-support-3.0.2/LICENSE.txt +22 -0
- data/vendor/bundle/gems/rspec-support-3.0.2/README.md +17 -0
- data/vendor/bundle/specifications/diff-lcs-1.2.5.gemspec +68 -0
- data/vendor/bundle/specifications/rspec-3.0.0.gemspec +43 -0
- data/vendor/bundle/specifications/rspec-core-3.0.2.gemspec +66 -0
- data/vendor/bundle/specifications/rspec-expectations-3.0.2.gemspec +51 -0
- data/vendor/bundle/specifications/rspec-mocks-3.0.2.gemspec +48 -0
- data/vendor/bundle/specifications/rspec-support-3.0.2.gemspec +42 -0
- metadata +153 -0
@@ -0,0 +1,195 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'diff/lcs/hunk'
|
6
|
+
|
7
|
+
# == ldiff Usage
|
8
|
+
# ldiff [options] oldfile newfile
|
9
|
+
#
|
10
|
+
# -c:: Displays a context diff with 3 lines of context.
|
11
|
+
# -C [LINES], --context [LINES]:: Displays a context diff with LINES lines of context. Default 3 lines.
|
12
|
+
# -u:: Displays a unified diff with 3 lines of context.
|
13
|
+
# -U [LINES], --unified [LINES]:: Displays a unified diff with LINES lines of context. Default 3 lines.
|
14
|
+
# -e:: Creates an 'ed' script to change oldfile to newfile.
|
15
|
+
# -f:: Creates an 'ed' script to change oldfile to newfile in reverse order.
|
16
|
+
# -a, --text:: Treats the files as text and compares them line-by-line, even if they do not seem to be text.
|
17
|
+
# --binary:: Treats the files as binary.
|
18
|
+
# -q, --brief:: Reports only whether or not the files differ, not the details.
|
19
|
+
# --help:: Shows the command-line help.
|
20
|
+
# --version:: Shows the version of Diff::LCS.
|
21
|
+
#
|
22
|
+
# By default, runs produces an "old-style" diff, with output like UNIX diff.
|
23
|
+
#
|
24
|
+
# == Copyright
|
25
|
+
# Copyright © 2004 Austin Ziegler
|
26
|
+
#
|
27
|
+
# Part of Diff::LCS <http://rubyforge.org/projects/ruwiki/>
|
28
|
+
# Austin Ziegler <diff-lcs@halostatue.ca>
|
29
|
+
#
|
30
|
+
# This program is free software. It may be redistributed and/or modified under
|
31
|
+
# the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
|
32
|
+
# Ruby licence.
|
33
|
+
module Diff::LCS::Ldiff
|
34
|
+
BANNER = <<-COPYRIGHT
|
35
|
+
ldiff #{Diff::LCS::VERSION}
|
36
|
+
Copyright 2004-2013 Austin Ziegler
|
37
|
+
|
38
|
+
Part of Diff::LCS.
|
39
|
+
http://rubyforge.org/projects/ruwiki/
|
40
|
+
|
41
|
+
Austin Ziegler <diff-lcs@halostatue.ca>
|
42
|
+
|
43
|
+
This program is free software. It may be redistributed and/or modified under
|
44
|
+
the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
|
45
|
+
MIT licence.
|
46
|
+
COPYRIGHT
|
47
|
+
end
|
48
|
+
|
49
|
+
class << Diff::LCS::Ldiff
|
50
|
+
attr_reader :format, :lines #:nodoc:
|
51
|
+
attr_reader :file_old, :file_new #:nodoc:
|
52
|
+
attr_reader :data_old, :data_new #:nodoc:
|
53
|
+
|
54
|
+
def run(args, input = $stdin, output = $stdout, error = $stderr) #:nodoc:
|
55
|
+
@binary = nil
|
56
|
+
|
57
|
+
args.options do |o|
|
58
|
+
o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile"
|
59
|
+
o.separator ""
|
60
|
+
o.on('-c', '-C', '--context [LINES]', Numeric, 'Displays a context diff with LINES lines', 'of context. Default 3 lines.') do |ctx|
|
61
|
+
@format = :context
|
62
|
+
@lines = ctx || 3
|
63
|
+
end
|
64
|
+
o.on('-u', '-U', '--unified [LINES]', Numeric, 'Displays a unified diff with LINES lines', 'of context. Default 3 lines.') do |ctx|
|
65
|
+
@format = :unified
|
66
|
+
@lines = ctx || 3
|
67
|
+
end
|
68
|
+
o.on('-e', 'Creates an \'ed\' script to change', 'oldfile to newfile.') do |ctx|
|
69
|
+
@format = :ed
|
70
|
+
end
|
71
|
+
o.on('-f', 'Creates an \'ed\' script to change', 'oldfile to newfile in reverse order.') do |ctx|
|
72
|
+
@format = :reverse_ed
|
73
|
+
end
|
74
|
+
o.on('-a', '--text', 'Treat the files as text and compare them', 'line-by-line, even if they do not seem', 'to be text.') do |txt|
|
75
|
+
@binary = false
|
76
|
+
end
|
77
|
+
o.on('--binary', 'Treats the files as binary.') do |bin|
|
78
|
+
@binary = true
|
79
|
+
end
|
80
|
+
o.on('-q', '--brief', 'Report only whether or not the files', 'differ, not the details.') do |ctx|
|
81
|
+
@format = :report
|
82
|
+
end
|
83
|
+
o.on_tail('--help', 'Shows this text.') do
|
84
|
+
error << o
|
85
|
+
return 0
|
86
|
+
end
|
87
|
+
o.on_tail('--version', 'Shows the version of Diff::LCS.') do
|
88
|
+
error << BANNER
|
89
|
+
return 0
|
90
|
+
end
|
91
|
+
o.on_tail ""
|
92
|
+
o.on_tail 'By default, runs produces an "old-style" diff, with output like UNIX diff.'
|
93
|
+
o.parse!
|
94
|
+
end
|
95
|
+
|
96
|
+
unless args.size == 2
|
97
|
+
error << args.options
|
98
|
+
return 127
|
99
|
+
end
|
100
|
+
|
101
|
+
# Defaults are for old-style diff
|
102
|
+
@format ||= :old
|
103
|
+
@lines ||= 0
|
104
|
+
|
105
|
+
file_old, file_new = *ARGV
|
106
|
+
|
107
|
+
case @format
|
108
|
+
when :context
|
109
|
+
char_old = '*' * 3
|
110
|
+
char_new = '-' * 3
|
111
|
+
when :unified
|
112
|
+
char_old = '-' * 3
|
113
|
+
char_new = '+' * 3
|
114
|
+
end
|
115
|
+
|
116
|
+
# After we've read up to a certain point in each file, the number of
|
117
|
+
# items we've read from each file will differ by FLD (could be 0).
|
118
|
+
file_length_difference = 0
|
119
|
+
|
120
|
+
if @binary.nil? or @binary
|
121
|
+
data_old = IO::read(file_old)
|
122
|
+
data_new = IO::read(file_new)
|
123
|
+
|
124
|
+
# Test binary status
|
125
|
+
if @binary.nil?
|
126
|
+
old_txt = data_old[0...4096].scan(/\0/).empty?
|
127
|
+
new_txt = data_new[0...4096].scan(/\0/).empty?
|
128
|
+
@binary = (not old_txt) or (not new_txt)
|
129
|
+
old_txt = new_txt = nil
|
130
|
+
end
|
131
|
+
|
132
|
+
unless @binary
|
133
|
+
data_old = data_old.split($/).map { |e| e.chomp }
|
134
|
+
data_new = data_new.split($/).map { |e| e.chomp }
|
135
|
+
end
|
136
|
+
else
|
137
|
+
data_old = IO::readlines(file_old).map { |e| e.chomp }
|
138
|
+
data_new = IO::readlines(file_new).map { |e| e.chomp }
|
139
|
+
end
|
140
|
+
|
141
|
+
# diff yields lots of pieces, each of which is basically a Block object
|
142
|
+
if @binary
|
143
|
+
diffs = (data_old == data_new)
|
144
|
+
else
|
145
|
+
diffs = Diff::LCS.diff(data_old, data_new)
|
146
|
+
diffs = nil if diffs.empty?
|
147
|
+
end
|
148
|
+
|
149
|
+
return 0 unless diffs
|
150
|
+
|
151
|
+
if @format == :report
|
152
|
+
output << "Files #{file_old} and #{file_new} differ\n"
|
153
|
+
return 1
|
154
|
+
end
|
155
|
+
|
156
|
+
if (@format == :unified) or (@format == :context)
|
157
|
+
ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
158
|
+
puts "#{char_old} #{file_old}\t#{ft}"
|
159
|
+
ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
160
|
+
puts "#{char_new} #{file_new}\t#{ft}"
|
161
|
+
end
|
162
|
+
|
163
|
+
# Loop over hunks. If a hunk overlaps with the last hunk, join them.
|
164
|
+
# Otherwise, print out the old one.
|
165
|
+
oldhunk = hunk = nil
|
166
|
+
|
167
|
+
if @format == :ed
|
168
|
+
real_output = output
|
169
|
+
output = []
|
170
|
+
end
|
171
|
+
|
172
|
+
diffs.each do |piece|
|
173
|
+
begin
|
174
|
+
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines,
|
175
|
+
file_length_difference)
|
176
|
+
file_length_difference = hunk.file_length_difference
|
177
|
+
|
178
|
+
next unless oldhunk
|
179
|
+
next if (@lines > 0) and hunk.merge(oldhunk)
|
180
|
+
|
181
|
+
output << oldhunk.diff(@format) << "\n"
|
182
|
+
ensure
|
183
|
+
oldhunk = hunk
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
output << oldhunk.diff(@format) << "\n"
|
188
|
+
|
189
|
+
if @format == :ed
|
190
|
+
output.reverse_each { |e| real_output << e.diff(:ed_finish) }
|
191
|
+
end
|
192
|
+
|
193
|
+
return 1
|
194
|
+
end
|
195
|
+
end
|