spacify 0.0.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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +60 -0
- data/Rakefile +74 -0
- data/VERSION +1 -0
- data/bin/spacify +9 -0
- data/lib/html_attribute.treetop +62 -0
- data/lib/html_node_element.treetop +35 -0
- data/lib/html_parser.treetop +21 -0
- data/lib/spacify.rb +247 -0
- data/test/helper.rb +13 -0
- data/test/test_spacify.rb +52 -0
- metadata +99 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Scott Noel-Hemming
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= spacify
|
2
|
+
|
3
|
+
Turn this:
|
4
|
+
|
5
|
+
|
6
|
+
<div id="signin_login_content" class="signin_show">
|
7
|
+
<cfinput type="text" required="yes" tabIndex="1" value="Username / Email" validate="email" name="login_username" message="Missing or invalid username." /> <br />
|
8
|
+
<cfinput name="login_password_default" type="text" tabIndex="2" value="optional password" maxLength="20" class="login_password_w_default subdued" />
|
9
|
+
<cfinput class="login_password_w_default signin_hide" type="Password" required="Yes" tabIndex="3" name="login_password" maxLength="20" validateAt="onServer" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" />
|
10
|
+
<cfinput type="Submit" name="submit" tabIndex="4" value="Lemmie In!" />
|
11
|
+
</div>
|
12
|
+
<div id="signin_register_content" class="signin_show signin_hide">
|
13
|
+
I would like to access the features of your totally awesome site!! I would like to provide my
|
14
|
+
<cfinput name="join_username" type="text" required="yes" tabIndex="5" value="email address" validate="email" message="Missing or invalid username." onclick="if(this.value == this.defaultValue) this.value = '';" />
|
15
|
+
as my username. I would like to provide my
|
16
|
+
<cfinput type="text" required="yes" tabIndex="6" name="join_zip" value="zip code" validate="zipcode" message="Missing or invalid zip." />
|
17
|
+
for location based service. I can provide an
|
18
|
+
<cfinput type="text" tabIndex="7" value="optional password" name="join_password_default" class="join_password_w_default subdued" maxLength="20" />
|
19
|
+
<cfinput name="join_password" type="Password" required="Yes" tabIndex="8" class="join_password_w_default signin_hide" maxLength="20" validateAt="onServer" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" />
|
20
|
+
or one will be sent to me. Please
|
21
|
+
<cfinput name="submit" type="Submit" tabIndex="9" value="sign me up" /> for your service.
|
22
|
+
</div>
|
23
|
+
|
24
|
+
into this:
|
25
|
+
|
26
|
+
<div id="signin_login_content" class="signin_show">
|
27
|
+
<cfinput name="login_username" tabIndex="1" type="text" value="Username / Email" required="yes" message="Missing or invalid username." validate="email" /> <br />
|
28
|
+
<cfinput name="login_password_default" tabIndex="2" type="text" value="optional password" class="login_password_w_default subdued" maxLength="20" />
|
29
|
+
<cfinput name="login_password" tabIndex="3" type="Password" required="Yes" class="login_password_w_default signin_hide" maxLength="20" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" validateAt="onServer" />
|
30
|
+
<cfinput name="submit" tabIndex="4" type="Submit" value="Lemmie In!" />
|
31
|
+
</div>
|
32
|
+
<div id="signin_register_content" class="signin_show signin_hide">
|
33
|
+
I would like to access the features of your totally awesome site!! I would like to provide my
|
34
|
+
<cfinput name="join_username" tabIndex="5" type="text" value="email address" required="yes" message="Missing or invalid username." validate="email" onclick="if(this.value == this.defaultValue) this.value = '';" />
|
35
|
+
as my username. I would like to provide my
|
36
|
+
<cfinput name="join_zip" tabIndex="6" type="text" value="zip code" required="yes" message="Missing or invalid zip." validate="zipcode" />
|
37
|
+
for location based service. I can provide an
|
38
|
+
<cfinput name="join_password_default" tabIndex="7" type="text" value="optional password" class="join_password_w_default subdued" maxLength="20" />
|
39
|
+
<cfinput name="join_password" tabIndex="8" type="Password" required="Yes" class="join_password_w_default signin_hide" maxLength="20" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" validateAt="onServer" />
|
40
|
+
or one will be sent to me. Please
|
41
|
+
<cfinput name="submit" tabIndex="9" type="Submit" value="sign me up" /> for your service.
|
42
|
+
</div>
|
43
|
+
|
44
|
+
Give unformatted code<br />
|
45
|
+
Order by most common attributes,<br />
|
46
|
+
and format the code with spaces.
|
47
|
+
|
48
|
+
== Note on Patches/Pull Requests
|
49
|
+
|
50
|
+
* Fork the project.
|
51
|
+
* Make your feature addition or bug fix.
|
52
|
+
* Add tests for it. This is important so I don't break it in a
|
53
|
+
future version unintentionally.
|
54
|
+
* Commit, do not mess with rakefile, version, or history.
|
55
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
56
|
+
* Send me a pull request. Bonus points for topic branches.
|
57
|
+
|
58
|
+
== Copyright
|
59
|
+
|
60
|
+
Copyright (c) 2010 Scott Noel-Hemming. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "spacify"
|
8
|
+
gem.summary = %Q{Format code with spaces}
|
9
|
+
gem.description = %Q{Format code with spaces}
|
10
|
+
gem.email = "frogstarr78@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/frogstarr78/spacify"
|
12
|
+
gem.authors = ["Scott Noel-Hemming"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "test_equality_with_lcs", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
task :test => :compile
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "spacify #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Compile Treetop files into ruby libs"
|
58
|
+
task :compile do
|
59
|
+
`tt lib/*.treetop`
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "Remove treetop generated libs"
|
63
|
+
task :clean do
|
64
|
+
require 'ftools'
|
65
|
+
def ruby_lib_file_name treetop_file_name
|
66
|
+
treetop_base_name = File.basename( treetop_file_name, 'treetop' )
|
67
|
+
ruby_lib_base_name = treetop_base_name << 'rb'
|
68
|
+
File.join('lib', ruby_lib_base_name )
|
69
|
+
end
|
70
|
+
|
71
|
+
Dir.glob 'lib/*.treetop' do |treetop_file|
|
72
|
+
FileUtils.rm( ruby_lib_file_name treetop_file )
|
73
|
+
end
|
74
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/spacify
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'html_parser'
|
2
|
+
|
3
|
+
grammar HTMLAttribute
|
4
|
+
include HTML
|
5
|
+
|
6
|
+
rule attributes
|
7
|
+
attribute space_n_attributes:( space attribute )* {
|
8
|
+
def to_a
|
9
|
+
@attirbute_array ||= [attribute] + space_n_attributes.elements.collect{|space_n_attribute| space_n_attribute.attribute }
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
return @attribute_hash unless @attribute_hash.nil?
|
14
|
+
|
15
|
+
@attribute_hash = { attribute.attribute_name.to_s => attribute, }
|
16
|
+
space_n_attributes.elements.each{|space_n_attribute|
|
17
|
+
@attribute_hash.update space_n_attribute.attribute.attribute_name.to_s => space_n_attribute.attribute
|
18
|
+
}
|
19
|
+
@attribute_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def [] key_or_index
|
23
|
+
if ( key_or_index.is_a? String and key_or_index =~ /^\d+$/ ) or key_or_index.is_a? Fixnum
|
24
|
+
attributes = self.to_a
|
25
|
+
else
|
26
|
+
attributes = self.to_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
attributes[key_or_index]
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_key? key
|
33
|
+
self.to_hash.has_key? key
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
rule attribute
|
39
|
+
attribute_name equal attribute_value {
|
40
|
+
def to_s
|
41
|
+
text_value
|
42
|
+
end
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
rule attribute_name
|
47
|
+
[_a-zA-Z] [_a-zA-Z0-9]* {
|
48
|
+
def to_s
|
49
|
+
text_value
|
50
|
+
end
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
rule attribute_value
|
55
|
+
( double_quote val:( !double_quote any )* double_quote
|
56
|
+
/ single_quote val:( !single_quote any )* single_quote ) {
|
57
|
+
def to_s
|
58
|
+
val.text_value
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'html_parser'
|
2
|
+
require 'html_attribute'
|
3
|
+
|
4
|
+
grammar HTMLNodeElement
|
5
|
+
include HTML
|
6
|
+
include HTMLAttribute
|
7
|
+
|
8
|
+
rule node
|
9
|
+
# open_node ( ( text / element )+ close_node )*
|
10
|
+
# It'd be something like this if I were creating an HTML parser.
|
11
|
+
# But I'm not. (Notice the disconnect in open/close node detection)
|
12
|
+
|
13
|
+
gt name:( !space any )+ ( space attributes )* space? '/'? lt {
|
14
|
+
def node_name
|
15
|
+
elements[1].text_value
|
16
|
+
end
|
17
|
+
|
18
|
+
def attributes
|
19
|
+
elements[2].elements[0].attributes
|
20
|
+
end
|
21
|
+
|
22
|
+
def empty?
|
23
|
+
elements[4].text_value == '/'
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
rule gt
|
29
|
+
'<'
|
30
|
+
end
|
31
|
+
|
32
|
+
rule lt
|
33
|
+
'>'
|
34
|
+
end
|
35
|
+
end
|
data/lib/spacify.rb
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'treetop'
|
5
|
+
require 'colored'
|
6
|
+
require 'html_node_element'
|
7
|
+
require 'stringio'
|
8
|
+
|
9
|
+
class BaseLine
|
10
|
+
attr_reader :data
|
11
|
+
attr_accessor :attribute_sort_order, :attribute_padding_by_name
|
12
|
+
def initialize data
|
13
|
+
@data = data
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@data
|
22
|
+
end
|
23
|
+
|
24
|
+
def sort_with hash
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class SpacerLine < BaseLine
|
30
|
+
def initialize data, match
|
31
|
+
super data
|
32
|
+
|
33
|
+
@match = match
|
34
|
+
parser = HTMLNodeElementParser.new
|
35
|
+
all, @leading, code, @trailing = data.split /^(\s*)(#@match)(.*)$/
|
36
|
+
@parsed = parser.parse code
|
37
|
+
raise "Unable to parse '#{code}'" if @parsed.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def attributes
|
41
|
+
@parsed.attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse?
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
s = ''
|
50
|
+
s << @leading
|
51
|
+
s << '<'
|
52
|
+
s << @parsed.node_name
|
53
|
+
s << ' '
|
54
|
+
attribute_sort_order.each do |attribute_name|
|
55
|
+
s << whitespace_pad_value_at_key!( attribute_name )
|
56
|
+
end
|
57
|
+
s << '/' if @parsed.empty?
|
58
|
+
s << '>'
|
59
|
+
s << @trailing
|
60
|
+
s << "\n"
|
61
|
+
s
|
62
|
+
end
|
63
|
+
|
64
|
+
def whitespace_pad_value_at_key! key
|
65
|
+
longest = attribute_padding_by_name[key]
|
66
|
+
if self.attributes.has_key? key
|
67
|
+
attribute_value = self.attributes[key].to_s
|
68
|
+
padding_length = longest - attribute_value.size
|
69
|
+
else
|
70
|
+
attribute_value = ''
|
71
|
+
padding_length = longest
|
72
|
+
end
|
73
|
+
|
74
|
+
# s = attribute_value << ( ' ' * padding_length )
|
75
|
+
s = attribute_value
|
76
|
+
s << ' ' * padding_length
|
77
|
+
s
|
78
|
+
end
|
79
|
+
|
80
|
+
def attribute_sort_order= order
|
81
|
+
@attribute_sort_order = case order
|
82
|
+
when Hash; then order.keys
|
83
|
+
when Array
|
84
|
+
if order.first.is_a? Array
|
85
|
+
order.collect(&:first)
|
86
|
+
else
|
87
|
+
order
|
88
|
+
end
|
89
|
+
else
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class RawLine < BaseLine
|
96
|
+
def attribute_sort_order; []; end
|
97
|
+
def attribute_padding_by_name; {}; end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Spacer
|
101
|
+
attr_accessor :lines
|
102
|
+
|
103
|
+
def initialize input, options = {}
|
104
|
+
@line_regexp = options.delete(:html)
|
105
|
+
@io = StringIO.new input
|
106
|
+
@lines = []
|
107
|
+
|
108
|
+
parse!
|
109
|
+
end
|
110
|
+
|
111
|
+
def parse!
|
112
|
+
read_lines!
|
113
|
+
collate_attributes!
|
114
|
+
sort_attribute_counts!
|
115
|
+
find_longest_values!
|
116
|
+
end
|
117
|
+
private :parse!
|
118
|
+
|
119
|
+
def to_s
|
120
|
+
lines.inject('') do |m, line|
|
121
|
+
m += line.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def read_lines!
|
126
|
+
@io.each_line do |line|
|
127
|
+
if line =~ Regexp.new( @line_regexp )
|
128
|
+
parse_line = SpacerLine.new line, @line_regexp
|
129
|
+
else
|
130
|
+
parse_line = RawLine.new line
|
131
|
+
end
|
132
|
+
lines << parse_line
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def collate_attributes!
|
137
|
+
@attribute_counts = {}
|
138
|
+
@attribute_counts.default = 0
|
139
|
+
parsable_lines do |line|
|
140
|
+
attributes = line.attributes.to_a
|
141
|
+
attributes.each do |attribute|
|
142
|
+
@attribute_counts[attribute.attribute_name.to_s] += 1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def sort_attribute_counts!
|
148
|
+
@attribute_counts = @attribute_counts.sort do |(lkey, lval), (rkey, rval)|
|
149
|
+
comp = rval <=> lval
|
150
|
+
if comp == 0
|
151
|
+
lkey <=> rkey
|
152
|
+
else
|
153
|
+
comp
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
lines.each do |line|
|
158
|
+
line.attribute_sort_order = @attribute_counts
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def find_longest_values!
|
163
|
+
@longest_attribute_values = {}
|
164
|
+
@attribute_counts.each do |attribute_name, count|
|
165
|
+
@longest_attribute_values.update attribute_name => find_longest_value_for( attribute_name )
|
166
|
+
end
|
167
|
+
|
168
|
+
lines.each do |line|
|
169
|
+
line.attribute_padding_by_name = @longest_attribute_values
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def find_longest_value_for attribute_name
|
174
|
+
longest = 0
|
175
|
+
parsable_lines do |line|
|
176
|
+
attributes = line.attributes.to_hash
|
177
|
+
if attributes[attribute_name]
|
178
|
+
attribute_value = attributes[attribute_name].to_s
|
179
|
+
longest = attribute_value.size if attribute_value.size > longest
|
180
|
+
end
|
181
|
+
end
|
182
|
+
longest + 1
|
183
|
+
end
|
184
|
+
|
185
|
+
def parsable_lines
|
186
|
+
lines.each {|line|
|
187
|
+
yield line if line.parse?
|
188
|
+
}
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
if __FILE__ == $0
|
193
|
+
def expected
|
194
|
+
%q|
|
195
|
+
<div id="signin_login_content" class="signin_show">
|
196
|
+
<cfinput name="login_username" tabIndex="1" type="text" value="Username / Email" required="yes" message="Missing or invalid username." validate="email" /> <br />
|
197
|
+
<cfinput name="login_password_default" tabIndex="2" type="text" value="optional password" class="login_password_w_default subdued" maxLength="20" />
|
198
|
+
<cfinput name="login_password" tabIndex="3" type="Password" required="Yes" class="login_password_w_default signin_hide" maxLength="20" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" validateAt="onServer" />
|
199
|
+
<cfinput name="submit" tabIndex="4" type="Submit" value="Lemmie In!" />
|
200
|
+
</div>
|
201
|
+
<div id="signin_register_content" class="signin_show signin_hide">
|
202
|
+
I would like to access the features of your totally awesome site!! I would like to provide my
|
203
|
+
<cfinput name="join_username" tabIndex="5" type="text" value="email address" required="yes" message="Missing or invalid username." validate="email" onclick="if(this.value == this.defaultValue) this.value = '';" />
|
204
|
+
as my username. I would like to provide my
|
205
|
+
<cfinput name="join_zip" tabIndex="6" type="text" value="zip code" required="yes" message="Missing or invalid zip." validate="zipcode" />
|
206
|
+
for location based service. I can provide an
|
207
|
+
<cfinput name="join_password_default" tabIndex="7" type="text" value="optional password" class="join_password_w_default subdued" maxLength="20" />
|
208
|
+
<cfinput name="join_password" tabIndex="8" type="Password" required="Yes" class="join_password_w_default signin_hide" maxLength="20" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" validateAt="onServer" />
|
209
|
+
or one will be sent to me. Please
|
210
|
+
<cfinput name="submit" tabIndex="9" type="Submit" value="sign me up" /> for your service.
|
211
|
+
</div>
|
212
|
+
|
|
213
|
+
end
|
214
|
+
|
215
|
+
def input
|
216
|
+
%q|
|
217
|
+
<div id="signin_login_content" class="signin_show">
|
218
|
+
<cfinput type="text" required="yes" tabIndex="1" value="Username / Email" validate="email" name="login_username" message="Missing or invalid username." /> <br />
|
219
|
+
<cfinput name="login_password_default" type="text" tabIndex="2" value="optional password" maxLength="20" class="login_password_w_default subdued" />
|
220
|
+
<cfinput class="login_password_w_default signin_hide" type="Password" required="Yes" tabIndex="3" name="login_password" maxLength="20" validateAt="onServer" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" />
|
221
|
+
<cfinput type="Submit" name="submit" tabIndex="4" value="Lemmie In!" />
|
222
|
+
</div>
|
223
|
+
<div id="signin_register_content" class="signin_show signin_hide">
|
224
|
+
I would like to access the features of your totally awesome site!! I would like to provide my
|
225
|
+
<cfinput name="join_username" type="text" required="yes" tabIndex="5" value="email address" validate="email" message="Missing or invalid username." onclick="if(this.value == this.defaultValue) this.value = '';" />
|
226
|
+
as my username. I would like to provide my
|
227
|
+
<cfinput type="text" required="yes" tabIndex="6" name="join_zip" value="zip code" validate="zipcode" message="Missing or invalid zip." />
|
228
|
+
for location based service. I can provide an
|
229
|
+
<cfinput type="text" tabIndex="7" value="optional password" name="join_password_default" class="join_password_w_default subdued" maxLength="20" />
|
230
|
+
<cfinput name="join_password" type="Password" required="Yes" tabIndex="8" class="join_password_w_default signin_hide" maxLength="20" validateAt="onServer" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" />
|
231
|
+
or one will be sent to me. Please
|
232
|
+
<cfinput name="submit" type="Submit" tabIndex="9" value="sign me up" /> for your service.
|
233
|
+
</div>
|
234
|
+
|
|
235
|
+
end
|
236
|
+
|
237
|
+
s = Spacer.new input, :html => '<cfinput[^>]+>'
|
238
|
+
puts s.to_s == expected ? 'true'.green : 'false'.red
|
239
|
+
|
240
|
+
#h = { :a => 3, :b => 0, :c => 1 }
|
241
|
+
#
|
242
|
+
#h = h.sort do |(lk,lv),(rk,rv)|
|
243
|
+
## puts [lk, lv, rk, rv].inspect
|
244
|
+
# rv <=> lv
|
245
|
+
#end
|
246
|
+
#puts h.inspect
|
247
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test_equality_with_lcs'
|
4
|
+
require 'test_equality_with_lcs/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'spacify'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
include TestEqualityWithLCS::Unit
|
13
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class SpacifyTest < Test::Unit::TestCase
|
4
|
+
def test_output
|
5
|
+
spacer = Spacer.new input, :html => '<cfinput[^>]+>'
|
6
|
+
assert_equal_with_lcs expected, spacer.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def expected
|
10
|
+
%q|
|
11
|
+
<div id="signin_login_content" class="signin_show">
|
12
|
+
<cfinput name="login_username" tabIndex="1" type="text" value="Username / Email" required="yes" message="Missing or invalid username." validate="email" /> <br />
|
13
|
+
<cfinput name="login_password_default" tabIndex="2" type="text" value="optional password" class="login_password_w_default subdued" maxLength="20" />
|
14
|
+
<cfinput name="login_password" tabIndex="3" type="Password" required="Yes" class="login_password_w_default signin_hide" maxLength="20" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" validateAt="onServer" />
|
15
|
+
<cfinput name="submit" tabIndex="4" type="Submit" value="Lemmie In!" />
|
16
|
+
</div>
|
17
|
+
<div id="signin_register_content" class="signin_show signin_hide">
|
18
|
+
I would like to access the features of your totally awesome site!! I would like to provide my
|
19
|
+
<cfinput name="join_username" tabIndex="5" type="text" value="email address" required="yes" message="Missing or invalid username." validate="email" onclick="if(this.value == this.defaultValue) this.value = '';" />
|
20
|
+
as my username. I would like to provide my
|
21
|
+
<cfinput name="join_zip" tabIndex="6" type="text" value="zip code" required="yes" message="Missing or invalid zip." validate="zipcode" />
|
22
|
+
for location based service. I can provide an
|
23
|
+
<cfinput name="join_password_default" tabIndex="7" type="text" value="optional password" class="join_password_w_default subdued" maxLength="20" />
|
24
|
+
<cfinput name="join_password" tabIndex="8" type="Password" required="Yes" class="join_password_w_default signin_hide" maxLength="20" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" validateAt="onServer" />
|
25
|
+
or one will be sent to me. Please
|
26
|
+
<cfinput name="submit" tabIndex="9" type="Submit" value="sign me up" /> for your service.
|
27
|
+
</div>
|
28
|
+
|
|
29
|
+
end
|
30
|
+
|
31
|
+
def input
|
32
|
+
%q|
|
33
|
+
<div id="signin_login_content" class="signin_show">
|
34
|
+
<cfinput type="text" required="yes" tabIndex="1" value="Username / Email" validate="email" name="login_username" message="Missing or invalid username." /> <br />
|
35
|
+
<cfinput name="login_password_default" type="text" tabIndex="2" value="optional password" maxLength="20" class="login_password_w_default subdued" />
|
36
|
+
<cfinput class="login_password_w_default signin_hide" type="Password" required="Yes" tabIndex="3" name="login_password" maxLength="20" validateAt="onServer" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" />
|
37
|
+
<cfinput type="Submit" name="submit" tabIndex="4" value="Lemmie In!" />
|
38
|
+
</div>
|
39
|
+
<div id="signin_register_content" class="signin_show signin_hide">
|
40
|
+
I would like to access the features of your totally awesome site!! I would like to provide my
|
41
|
+
<cfinput name="join_username" type="text" required="yes" tabIndex="5" value="email address" validate="email" message="Missing or invalid username." onclick="if(this.value == this.defaultValue) this.value = '';" />
|
42
|
+
as my username. I would like to provide my
|
43
|
+
<cfinput type="text" required="yes" tabIndex="6" name="join_zip" value="zip code" validate="zipcode" message="Missing or invalid zip." />
|
44
|
+
for location based service. I can provide an
|
45
|
+
<cfinput type="text" tabIndex="7" value="optional password" name="join_password_default" class="join_password_w_default subdued" maxLength="20" />
|
46
|
+
<cfinput name="join_password" type="Password" required="Yes" tabIndex="8" class="join_password_w_default signin_hide" maxLength="20" validateAt="onServer" onBlur="if(this.value != '' ) this.value = calcMD5(this.value)" />
|
47
|
+
or one will be sent to me. Please
|
48
|
+
<cfinput name="submit" type="Submit" tabIndex="9" value="sign me up" /> for your service.
|
49
|
+
</div>
|
50
|
+
|
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spacify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Scott Noel-Hemming
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-07 00:00:00 -07:00
|
18
|
+
default_executable: spacify
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: test_equality_with_lcs
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
description: Format code with spaces
|
45
|
+
email: frogstarr78@gmail.com
|
46
|
+
executables:
|
47
|
+
- spacify
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files:
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
files:
|
54
|
+
- .document
|
55
|
+
- .gitignore
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
- Rakefile
|
59
|
+
- VERSION
|
60
|
+
- bin/spacify
|
61
|
+
- lib/html_attribute.treetop
|
62
|
+
- lib/html_node_element.treetop
|
63
|
+
- lib/html_parser.treetop
|
64
|
+
- lib/spacify.rb
|
65
|
+
- test/helper.rb
|
66
|
+
- test/test_spacify.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/frogstarr78/spacify
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Format code with spaces
|
97
|
+
test_files:
|
98
|
+
- test/test_spacify.rb
|
99
|
+
- test/helper.rb
|