lazibi 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.autotest +44 -2
  2. data/History.txt +10 -1
  3. data/Manifest.txt +114 -91
  4. data/README.txt +4 -125
  5. data/Rakefile +20 -10
  6. data/config/lazibi_config_template.rb +15 -0
  7. data/lib/core/beautify_engine.rb +10 -0
  8. data/lib/core/default_engine.rb +11 -0
  9. data/lib/core/engine_base.rb +74 -0
  10. data/lib/filter/beautify_filter.rb +148 -0
  11. data/lib/filter/filter_base.rb +19 -0
  12. data/lib/filter/optional_do_filter.rb +66 -0
  13. data/lib/filter/optional_end_filter.rb +124 -0
  14. data/lib/filter/syntax_guard_filter.rb +77 -0
  15. data/lib/helper/application_helper.rb +9 -0
  16. data/lib/helper/beautify_filter_helper.rb +52 -0
  17. data/lib/helper/filter_helper.rb +133 -0
  18. data/lib/helper/task_helper.rb +53 -45
  19. data/lib/lazibi.rb +1 -4
  20. data/lib/lazibi/version.rb +1 -1
  21. data/lib/task.rb +41 -32
  22. data/spec/core/beautify_engine_spec.rb +12 -0
  23. data/spec/core/default_engine_spec.rb +28 -0
  24. data/spec/core/engine_base_spec.rb +23 -0
  25. data/spec/filter/beautify_filter_spec.rb +64 -0
  26. data/spec/filter/filter_spec_helper.rb +9 -0
  27. data/spec/filter/optional_do_filter_spec.rb +56 -0
  28. data/spec/filter/optional_end_filter_spec.rb +84 -0
  29. data/spec/filter/syntax_guard_filter_spec.rb +35 -0
  30. data/spec/fixtures/beautify/metas/square_brackets.txt +6 -0
  31. data/{test/fixtures/functional/ruby → spec/fixtures/beautify/rbs}/square_brackets.txt +1 -1
  32. data/{test → spec}/fixtures/clean/comment_break.txt +0 -0
  33. data/{test → spec}/fixtures/clean/complex_string.txt +0 -0
  34. data/{test → spec}/fixtures/clean/end_concat.txt +0 -0
  35. data/{test → spec}/fixtures/clean/long_indent.txt +0 -0
  36. data/{test → spec}/fixtures/clean/mixed_re.txt +0 -0
  37. data/{test → spec}/fixtures/clean/only_if.txt +0 -0
  38. data/{test → spec}/fixtures/clean/re.txt +0 -0
  39. data/{test → spec}/fixtures/clean/semi_colon_after_end.txt +0 -0
  40. data/{test → spec}/fixtures/clean/sep_line.txt +0 -0
  41. data/{test → spec}/fixtures/clean/unless_problem.txt +0 -0
  42. data/{test → spec}/fixtures/meta/basic_class.txt +0 -0
  43. data/{test → spec}/fixtures/meta/case.txt +0 -0
  44. data/{test → spec}/fixtures/meta/class_with_def.txt +0 -0
  45. data/{test → spec}/fixtures/meta/comment.txt +0 -0
  46. data/{test → spec}/fixtures/meta/comment_after_end.txt +0 -0
  47. data/{test → spec}/fixtures/meta/eval_code.txt +0 -0
  48. data/{test → spec}/fixtures/meta/here_doc.txt +0 -0
  49. data/{test → spec}/fixtures/meta/inline_do_end.txt +0 -0
  50. data/{test → spec}/fixtures/meta/inline_end.txt +0 -0
  51. data/{test → spec}/fixtures/meta/loop.txt +0 -0
  52. data/{test → spec}/fixtures/meta/middle.txt +0 -0
  53. data/{test → spec}/fixtures/meta/multi_blocks.txt +0 -0
  54. data/{test → spec}/fixtures/meta/nested_comment.txt +0 -0
  55. data/{test → spec}/fixtures/meta/optional_do.txt +0 -0
  56. data/{test → spec}/fixtures/meta/optional_do_with_nasty_chars.txt +0 -0
  57. data/{test → spec}/fixtures/meta/partial_method.txt +0 -0
  58. data/{test → spec}/fixtures/meta/single_method.txt +0 -0
  59. data/{test → spec}/fixtures/meta/two_methods.txt +0 -0
  60. data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/brackets_block.txt +0 -0
  61. data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/classical.txt +0 -0
  62. data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/describe.txt +0 -0
  63. data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/do_block.txt +0 -0
  64. data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/lambda.txt +0 -0
  65. data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/square_brackets.txt +2 -2
  66. data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/brackets_block.txt +0 -0
  67. data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/classical.txt +0 -0
  68. data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/describe.txt +0 -0
  69. data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/do_block.txt +0 -0
  70. data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/lambda.txt +0 -0
  71. data/spec/fixtures/optional_do/rbs/square_brackets.txt +6 -0
  72. data/{test → spec}/fixtures/real/basic_class.txt +0 -0
  73. data/{test → spec}/fixtures/real/case.txt +0 -0
  74. data/{test → spec}/fixtures/real/class_with_def.txt +0 -0
  75. data/{test → spec}/fixtures/real/comment.txt +0 -0
  76. data/{test → spec}/fixtures/real/comment_after_end.txt +0 -0
  77. data/{test → spec}/fixtures/real/comment_after_end_expected.txt +0 -0
  78. data/{test → spec}/fixtures/real/comment_break.txt +0 -0
  79. data/{test → spec}/fixtures/real/complex_string.txt +0 -0
  80. data/{test → spec}/fixtures/real/end_concat.txt +0 -0
  81. data/{test → spec}/fixtures/real/eval_code.txt +0 -0
  82. data/{test → spec}/fixtures/real/general_eval.txt +0 -0
  83. data/{test → spec}/fixtures/real/here_doc.txt +0 -0
  84. data/{test → spec}/fixtures/real/inline_do_end.txt +0 -0
  85. data/{test → spec}/fixtures/real/inline_end.txt +0 -0
  86. data/{test → spec}/fixtures/real/javascript.txt +0 -0
  87. data/{test → spec}/fixtures/real/long_indent.txt +0 -0
  88. data/{test → spec}/fixtures/real/loop.txt +0 -0
  89. data/{test → spec}/fixtures/real/middle.txt +0 -0
  90. data/{test → spec}/fixtures/real/mixed_re.txt +0 -0
  91. data/{test → spec}/fixtures/real/multi_blocks.txt +0 -0
  92. data/{test → spec}/fixtures/real/nested_comment.txt +0 -0
  93. data/{test → spec}/fixtures/real/only_if.txt +0 -0
  94. data/{test → spec}/fixtures/real/optional_do.txt +0 -0
  95. data/{test → spec}/fixtures/real/optional_do_with_nasty_chars.txt +0 -0
  96. data/{test → spec}/fixtures/real/partial_method.txt +0 -0
  97. data/{test → spec}/fixtures/real/re.txt +0 -0
  98. data/{test → spec}/fixtures/real/semi_colon_after_end.txt +0 -0
  99. data/{test → spec}/fixtures/real/sep_line.txt +0 -0
  100. data/{test → spec}/fixtures/real/single_method.txt +0 -0
  101. data/{test → spec}/fixtures/real/strange_syntax_1.txt +0 -0
  102. data/{test → spec}/fixtures/real/two_methods.txt +0 -0
  103. data/{test → spec}/fixtures/real/unless_problem.txt +0 -0
  104. data/spec/helper/filter_helper_spec.rb +35 -0
  105. data/spec/helper/task_helper_spec.rb +21 -0
  106. data/spec/lazibi_spec.rb +22 -0
  107. data/spec/spec_helper.rb +16 -0
  108. data/webgen/src/code/examples/migration.py.rb +10 -0
  109. data/webgen/src/code/examples/rspec.py.rb +7 -0
  110. data/webgen/src/css/blossom_base.css +172 -0
  111. data/webgen/src/css/blossom_v05.css +48 -0
  112. data/webgen/src/css/code.css +32 -0
  113. data/webgen/src/css/hack.css +13 -0
  114. data/webgen/src/css/print.css +178 -0
  115. data/webgen/src/default.template +90 -0
  116. data/webgen/src/development.page +19 -0
  117. data/webgen/src/documentation.page +44 -0
  118. data/webgen/src/faq.page +42 -0
  119. data/webgen/src/images/cover_landscape.jpg +0 -0
  120. data/webgen/src/images/example_picture03.jpg +0 -0
  121. data/webgen/src/images/example_picture04.jpg +0 -0
  122. data/webgen/src/index.page +45 -0
  123. data/webgen/src/installation.page +17 -0
  124. metadata +214 -175
  125. data/coverage/index.html +0 -476
  126. data/coverage/lib-helper-parser_helper_rb.html +0 -718
  127. data/coverage/lib-helper-task_helper_rb.html +0 -684
  128. data/coverage/lib-lazibi-version_rb.html +0 -640
  129. data/coverage/lib-lazibi_rb.html +0 -664
  130. data/coverage/lib-parser_rb.html +0 -787
  131. data/coverage/lib-task_rb.html +0 -751
  132. data/lib/helper/app_helper.rb +0 -0
  133. data/lib/helper/parser_helper.rb +0 -92
  134. data/lib/parser.rb +0 -194
  135. data/lib/vendor/beautifier.rb +0 -278
  136. data/test/test_functional.rb +0 -75
  137. data/test/test_helper.rb +0 -7
  138. data/test/test_unit.rb +0 -151
  139. data/website/index.html +0 -234
  140. data/website/index.txt +0 -135
  141. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  142. data/website/stylesheets/screen.css +0 -140
  143. data/website/template.rhtml +0 -48
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'beautify_engine'
3
+
4
+ describe 'BeautifyEngine' do
5
+ before(:each) do
6
+ @e = BeautifyEngine.new
7
+ end
8
+
9
+ it "should beautify" do
10
+ @e.up(' def class; end').should == "def class; end\n"
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'default_engine'
3
+
4
+ describe 'DefaultEngine' do
5
+ include Helper::ApplicationHelper
6
+ before(:each) do
7
+ @e = DefaultEngine.new
8
+ end
9
+
10
+ it "should stack filters" do
11
+ rb = " def\n it do\n puts\n end\nend"
12
+ meta ="def\n it\n puts"
13
+ rb_clean = "def\n it do\n puts\n end\nend"
14
+ @e.up(rb).should == meta
15
+ @e.down(meta).should == rb_clean
16
+ end
17
+
18
+ it 'should skip' do
19
+ rb = '<<-HERE abc HERE'
20
+ @e.up(rb).should =~ /^#/
21
+ end
22
+
23
+ it 'should preserved skipped rb' do
24
+ rb = '<<-HERE abc HERE'
25
+ meta = @e.up(rb)
26
+ @e.down(meta).should == rb
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'engine_base'
3
+
4
+ describe 'EngineBase' do
5
+ before(:each) do
6
+ @e = EngineBase.new
7
+ end
8
+
9
+ it "should be able to go_up" do
10
+ @e.go_up(:beautify)
11
+ @e.up(' def;end').should == "def;end\n"
12
+ end
13
+
14
+ it "should stack filters" do
15
+ rb = " def\n it do\n puts\n end\nend"
16
+ meta ="def\n it\n puts"
17
+ rb_clean = "def\n it do\n puts\n end\nend"
18
+ @e.go_up(:beautify, :optional_end, :optional_do)
19
+ @e.up(rb).should == meta
20
+ @e.go_down(:optional_do, :optional_end)
21
+ @e.down(meta).should == rb_clean
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/filter_spec_helper'
2
+
3
+ module Lazibi
4
+ module Spec
5
+ describe 'BeautifyFilter' do
6
+ before(:all) do
7
+ @f = Beautify.new
8
+
9
+ # load fixtures
10
+ @p_rbs = {}
11
+ @p_metas = {}
12
+
13
+
14
+ expected_dir = FIXTURE_DIR + '/real'
15
+ Dir.open(expected_dir).each do |fn|
16
+ next unless fn =~ /[.]txt$/
17
+ @p_rbs[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(expected_dir + "/#{fn}")
18
+ end
19
+
20
+ clean_dir = FIXTURE_DIR + '/clean'
21
+ Dir.open(clean_dir).each do |fn|
22
+ next unless fn =~ /[.]txt$/
23
+ @p_metas[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(clean_dir + "/#{fn}")
24
+ end
25
+
26
+ @rbs = {}
27
+ @metas = {}
28
+
29
+
30
+ rb_dir = FIXTURE_DIR + '/beautify/rbs'
31
+ Dir.open(rb_dir).each do |fn|
32
+ next unless fn =~ /[.]txt$/
33
+ @rbs[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(rb_dir + "/#{fn}")
34
+ end
35
+
36
+ meta_dir = FIXTURE_DIR + '/beautify/metas'
37
+ Dir.open(meta_dir).each do |fn|
38
+ next unless fn =~ /[.]txt$/
39
+ @metas[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(meta_dir + "/#{fn}")
40
+ end
41
+ end
42
+
43
+ it "should beautify public" do
44
+ @p_metas.keys.each do |k|
45
+ @f.up(@p_rbs[k]).should == @p_metas[k]
46
+ end
47
+ end
48
+
49
+ it 'should clean str.gsub(/([^ \/a-zA-Z0-9_.-])/n)' do
50
+ @f.clean_line('str.gsub(/([^ \/a-zA-Z0-9_.-])/n)').should == 'str.gsub(//n)'
51
+ end
52
+
53
+ it 'should clean %r{\A#{Regexp.escape(expanded_root)}(/|\\)}' do
54
+ @f.clean_line('%r{\A#{Regexp.escape(expanded_root)}(/|\\)}').should == "''"
55
+ end
56
+
57
+ it 'should beautify' do
58
+ @metas.keys.each do |k|
59
+ @f.up(@rbs[k]).should == @metas[k]
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ filter_dir = File.dirname(__FILE__) + '/../../lib/filter/'
4
+ Dir.open(filter_dir).each do |fn|
5
+ next unless fn =~ /[.]rb$/
6
+ require fn
7
+ end
8
+
9
+ include Filter
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/filter_spec_helper'
2
+
3
+ module Lazibi
4
+ module Spec
5
+ describe 'OptionalDoFilter' do
6
+ before(:all) do
7
+ @f = OptionalDo.new
8
+ @beautify = Beautify.new
9
+ @optional_end = OptionalEnd.new
10
+
11
+ # load fixtures
12
+ @rbs = {}
13
+ @metas = {}
14
+
15
+
16
+ rb_dir = FIXTURE_DIR + '/optional_do/rbs'
17
+ Dir.open(rb_dir).each do |fn|
18
+ next unless fn =~ /[.]txt$/
19
+ @rbs[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(rb_dir + "/#{fn}")
20
+ end
21
+
22
+ meta_dir = FIXTURE_DIR + '/optional_do/metas'
23
+ Dir.open(meta_dir).each do |fn|
24
+ next unless fn =~ /[.]txt$/
25
+ @metas[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(meta_dir + "/#{fn}")
26
+ end
27
+ end
28
+
29
+ it 'should remove do test drive' do
30
+ @f.up('it do').should == 'it'
31
+ @f.down("it\n abc").should == "it do\n abc"
32
+ end
33
+
34
+
35
+ it 'should integrate with beautify and optional_end' do
36
+ list = [:classical, :lambda, :brackets_block, :describe, :do_block, :square_brackets]
37
+ list.each do |name|
38
+ assert_integrate name
39
+ end
40
+ end
41
+
42
+ def assert_integrate(name, debug = false)
43
+ code = @rbs[name]
44
+ code = @beautify.up(code)
45
+ code = @optional_end.up(code)
46
+ code = @f.up(code)
47
+ code.should == @metas[name]
48
+
49
+ code = @metas[name]
50
+ code = @f.down(code)
51
+ code = @optional_end.down(code)
52
+ code.should == @rbs[name]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/filter_spec_helper'
2
+
3
+ module Lazibi
4
+ module Spec
5
+ describe 'OptionalEndFilter' do
6
+ before(:all) do
7
+ @f = OptionalEnd.new
8
+
9
+ # load fixtures
10
+ @rbs = {}
11
+ @metas = {}
12
+
13
+
14
+ rb_dir = FIXTURE_DIR + '/real'
15
+ Dir.open(rb_dir).each do |fn|
16
+ next unless fn =~ /[.]txt$/
17
+ @rbs[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(rb_dir + "/#{fn}")
18
+ end
19
+
20
+ meta_dir = FIXTURE_DIR + '/meta'
21
+ Dir.open(meta_dir).each do |fn|
22
+ next unless fn =~ /[.]txt$/
23
+ @metas[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(meta_dir + "/#{fn}")
24
+ end
25
+ end
26
+
27
+ it "should find end" do
28
+ assert_find :basic_class, 0, 0
29
+ assert_find :class_with_def, 0, 1
30
+ assert_find :class_with_def, 0, 1
31
+ assert_find :class_with_def, 2, 0, 1..-1
32
+ assert_find :two_methods, 0, 3
33
+ assert_find :two_methods, 2, 0, 1..-1
34
+ assert_find :partial_method, 2, 0
35
+ assert_find :middle, 0, 1
36
+ assert_find :multi_blocks, 0, 7
37
+ end
38
+
39
+ it "should preserve" do
40
+ @metas.keys.reject{|k| ['partial_method', 'inline_end', 'optional_do',
41
+ 'eval_code', 'here_doc', 'single_method', 'comment_after_end'].include? k.to_s }.each do |k|
42
+ assert_preserve k
43
+ end
44
+ end
45
+
46
+
47
+ it "should convert to rb" do
48
+ assert_to_rb :partial_method
49
+ assert_to_rb :eval_code
50
+ assert_to_rb :comment_after_end, :comment_after_end_expected
51
+ end
52
+
53
+ it "should convert to meta" do
54
+ assert_to_meta :inline_end
55
+ assert_to_meta :comment_after_end
56
+ end
57
+
58
+
59
+ def assert_find( name, indent, end_i, range = nil )
60
+ unless range
61
+ @f.find_end(@metas[name].split("\n"), indent).should == end_i
62
+ else
63
+ @f.find_end(@metas[name].split("\n")[range], indent).should == end_i
64
+ end
65
+ end
66
+
67
+
68
+ def assert_to_rb( name, name_2 = nil )
69
+ name_2 = name unless name_2
70
+ @f.down( @metas[name]).should == @rbs[name_2]
71
+ end
72
+
73
+ def assert_to_meta( name, name_2 = nil )
74
+ name_2 = name unless name_2
75
+ @f.up( @rbs[name]).should == @metas[name_2]
76
+ end
77
+
78
+ def assert_preserve( name )
79
+ assert_to_rb(name)
80
+ assert_to_meta(name)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/filter_spec_helper'
2
+
3
+ module Lazibi
4
+ module Spec
5
+ describe 'SyntaxGuardFilter' do
6
+ before(:all) do
7
+ @f = SyntaxGuard.new
8
+
9
+ # load fixtures
10
+ @p_rbs = {}
11
+ @p_metas = {}
12
+
13
+
14
+ expected_dir = FIXTURE_DIR + '/real'
15
+ Dir.open(expected_dir).each do |fn|
16
+ next unless fn =~ /[.]txt$/
17
+ @p_rbs[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(expected_dir + "/#{fn}")
18
+ end
19
+
20
+ clean_dir = FIXTURE_DIR + '/clean'
21
+ Dir.open(clean_dir).each do |fn|
22
+ next unless fn =~ /[.]txt$/
23
+ @p_metas[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(clean_dir + "/#{fn}")
24
+ end
25
+ end
26
+
27
+ it 'should skip' do
28
+ bad_examples = %w( eval_code here_doc single_method general_eval javascript strange_syntax_1 )
29
+ bad_examples.each do |example|
30
+ @f.up(@p_rbs[example.to_sym]).should be_false
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ it "should read several example names from file if --example is given an existing file name" do
2
+ options = parse(["--example", File.dirname(__FILE__) + '/examples.txt'])
3
+ options.examples.should eql([
4
+ "Sir, if you were my husband, I would poison your drink.",
5
+ "Madam, if you were my wife, I would drink it."])
6
+ end
@@ -1,6 +1,6 @@
1
1
  it "should read several example names from file if --example is given an existing file name" do
2
2
  options = parse(["--example", File.dirname(__FILE__) + '/examples.txt'])
3
3
  options.examples.should eql([
4
- "Sir, if you were my husband, I would poison your drink.",
4
+ "Sir, if you were my husband, I would poison your drink.",
5
5
  "Madam, if you were my wife, I would drink it."])
6
6
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  it "should read several example names from file if --example is given an existing file name"
2
2
  options = parse(["--example", File.dirname(__FILE__) + '/examples.txt'])
3
3
  options.examples.should eql([
4
- "Sir, if you were my husband, I would poison your drink.",
5
- "Madam, if you were my wife, I would drink it."])
4
+ "Sir, if you were my husband, I would poison your drink.",
5
+ "Madam, if you were my wife, I would drink it."])