bbcode 0.0.1 → 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Ezra Zygmuntowicz
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/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ lib/bbcode.rb
2
+ LICENSE
3
+ TODO
4
+ README
5
+ Manifest
6
+ Rakefile
data/README ADDED
File without changes
data/Rakefile CHANGED
@@ -1,28 +1,13 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
- require File.dirname(__FILE__) + '/lib/bbcode'
1
+ require 'echoe'
3
2
 
4
- # Generate all the Rake tasks
5
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('bbcode', Bbcode::VERSION) do |p|
7
- p.developer('FIXME full name', 'FIXME email')
8
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
- p.rubyforge_name = p.name # TODO this is default value
11
- # p.extra_deps = [
12
- # ['activesupport','>= 2.0.2'],
13
- # ]
14
- p.extra_dev_deps = [
15
- ['newgem', ">= #{::Newgem::VERSION}"]
16
- ]
17
-
18
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
- p.rsync_args = '-av --delete --ignore-errors'
22
- end
3
+ Echoe.new("bbcode") do |p|
4
+ p.author = "eiffel qiu"
5
+ p.description = "A tool to beautify code."
6
+ p.summary = "A tool to beautify code."
7
+ p.url = "http://www.likenote.com"
8
+ p.email = "eiffelqiu@gmail.com"
9
+ p.version = "0.0.2"
10
+ #p.docs_host = "uncapitalizer.com:~/www/files/doc/"
11
+ #p.runtime_dependencies = ["string_tools >=1.4.0"]
12
+ end
23
13
 
24
- require 'newgem/tasks' # load /tasks/*.rake
25
- Dir['tasks/**/*.rake'].each { |t| load t }
26
-
27
- # TODO - want other tests/tasks run by default? Add them to the list
28
- # task :default => [:spec, :features]
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ TODO:
2
+
data/bbcode.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{bbcode}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["eiffel qiu"]
9
+ s.date = %q{2009-04-11}
10
+ s.description = %q{A tool to beautify code.}
11
+ s.email = %q{eiffelqiu@gmail.com}
12
+ s.extra_rdoc_files = ["lib/bbcode.rb", "LICENSE", "TODO", "README"]
13
+ s.files = ["lib/bbcode.rb", "LICENSE", "TODO", "README", "Manifest", "Rakefile", "bbcode.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://www.likenote.com}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bbcode", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{bbcode}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{A tool to beautify code.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
data/lib/bbcode.rb CHANGED
@@ -1,6 +1,186 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- module Bbcode
5
- VERSION = '0.0.1'
6
- end
1
+ module Bbcode
2
+
3
+ # user-customizable values
4
+
5
+ Bbcode::TabStr = " "
6
+ Bbcode::TabSize = 4
7
+
8
+ # indent regexp tests
9
+
10
+ IndentExp = [
11
+ /^module\b/,
12
+ /^class\b/,
13
+ /^if\b/,
14
+ /(=\s*|^)until\b/,
15
+ /(=\s*|^)for\b/,
16
+ /^unless\b/,
17
+ /(=\s*|^)while\b/,
18
+ /(=\s*|^)begin\b/,
19
+ /(^| )case\b/,
20
+ /\bthen\b/,
21
+ /^rescue\b/,
22
+ /^def\b/,
23
+ /\bdo\b/,
24
+ /^else\b/,
25
+ /^elsif\b/,
26
+ /^ensure\b/,
27
+ /\bwhen\b/,
28
+ /\{[^\}]*$/,
29
+ /\[[^\]]*$/
30
+ ]
31
+
32
+ # outdent regexp tests
33
+
34
+ OutdentExp = [
35
+ /^rescue\b/,
36
+ /^ensure\b/,
37
+ /^elsif\b/,
38
+ /^end\b/,
39
+ /^else\b/,
40
+ /\bwhen\b/,
41
+ /^[^\{]*\}/,
42
+ /^[^\[]*\]/
43
+ ]
44
+
45
+ def self.included(base)
46
+ base.send(:extend, ClassMethods)
47
+ end
48
+
49
+ module ClassMethods
50
+
51
+ def rb_make_tab(tab)
52
+ return (tab < 0) ? "" : TabStr * TabSize * tab
53
+ end
54
+
55
+ def rb_add_line(line,tab)
56
+ line.strip!
57
+ line = rb_make_tab(tab) + line if line.length > 0
58
+ return line
59
+ end
60
+
61
+ def beautify_string(source, path = "")
62
+ comment_block = false
63
+ in_here_doc = false
64
+ here_doc_term = ""
65
+ program_end = false
66
+ multiLine_array = []
67
+ multiLine_str = ""
68
+ tab = 0
69
+ output = []
70
+ source.each do |line|
71
+ line.chomp!
72
+ if(!program_end)
73
+ # detect program end mark
74
+ if(line =~ /^__END__$/)
75
+ program_end = true
76
+ else
77
+ # combine continuing lines
78
+ if(!(line =~ /^\s*#/) && line =~ /[^\\]\\\s*$/)
79
+ multiLine_array.push line
80
+ multiLine_str += line.sub(/^(.*)\\\s*$/,"\\1")
81
+ next
82
+ end
83
+
84
+ # add final line
85
+ if(multiLine_str.length > 0)
86
+ multiLine_array.push line
87
+ multiLine_str += line.sub(/^(.*)\\\s*$/,"\\1")
88
+ end
89
+
90
+ tline = ((multiLine_str.length > 0)?multiLine_str:line).strip
91
+ if(tline =~ /^=begin/)
92
+ comment_block = true
93
+ end
94
+ if(in_here_doc)
95
+ in_here_doc = false if tline =~ %r{\s*#{here_doc_term}\s*}
96
+ else # not in here_doc
97
+ if tline =~ %r{=\s*<<}
98
+ here_doc_term = tline.sub(%r{.*=\s*<<-?\s*([_|\w]+).*},"\\1")
99
+ in_here_doc = here_doc_term.size > 0
100
+ end
101
+ end
102
+ end
103
+ end
104
+ if(comment_block || program_end || in_here_doc)
105
+ # add the line unchanged
106
+ output << line
107
+ else
108
+ comment_line = (tline =~ /^#/)
109
+ if(!comment_line)
110
+ # throw out sequences that will
111
+ # only sow confusion
112
+ while tline.gsub!(/\{[^\{]*?\}/,"")
113
+ end
114
+ while tline.gsub!(/\[[^\[]*?\]/,"")
115
+ end
116
+ while tline.gsub!(/'.*?'/,"")
117
+ end
118
+ while tline.gsub!(/".*?"/,"")
119
+ end
120
+ while tline.gsub!(/\`.*?\`/,"")
121
+ end
122
+ while tline.gsub!(/\([^\(]*?\)/,"")
123
+ end
124
+ while tline.gsub!(/\/.*?\//,"")
125
+ end
126
+ while tline.gsub!(/%r(.).*?\1/,"")
127
+ end
128
+ # delete end-of-line comments
129
+ tline.sub!(/#[^\"]+$/,"")
130
+ # convert quotes
131
+ tline.gsub!(/\\\"/,"'")
132
+ OutdentExp.each do |re|
133
+ if(tline =~ re)
134
+ tab -= 1
135
+ break
136
+ end
137
+ end
138
+ end
139
+ if (multiLine_array.length > 0)
140
+ multiLine_array.each do |ml|
141
+ output << rb_add_line(ml,tab)
142
+ end
143
+ multiLine_array.clear
144
+ multiLine_str = ""
145
+ else
146
+ output << rb_add_line(line,tab)
147
+ end
148
+ if(!comment_line)
149
+ IndentExp.each do |re|
150
+ if(tline =~ re && !(tline =~ /\s+end\s*$/))
151
+ tab += 1
152
+ break
153
+ end
154
+ end
155
+ end
156
+ end
157
+ if(tline =~ /^=end/)
158
+ comment_block = false
159
+ end
160
+ end
161
+ error = (tab != 0)
162
+ STDERR.puts "Error: indent/outdent mismatch: #{tab}." if error
163
+ return output.join("\n") + "\n",error
164
+ end # beautify_string
165
+
166
+ def beautify_file(path)
167
+ error = false
168
+ if(path == '-') # stdin source
169
+ source = STDIN.read
170
+ dest,error = beautify_string(source,"stdin")
171
+ print dest
172
+ else # named file source
173
+ source = File.read(path)
174
+ dest,error = beautify_string(source,path)
175
+ if(source != dest)
176
+ # make a backup copy
177
+ File.open(path + "~","w") { |f| f.write(source) }
178
+ # overwrite the original
179
+ File.open(path,"w") { |f| f.write(dest) }
180
+ end
181
+ end
182
+ return error
183
+ end # beautify_file
184
+ end
185
+
186
+ end # module Bbcode
metadata CHANGED
@@ -1,67 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - FIXME full name
7
+ - eiffel qiu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-31 00:00:00 +08:00
12
+ date: 2009-04-11 00:00:00 +08:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: newgem
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.2.2
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: hoe
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.8.0
34
- version:
35
- description: FIX (describe your package)
36
- email:
37
- - FIXME email
14
+ dependencies: []
15
+
16
+ description: A tool to beautify code.
17
+ email: eiffelqiu@gmail.com
38
18
  executables: []
39
19
 
40
20
  extensions: []
41
21
 
42
22
  extra_rdoc_files:
43
- - History.txt
44
- - Manifest.txt
45
- - PostInstall.txt
46
- - README.rdoc
23
+ - lib/bbcode.rb
24
+ - LICENSE
25
+ - TODO
26
+ - README
47
27
  files:
48
- - History.txt
49
- - Manifest.txt
50
- - PostInstall.txt
51
- - README.rdoc
52
- - Rakefile
53
28
  - lib/bbcode.rb
54
- - script/console
55
- - script/destroy
56
- - script/generate
57
- - test/test_bbcode.rb
58
- - test/test_helper.rb
29
+ - LICENSE
30
+ - TODO
31
+ - README
32
+ - Manifest
33
+ - Rakefile
34
+ - bbcode.gemspec
59
35
  has_rdoc: true
60
- homepage: FIX (url)
61
- post_install_message: PostInstall.txt
36
+ homepage: http://www.likenote.com
37
+ post_install_message:
62
38
  rdoc_options:
39
+ - --line-numbers
40
+ - --inline-source
41
+ - --title
42
+ - Bbcode
63
43
  - --main
64
- - README.rdoc
44
+ - README
65
45
  require_paths:
66
46
  - lib
67
47
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -74,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
54
  requirements:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
- version: "0"
57
+ version: "1.2"
78
58
  version:
79
59
  requirements: []
80
60
 
@@ -82,7 +62,6 @@ rubyforge_project: bbcode
82
62
  rubygems_version: 1.3.1
83
63
  signing_key:
84
64
  specification_version: 2
85
- summary: FIX (describe your package)
86
- test_files:
87
- - test/test_bbcode.rb
88
- - test/test_helper.rb
65
+ summary: A tool to beautify code.
66
+ test_files: []
67
+
data/History.txt DELETED
@@ -1,4 +0,0 @@
1
- == 0.0.1 2008-12-31
2
-
3
- * 1 major enhancement:
4
- * Initial release
data/Manifest.txt DELETED
@@ -1,11 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- PostInstall.txt
4
- README.rdoc
5
- Rakefile
6
- lib/bbcode.rb
7
- script/console
8
- script/destroy
9
- script/generate
10
- test/test_bbcode.rb
11
- test/test_helper.rb
data/PostInstall.txt DELETED
@@ -1,7 +0,0 @@
1
-
2
- For more information on bbcode, see http://bbcode.rubyforge.org
3
-
4
- NOTE: Change this information in PostInstall.txt
5
- You can also delete it if you don't want it.
6
-
7
-
data/README.rdoc DELETED
@@ -1,48 +0,0 @@
1
- = bbcode
2
-
3
- * FIX (url)
4
-
5
- == DESCRIPTION:
6
-
7
- FIX (describe your package)
8
-
9
- == FEATURES/PROBLEMS:
10
-
11
- * FIX (list of features or problems)
12
-
13
- == SYNOPSIS:
14
-
15
- FIX (code sample of usage)
16
-
17
- == REQUIREMENTS:
18
-
19
- * FIX (list of requirements)
20
-
21
- == INSTALL:
22
-
23
- * FIX (sudo gem install, anything else)
24
-
25
- == LICENSE:
26
-
27
- (The MIT License)
28
-
29
- Copyright (c) 2008 FIXME full name
30
-
31
- Permission is hereby granted, free of charge, to any person obtaining
32
- a copy of this software and associated documentation files (the
33
- 'Software'), to deal in the Software without restriction, including
34
- without limitation the rights to use, copy, modify, merge, publish,
35
- distribute, sublicense, and/or sell copies of the Software, and to
36
- permit persons to whom the Software is furnished to do so, subject to
37
- the following conditions:
38
-
39
- The above copyright notice and this permission notice shall be
40
- included in all copies or substantial portions of the Software.
41
-
42
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/script/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/bbcode.rb'}"
9
- puts "Loading bbcode gem"
10
- exec "#{irb} #{libs} --simple-prompt"
data/script/destroy DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
data/test/test_bbcode.rb DELETED
@@ -1,11 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestBbcode < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end
data/test/test_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'stringio'
2
- require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/bbcode'