pivotal-erector 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/README.txt +5 -5
  2. data/VERSION.yml +2 -2
  3. data/bin/{erect → erector} +0 -0
  4. data/lib/erector/erect.rb +1 -1
  5. data/lib/erector/erected.rb +1 -1
  6. data/lib/erector/rails/extensions/action_controller.rb +25 -7
  7. data/lib/erector/rails/extensions/{widget.rb → rails_widget/helpers.rb} +2 -9
  8. data/lib/erector/rails/extensions/{widget/2.2.0/widget.rb → rails_widget.rb} +4 -2
  9. data/lib/erector/rails/rails_version.rb +6 -0
  10. data/lib/erector/rails/template_handlers/action_view_template_handler.rb +43 -11
  11. data/lib/erector/rails.rb +2 -1
  12. data/lib/erector/version.rb +1 -1
  13. data/lib/erector/widget.rb +213 -73
  14. data/lib/erector/widgets/table.rb +3 -3
  15. data/spec/erector/indentation_spec.rb +39 -24
  16. data/spec/erector/widget_spec.rb +197 -64
  17. data/spec/erector/widgets/table_spec.rb +3 -3
  18. data/spec/spec.opts +1 -0
  19. data/spec/spec_helper.rb +1 -4
  20. data/spec/spec_suite.rb +6 -12
  21. metadata +18 -30
  22. data/lib/erector/rails/extensions/action_controller/1.2.5/action_controller.rb +0 -17
  23. data/lib/erector/rails/extensions/action_controller/2.2.0/action_controller.rb +0 -26
  24. data/lib/erector/rails/extensions/widget/1.2.5/widget.rb +0 -18
  25. data/lib/erector/rails/supported_rails_versions.rb +0 -14
  26. data/lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb +0 -32
  27. data/lib/erector/rails/template_handlers/2.0.0/action_view_template_handler.rb +0 -36
  28. data/lib/erector/rails/template_handlers/2.1.0/action_view_template_handler.rb +0 -31
  29. data/lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb +0 -46
  30. data/spec/erect/erect_spec.rb +0 -145
  31. data/spec/erect/erected_spec.rb +0 -80
  32. data/spec/erect/rhtml_parser_spec.rb +0 -318
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal-erector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee
@@ -12,8 +12,8 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-04-05 00:00:00 -07:00
16
- default_executable: erect
15
+ date: 2009-05-06 00:00:00 -07:00
16
+ default_executable: erector
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: treetop
@@ -26,9 +26,9 @@ dependencies:
26
26
  version: 1.2.3
27
27
  version:
28
28
  description: Html Builder library.
29
- email: erector-devel@rubyforge.org
29
+ email: erector@googlegroups.com
30
30
  executables:
31
- - erect
31
+ - erector
32
32
  extensions: []
33
33
 
34
34
  extra_rdoc_files:
@@ -36,7 +36,7 @@ extra_rdoc_files:
36
36
  files:
37
37
  - README.txt
38
38
  - VERSION.yml
39
- - bin/erect
39
+ - bin/erector
40
40
  - lib/erector.rb
41
41
  - lib/erector/erect.rb
42
42
  - lib/erector/erected.rb
@@ -44,17 +44,10 @@ files:
44
44
  - lib/erector/indenting.rb
45
45
  - lib/erector/rails.rb
46
46
  - lib/erector/rails/extensions/action_controller.rb
47
- - lib/erector/rails/extensions/action_controller/1.2.5/action_controller.rb
48
- - lib/erector/rails/extensions/action_controller/2.2.0/action_controller.rb
49
47
  - lib/erector/rails/extensions/action_view.rb
50
- - lib/erector/rails/extensions/widget.rb
51
- - lib/erector/rails/extensions/widget/1.2.5/widget.rb
52
- - lib/erector/rails/extensions/widget/2.2.0/widget.rb
53
- - lib/erector/rails/supported_rails_versions.rb
54
- - lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb
55
- - lib/erector/rails/template_handlers/2.0.0/action_view_template_handler.rb
56
- - lib/erector/rails/template_handlers/2.1.0/action_view_template_handler.rb
57
- - lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb
48
+ - lib/erector/rails/extensions/rails_widget.rb
49
+ - lib/erector/rails/extensions/rails_widget/helpers.rb
50
+ - lib/erector/rails/rails_version.rb
58
51
  - lib/erector/rails/template_handlers/action_view_template_handler.rb
59
52
  - lib/erector/raw_string.rb
60
53
  - lib/erector/rhtml.treetop
@@ -65,17 +58,15 @@ files:
65
58
  - lib/erector/widgets.rb
66
59
  - lib/erector/widgets/table.rb
67
60
  - spec/core_spec_suite.rb
68
- - spec/erect/erect_spec.rb
69
- - spec/erect/erected_spec.rb
70
- - spec/erect/rhtml_parser_spec.rb
71
61
  - spec/erector/indentation_spec.rb
72
62
  - spec/erector/unicode_builder_spec.rb
73
63
  - spec/erector/widget_spec.rb
74
64
  - spec/erector/widgets/table_spec.rb
75
65
  - spec/rails_spec_suite.rb
66
+ - spec/spec.opts
76
67
  - spec/spec_helper.rb
77
68
  - spec/spec_suite.rb
78
- has_rdoc: true
69
+ has_rdoc: false
79
70
  homepage: http://erector.rubyforge.org/
80
71
  post_install_message:
81
72
  rdoc_options:
@@ -99,20 +90,17 @@ requirements: []
99
90
  rubyforge_project:
100
91
  rubygems_version: 1.2.0
101
92
  signing_key:
102
- specification_version: 2
93
+ specification_version: 3
103
94
  summary: Html Builder library.
104
95
  test_files:
96
+ - spec/core_spec_suite.rb
105
97
  - spec/erector
106
- - spec/erector/widgets
107
- - spec/erector/widgets/table_spec.rb
98
+ - spec/erector/indentation_spec.rb
108
99
  - spec/erector/unicode_builder_spec.rb
109
100
  - spec/erector/widget_spec.rb
110
- - spec/erector/indentation_spec.rb
101
+ - spec/erector/widgets
102
+ - spec/erector/widgets/table_spec.rb
111
103
  - spec/rails_spec_suite.rb
112
- - spec/spec_suite.rb
113
- - spec/core_spec_suite.rb
104
+ - spec/spec.opts
114
105
  - spec/spec_helper.rb
115
- - spec/erect
116
- - spec/erect/erected_spec.rb
117
- - spec/erect/erect_spec.rb
118
- - spec/erect/rhtml_parser_spec.rb
106
+ - spec/spec_suite.rb
@@ -1,17 +0,0 @@
1
- ActionController::Base.class_eval do
2
- def render_widget(widget_class, assigns=@assigns)
3
- @__widget_class = widget_class
4
- @__widget_assigns = assigns
5
- add_variables_to_assigns
6
- render :inline => "<% @__widget_class.new(self, @__widget_assigns, _erbout).render %>"
7
- end
8
-
9
- def render_with_erector_widget(*options, &block)
10
- if options.first.is_a?(Hash) && widget = options.first.delete(:widget)
11
- render_widget widget, @assigns, &block
12
- else
13
- render_without_erector_widget *options, &block
14
- end
15
- end
16
- alias_method_chain :render, :erector_widget
17
- end
@@ -1,26 +0,0 @@
1
- ActionController::Base.class_eval do
2
- def render_widget(widget_class, assigns=nil)
3
- @__widget_class = widget_class
4
- if assigns
5
- @__widget_assigns = assigns
6
- else
7
- @__widget_assigns = {}
8
- variables = instance_variable_names
9
- variables -= protected_instance_variables
10
- variables.each do |name|
11
- @__widget_assigns[name.sub('@', "")] = instance_variable_get(name)
12
- end
13
- end
14
- response.template.send(:_evaluate_assigns_and_ivars)
15
- render :inline => "<% @__widget_class.new(self, @__widget_assigns, output_buffer).render %>"
16
- end
17
-
18
- def render_with_erector_widget(*options, &block)
19
- if options.first.is_a?(Hash) && widget = options.first.delete(:widget)
20
- render_widget widget, @assigns, &block
21
- else
22
- render_without_erector_widget *options, &block
23
- end
24
- end
25
- alias_method_chain :render, :erector_widget
26
- end
@@ -1,18 +0,0 @@
1
- module Erector
2
- Widget.class_eval do
3
- attr_reader :_erbout
4
-
5
- after_initialize do
6
- @_erbout = output
7
- end
8
-
9
- def define_javascript_functions(*args)
10
- begin
11
- text raw(helpers.define_javascript_functions(*args))
12
- rescue => e
13
- puts e.backtrace.join("\n\t")
14
- raise e
15
- end
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- module Erector
2
- module Rails
3
- SUPPORTED_RAILS_VERSIONS = {
4
- # "1.2.5" => {'version' => '1.2.5', 'git_tag' => 'v1.2.5'},
5
- "1.99.0" => {'version' => '1.99.0', 'git_tag' => 'v2.0.0_RC1'},
6
- "2.0.2" => {'version' => '2.0.2', 'git_tag' => 'v2.0.2'},
7
- "2.1.0" => {'version' => '2.1.0', 'git_tag' => 'v2.1.0'},
8
- "2.2.0" => {'version' => '2.2.0', 'git_tag' => 'v2.2.0'},
9
- "2.2.2" => {'version' => '2.2.2', 'git_tag' => 'v2.2.2'},
10
- "2.3.2" => {'version' => '2.3.2', 'git_tag' => 'v2.3.2'},
11
- # "edge" => {'version' => 'edge', 'git_tag' => 'master'}, #TODO: Readd edge support
12
- }
13
- end
14
- end
@@ -1,32 +0,0 @@
1
- module ActionView #:nodoc:
2
- module TemplateHandlers #:nodoc:
3
- class Erector
4
- def self.line_offset
5
- 2
6
- end
7
-
8
- attr_reader :view
9
- def initialize(view)
10
- @view = view
11
- end
12
-
13
- def compilable?
14
- true
15
- end
16
-
17
- ActionView::Base.register_template_handler :rb, ActionView::TemplateHandlers::Erector
18
-
19
- def render(template, local_assigns)
20
- relative_path_parts = view.first_render.split('/')
21
- require_dependency view.template_file_path
22
-
23
- dot_rb = /\.rb$/
24
- widget_class = relative_path_parts.inject(Views) do |mod, node|
25
- mod.const_get(node.gsub(dot_rb, '').gsub(".html", "").camelize)
26
- end
27
- render_method = view.is_partial_template? ? 'render_partial' : 'render'
28
- widget_class.new(view, view.assigns).to_s(render_method)
29
- end
30
- end
31
- end
32
- end
@@ -1,36 +0,0 @@
1
- module ActionView #:nodoc:
2
- module TemplateHandlers #:nodoc:
3
- class Erector < TemplateHandler
4
- def self.line_offset
5
- 2
6
- end
7
-
8
- attr_reader :view
9
- def initialize(view)
10
- @view = view
11
- end
12
-
13
- def compilable?
14
- true
15
- end
16
- undef :compile
17
-
18
- ActionView::Base.register_template_handler :rb, ActionView::TemplateHandlers::Erector
19
-
20
- def render(template, local_assigns)
21
- relative_path_parts = view.first_render.split('/')
22
- file_name = relative_path_parts.last
23
- require_dependency(view.template_file_path)
24
-
25
- dot_rb = /\.rb$/
26
- widget_class = relative_path_parts.inject(Views) do |mod, node|
27
- mod.const_get(node.gsub(dot_rb, '').gsub(".html", "").camelize)
28
- end
29
- render_method = view.is_partial_template? ? 'render_partial' : 'render'
30
- widget = widget_class.new(view, view.assigns)
31
- widget.to_s(render_method)
32
- end
33
- end
34
- end
35
- end
36
-
@@ -1,31 +0,0 @@
1
- module ActionView #:nodoc:
2
- module TemplateHandlers #:nodoc:
3
- class Erector < TemplateHandler
4
- include Compilable
5
- def self.line_offset
6
- 2
7
- end
8
-
9
- ActionView::Template.instance_eval do
10
- register_template_handler :rb, ActionView::TemplateHandlers::Erector
11
- end
12
-
13
- def compile(template)
14
- relative_path_parts = template.path.split('/')
15
-
16
- is_partial = relative_path_parts.last =~ /^_/
17
- require_dependency File.expand_path(template.filename)
18
-
19
- widget_class_parts = relative_path_parts.inject(['Views']) do |class_parts, node|
20
- class_parts << node.gsub(/^_/, "").gsub(/(\.html)?\.rb$/, '').camelize
21
- class_parts
22
- end
23
- widget_class_name = widget_class_parts.join("::")
24
- render_method = is_partial ? 'render_partial' : 'render'
25
-
26
- erb_template = "<% #{widget_class_name}.new(self, controller.assigns, _erbout).#{render_method} %>"
27
- ::ERB.new(erb_template, nil, ActionView::Base.erb_trim_mode).src
28
- end
29
- end
30
- end
31
- end
@@ -1,46 +0,0 @@
1
- module ActionView #:nodoc:
2
- module TemplateHandlers #:nodoc:
3
- class Erector < TemplateHandler
4
- include Compilable
5
- def self.line_offset
6
- 2
7
- end
8
-
9
- ActionView::Template.instance_eval do
10
- register_template_handler :rb, ActionView::TemplateHandlers::Erector
11
- end
12
-
13
- def compile(template)
14
- relative_path_parts = template.path.split('/')
15
-
16
- is_partial = relative_path_parts.last =~ /^_/
17
- require_dependency File.expand_path(template.filename)
18
-
19
- widget_class_parts = relative_path_parts.inject(['Views']) do |class_parts, node|
20
- class_parts << node.gsub(/^_/, "").gsub(/(\.html)?\.rb$/, '').camelize
21
- class_parts
22
- end
23
- widget_class_name = widget_class_parts.join("::")
24
- render_method = is_partial ? 'render_partial' : 'render'
25
-
26
- erb_template = <<-ERB
27
- <%
28
- assigns = instance_variables.inject({}) do |hash, name|
29
- hash[name.sub('@', "")] = instance_variable_get(name)
30
- hash
31
- end
32
-
33
- widget = #{widget_class_name}.new(self, assigns, output_buffer)
34
- widget.#{render_method}
35
- %>
36
- ERB
37
- ::ERB.new(
38
- erb_template,
39
- nil,
40
- ::ActionView::TemplateHandlers::ERB.erb_trim_mode,
41
- "@output_buffer"
42
- ).src
43
- end
44
- end
45
- end
46
- end
@@ -1,145 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
-
3
- module Erector
4
- describe Erect do
5
- it "parses an empty command line" do
6
- erect = Erect.new([])
7
- erect.files.should == []
8
- end
9
-
10
- it "parses a command line with one filename on it" do
11
- erect = Erect.new(["foo.html"])
12
- erect.files.should == ["foo.html"]
13
- end
14
-
15
- it "parses a command line with several filenames on it" do
16
- erect = Erect.new(["foo.html", "bar/baz.html"])
17
- erect.files.should == ["foo.html", "bar/baz.html"]
18
- end
19
-
20
- it "is verbose by default, but quiet when told" do
21
- Erect.new([]).verbose.should be_true
22
- Erect.new(["-q"]).verbose.should be_false
23
- end
24
-
25
- it "parses a command line with several filenames and an option on it" do
26
- erect = Erect.new(["-q", "foo.html", "bar/baz.html"])
27
- erect.files.should == ["foo.html", "bar/baz.html"]
28
- end
29
-
30
- def capture
31
- output = StringIO.new
32
- $stdout = output
33
- yield
34
- output.string
35
- ensure
36
- $stdout = STDOUT
37
- end
38
-
39
- it "exits immediately from help" do
40
- output = capture do
41
- lambda {
42
- erect = Erect.new(["-h"])
43
- }.should raise_error(SystemExit)
44
- end
45
- output.should =~ /^Usage/
46
- end
47
-
48
- it "exits immediately from --version" do
49
- output = capture do
50
- lambda {
51
- erect = Erect.new(["--version"])
52
- }.should raise_error(SystemExit)
53
- end
54
- output.should == Erector::VERSION + "\n"
55
- end
56
-
57
- it "changes to html output" do
58
- erect = Erect.new(["--to-html"])
59
- erect.mode.should == :to_html
60
- end
61
-
62
- end
63
-
64
- describe "Erect functionally" do
65
-
66
- attr_reader :dir, :fred_html, :wilma_rhtml, :barney_html_erb, :fred_rb
67
-
68
- def create(file, body="hi")
69
- File.open(file, "w") do |f|
70
- f.puts(body)
71
- end
72
- end
73
-
74
- before :all do
75
- @dir = Dir.tmpdir + "/#{Time.now.to_i}" + "/explode"
76
- @fred_html = "#{dir}/fred.html"
77
- @wilma_rhtml = "#{dir}/wilma.rhtml"
78
- @barney_html_erb = "#{dir}/barney.html.erb"
79
- @fred_rb = "#{dir}/fred.rb"
80
-
81
- FileUtils.mkdir_p(dir)
82
- create(fred_html)
83
- create(wilma_rhtml)
84
- create(barney_html_erb)
85
- create(fred_rb, "class Fred < Erector::Widget\ndef render\ndiv 'dino'\nend\nend")
86
- end
87
-
88
- it "explodes dirs into .html etc. files when in to-rb mode" do
89
- erect = Erect.new(["--to-erector", dir])
90
- erect.files.sort.should == [barney_html_erb, fred_html, wilma_rhtml]
91
- end
92
-
93
- it "explodes dirs into .rb files when in to-html mode" do
94
- erect = Erect.new(["--to-html", dir])
95
- erect.files.should == [fred_rb]
96
- end
97
-
98
- it "outputs .rb files in the same directory as the input .html files" do
99
- erect = Erect.new(["--to-erector", "-q", fred_html])
100
- erect.run
101
- File.exist?(fred_rb).should be_true
102
- File.read(fred_rb).should include("text 'hi'")
103
- end
104
-
105
- it "outputs .html files in the same directory as the input .rb files" do
106
- betty_rb = "#{dir}/betty.rb"
107
- betty_html = "#{dir}/betty.html"
108
- create(betty_rb, "class Betty < Erector::Widget\ndef render\ndiv 'bam bam'\nend\nend")
109
-
110
- erect = Erect.new(["--to-html", "-q", betty_rb])
111
- erect.run
112
- File.exist?(betty_html).should be_true
113
- File.read(betty_html).should == "<div>bam bam</div>\n"
114
- end
115
-
116
- it "outputs .html files in the given directory" do
117
- create(fred_rb, "class Fred < Erector::Widget\ndef render\ndiv 'dino'\nend\nend")
118
-
119
-
120
- out_dir = "#{dir}/out"
121
- out_file = "#{out_dir}/fred.html"
122
- Erect.new([]).output_dir.should be_nil
123
- erect = Erect.new(["--to-html", "-o", "#{out_dir}", "-q", fred_rb])
124
- erect.output_dir.should == out_dir
125
- erect.run
126
- File.exist?(out_file).should be_true
127
- File.read(out_file).should == "<div>dino</div>\n"
128
- end
129
-
130
- it "supports the --add-to-svn option"
131
- it "supports the --delete-original option"
132
-
133
- it "skips rendering classes that aren't widgets" do
134
- mr_slate_rb = "#{dir}/mr_slate.rb"
135
- mr_slate_html = "#{dir}/mr_slate.html"
136
- create(mr_slate_rb, "class MrSlate\nend")
137
- erect = Erect.new(["-q", "--to-html", mr_slate_rb])
138
- erect.run
139
- File.exist?(mr_slate_html).should be_false
140
- end
141
-
142
- it "properly indents lines beginning with for, unless, etc."
143
- it "escapes single quotes inside text strings"
144
- end
145
- end
@@ -1,80 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
-
3
- module Erector
4
- describe Erected do
5
-
6
- it "picks the right file name" do
7
- Erected.new("foo.html.erb").filename.should == "foo.rb"
8
- Erected.new("foo.html").filename.should == "foo.rb"
9
- Erected.new("foo.bar.html").filename.should == "foo.rb"
10
- Erected.new("foo_bar.html.erb").filename.should == "foo_bar.rb"
11
- Erected.new("stuff/foo_bar.html.erb").filename.should == "stuff/foo_bar.rb"
12
- end
13
-
14
- it "picks a nice class name" do
15
- Erected.new("foo.html.erb").classname.should == "Foo"
16
- Erected.new("foo.html").classname.should == "Foo"
17
- Erected.new("foo.bar.html").classname.should == "Foo"
18
- Erected.new("foo_bar.html.erb").classname.should == "FooBar"
19
- Erected.new("stuff/foo_bar.html.erb").classname.should == "FooBar"
20
- end
21
-
22
- it "picks an even nicer class name if it's in a views dir" do
23
- Erected.new("app/views/stuff/foo_bar.html.erb").classname.should == "Views::Stuff::FooBar"
24
- Erected.new("views/stuff/foo_bar.html.erb").classname.should == "Views::Stuff::FooBar"
25
- end
26
-
27
- def convert(dir, input, output)
28
- dir = Dir.tmpdir + "/#{Time.now.to_i}" + "/#{dir}"
29
-
30
- FileUtils.mkdir_p(dir)
31
- html = "#{dir}/dummy.html"
32
- rb = "#{dir}/dummy.rb"
33
-
34
- File.open(html, "w") do |f|
35
- f.puts(input)
36
- end
37
-
38
- @e = Erected.new(html)
39
- @e.convert
40
-
41
- File.read(rb).should == output
42
- end
43
-
44
- it "converts a normal file" do
45
- convert(".",
46
- "<div>hello</div>",
47
- "class Dummy < Erector::Widget\n" +
48
- " def render\n" +
49
- " div do\n" +
50
- " text 'hello'\n" +
51
- " end\n" +
52
- " end\n" +
53
- "end\n"
54
- )
55
- end
56
-
57
- it "converts a views file" do
58
- convert("app/views/foos",
59
- "<div>hello</div>",
60
- "class Views::Foos::Dummy < Erector::Widget\n" +
61
- " def render\n" +
62
- " div do\n" +
63
- " text 'hello'\n" +
64
- " end\n" +
65
- " end\n" +
66
- "end\n"
67
- )
68
- end
69
-
70
- # todo: figure out if there is any such thing as unparsable HTML anymore
71
- # it "raises an exception if given unparsable HTML" do
72
- # begin
73
- # convert(".", "<", "")
74
- # rescue => e
75
- # e.to_s.should include("Could not parse")
76
- # end
77
- # end
78
-
79
- end
80
- end