erector 0.7.2 → 0.8.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.
Files changed (67) hide show
  1. data/README.txt +17 -3
  2. data/VERSION.yml +2 -2
  3. data/bin/erector +1 -1
  4. data/lib/erector.rb +22 -2
  5. data/lib/erector/after_initialize.rb +34 -0
  6. data/lib/erector/caching.rb +93 -0
  7. data/lib/erector/convenience.rb +58 -0
  8. data/lib/erector/dependencies.rb +24 -0
  9. data/lib/erector/dependency.rb +21 -0
  10. data/lib/erector/{erect.rb → erect/erect.rb} +14 -4
  11. data/lib/erector/{erected.rb → erect/erected.rb} +6 -4
  12. data/lib/erector/{indenting.rb → erect/indenting.rb} +0 -0
  13. data/lib/erector/{rhtml.treetop → erect/rhtml.treetop} +51 -11
  14. data/lib/erector/errors.rb +12 -0
  15. data/lib/erector/extensions/hash.rb +21 -0
  16. data/lib/erector/externals.rb +88 -24
  17. data/lib/erector/html.rb +352 -0
  18. data/lib/erector/inline.rb +5 -5
  19. data/lib/erector/jquery.rb +36 -0
  20. data/lib/erector/mixin.rb +3 -5
  21. data/lib/erector/needs.rb +94 -0
  22. data/lib/erector/output.rb +117 -0
  23. data/lib/erector/rails.rb +2 -2
  24. data/lib/erector/rails/extensions/action_controller.rb +5 -3
  25. data/lib/erector/rails/extensions/rails_helpers.rb +159 -0
  26. data/lib/erector/rails/extensions/rails_widget.rb +98 -56
  27. data/lib/erector/rails/rails_form_builder.rb +8 -4
  28. data/lib/erector/rails/rails_version.rb +2 -2
  29. data/lib/erector/rails/template_handlers/ert_handler.rb +1 -1
  30. data/lib/erector/rails/template_handlers/rb_handler.rb +42 -1
  31. data/lib/erector/raw_string.rb +2 -2
  32. data/lib/erector/sass.rb +22 -0
  33. data/lib/erector/widget.rb +100 -653
  34. data/lib/erector/widgets.rb +1 -0
  35. data/lib/erector/widgets/external_renderer.rb +51 -0
  36. data/lib/erector/widgets/page.rb +45 -63
  37. data/lib/erector/widgets/table.rb +9 -1
  38. data/spec/erect/erect_rails_spec.rb +19 -17
  39. data/spec/erect/erect_spec.rb +11 -1
  40. data/spec/erect/erected_spec.rb +76 -5
  41. data/spec/erect/rhtml_parser_spec.rb +11 -1
  42. data/spec/erector/caching_spec.rb +267 -0
  43. data/spec/erector/convenience_spec.rb +258 -0
  44. data/spec/erector/dependency_spec.rb +46 -0
  45. data/spec/erector/externals_spec.rb +233 -0
  46. data/spec/erector/html_spec.rb +508 -0
  47. data/spec/erector/indentation_spec.rb +84 -24
  48. data/spec/erector/inline_spec.rb +19 -8
  49. data/spec/erector/jquery_spec.rb +35 -0
  50. data/spec/erector/mixin_spec.rb +1 -1
  51. data/spec/erector/needs_spec.rb +120 -0
  52. data/spec/erector/output_spec.rb +199 -0
  53. data/spec/erector/sample-file.txt +1 -0
  54. data/spec/erector/sass_spec.rb +33 -0
  55. data/spec/erector/widget_spec.rb +113 -932
  56. data/spec/erector/widgets/field_table_spec.rb +6 -6
  57. data/spec/erector/widgets/form_spec.rb +3 -3
  58. data/spec/erector/widgets/page_spec.rb +52 -6
  59. data/spec/erector/widgets/table_spec.rb +4 -4
  60. data/spec/spec_helper.rb +70 -29
  61. metadata +56 -19
  62. data/lib/erector/rails/extensions/rails_widget/rails_helpers.rb +0 -137
  63. data/spec/core_spec_suite.rb +0 -3
  64. data/spec/erector/external_spec.rb +0 -110
  65. data/spec/rails_spec_suite.rb +0 -3
  66. data/spec/spec.opts +0 -1
  67. data/spec/spec_suite.rb +0 -40
@@ -1,137 +0,0 @@
1
- module Erector
2
- module Rails
3
- module Helpers
4
- include ActionController::UrlWriter
5
-
6
- # parent returning raw text whose first parameter is HTML escaped
7
- ESCAPED_HELPERS = [
8
- :link_to,
9
- :link_to_remote,
10
- :mail_to,
11
- :button_to,
12
- :submit_tag,
13
- ]
14
- ESCAPED_HELPERS.each do |method_name|
15
- start_line = __LINE__ + 2
16
- method_def =<<-METHOD_DEF
17
- def #{method_name}(link_text, *args, &block)
18
- rawtext(parent.#{method_name}(h(link_text), *args, &block))
19
- end
20
- METHOD_DEF
21
- eval(method_def, binding, __FILE__, start_line)
22
- end
23
-
24
- # return text, take block
25
- RAW_HELPERS = [
26
- :link_to_function,
27
- :text_field_tag,
28
- :password_field_tag,
29
- :check_box_tag,
30
- :error_messages_for,
31
- :submit_tag,
32
- :file_field,
33
- :image_tag,
34
- :javascript_include_tag,
35
- :stylesheet_link_tag,
36
- :sortable_element,
37
- :sortable_element_js,
38
- :text_field_with_auto_complete
39
- ]
40
- RAW_HELPERS.each do |method_name|
41
- start_line = __LINE__ + 2
42
- method_def =<<-METHOD_DEF
43
- def #{method_name}(*args, &block)
44
- rawtext parent.#{method_name}(*args, &block)
45
- end
46
- METHOD_DEF
47
- eval(method_def, binding, __FILE__, start_line)
48
- end
49
-
50
- CAPTURED_HELPERS_WITHOUT_CONCAT = [
51
- :render
52
- ]
53
- CAPTURED_HELPERS_WITHOUT_CONCAT.each do |method_name|
54
- start_line = __LINE__ + 2
55
- method_def =<<-METHOD_DEF
56
- def #{method_name}(*args, &block)
57
- captured = parent.capture do
58
- parent.concat(parent.#{method_name}(*args, &block))
59
- parent.output_buffer.to_s
60
- end
61
- rawtext(captured)
62
- end
63
- METHOD_DEF
64
- eval(method_def, binding, __FILE__, start_line)
65
- end
66
-
67
- CAPTURED_HELPERS_WITH_CONCAT = [
68
- :form_tag
69
- ]
70
- CAPTURED_HELPERS_WITH_CONCAT.each do |method_name|
71
- start_line = __LINE__ + 2
72
- method_def =<<-METHOD_DEF
73
- def #{method_name}(*args, &block)
74
- captured = parent.capture do
75
- parent.#{method_name}(*args, &block)
76
- parent.output_buffer.to_s
77
- end
78
- rawtext(captured)
79
- end
80
- METHOD_DEF
81
- eval(method_def, binding, __FILE__, start_line)
82
- end
83
-
84
- def form_for(record_or_name_or_array, *args, &proc)
85
- options = args.extract_options!
86
- options[:builder] ||= ::Erector::RailsFormBuilder
87
- args.push(options)
88
- parent.form_for(record_or_name_or_array, *args, &proc)
89
- end
90
-
91
- def fields_for(record_or_name_or_array, *args, &proc)
92
- options = args.extract_options!
93
- options[:builder] ||= ::Erector::RailsFormBuilder
94
- args.push(options)
95
- parent.fields_for(record_or_name_or_array, *args, &proc)
96
- end
97
-
98
- def javascript_include_merged(key)
99
- parent.javascript_include_merged(key)
100
- end
101
-
102
- def stylesheet_link_merged(key)
103
- parent.stylesheet_link_merged(key)
104
- end
105
-
106
- def flash
107
- parent.controller.send(:flash)
108
- end
109
-
110
- def session
111
- parent.controller.session
112
- end
113
-
114
- def controller
115
- parent.controller
116
- end
117
-
118
- def cycle(*args)
119
- parent.cycle(*args)
120
- end
121
-
122
- def simple_format(string)
123
- p raw(string.to_s.html_escape.gsub(/\r\n?/, "\n").gsub(/\n/, "<br/>\n"))
124
- end
125
-
126
- def time_ago_in_words(*args)
127
- parent.time_ago_in_words(*args)
128
- end
129
-
130
- def pluralize(*args)
131
- parent.pluralize(*args)
132
- end
133
- end
134
-
135
- Erector::Widget.send :include, Helpers
136
- end
137
- end
@@ -1,3 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/spec_suite"
3
- SpecSuite.core
@@ -1,110 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
- require 'benchmark'
3
- require 'active_support' # for Symbol#to_proc
4
-
5
- describe Erector::External do
6
- it "can be constructed with type, klass, text" do
7
- x = Erector::External.new(:foo, Object, "abc")
8
- x.type.should == :foo
9
- x.klass.should == Object
10
- x.text.should == "abc"
11
- x.options.should == {}
12
- end
13
-
14
- it "can be constructed with type, klass, text, and options" do
15
- x = Erector::External.new(:foo, Object, "abc", {:bar => 7})
16
- x.options.should == {:bar => 7}
17
- end
18
-
19
- it "is equal to an identical external" do
20
- x = Erector::External.new(:foo, Object, "abc", {:bar => 7})
21
- y = Erector::External.new(:foo, Object, "abc", {:bar => 7})
22
- x.should == y
23
- [x].should include(y)
24
- end
25
-
26
- it "is equal to an identical external with a different class" do
27
- class_x = Class.new
28
- class_y = Class.new
29
- x = Erector::External.new(:foo, class_x, "abc", {:bar => 7})
30
- y = Erector::External.new(:foo, class_y, "abc", {:bar => 7})
31
- x.should == y
32
- [x].should include(y)
33
- end
34
-
35
- it "is not equal to an identical external with a different options" do
36
- class_x = Class.new
37
- x = Erector::External.new(:foo, class_x, "abc")
38
- y = Erector::External.new(:foo, class_x, "abc", {:bar => 7})
39
- x.should_not == y
40
- [x].should_not include(y)
41
- end
42
-
43
- end
44
-
45
- describe "external declarations" do
46
- class HotSauce < Erector::Widget
47
- external :css, "/css/tapatio.css", :media => "print"
48
- external :css, "/css/salsa_picante.css"
49
- external :js, "/lib/jquery.js"
50
- external :js, "/lib/picante.js"
51
- end
52
-
53
- class SourCream < Erector::Widget
54
- external :css, "/css/sourcream.css"
55
- external :js, "/lib/jquery.js"
56
- external :js, "/lib/dairy.js"
57
- end
58
-
59
- it "can be fetched via the type" do
60
- Erector::Widget.externals(:css).map(&:text).should == [
61
- "/css/tapatio.css",
62
- "/css/salsa_picante.css",
63
- "/css/sourcream.css",
64
- ]
65
- end
66
-
67
- it "can be filtered via the class" do
68
- Erector::Widget.externals(:css, HotSauce).map(&:text).should == [
69
- "/css/tapatio.css",
70
- "/css/salsa_picante.css",
71
- ]
72
- Erector::Widget.externals(:css, SourCream).map(&:text).should == [
73
- "/css/sourcream.css",
74
- ]
75
- end
76
-
77
- it "retains the options" do
78
- Erector::Widget.externals(:css, HotSauce).map(&:options).should == [
79
- {:media => "print"},
80
- {}
81
- ]
82
- end
83
-
84
- it "removes duplicates" do
85
- Erector::Widget.externals(:js).map(&:text).should == [
86
- "/lib/jquery.js",
87
- "/lib/picante.js",
88
- "/lib/dairy.js",
89
- ]
90
- end
91
-
92
-
93
- class Taco < Erector::Widget
94
- external :filling, "beef"
95
- external :filling, "beef", :media => "print"
96
- end
97
-
98
- it "considers options when removing duplicates" do
99
- Erector::Widget.externals(:filling).map(&:text).should == ["beef", "beef"]
100
- end
101
-
102
- it "works with strings or symbols" do
103
- Erector::Widget.externals("js").map(&:text).should == [
104
- "/lib/jquery.js",
105
- "/lib/picante.js",
106
- "/lib/dairy.js",
107
- ]
108
- end
109
-
110
- end
@@ -1,3 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/spec_suite"
3
- SpecSuite.rails
@@ -1 +0,0 @@
1
- --backtrace
@@ -1,40 +0,0 @@
1
- class SpecSuite
2
- class << self
3
- def all
4
- system("ruby #{dir}/core_spec_suite.rb") || raise("Core Spec Suite failed")
5
-
6
- require "#{dir}/../lib/erector/rails/rails_version"
7
-
8
- rails_version = Erector::Rails::RAILS_VERSION
9
- puts "Running rails_spec_suite for Rails version #{rails_version}"
10
-
11
- system("ruby #{dir}/rails_spec_suite.rb") || raise("Failed for version #{rails_version}")
12
- end
13
-
14
- def core
15
- run Dir["#{dir}/{erect,erector}/**/*_spec.rb"] - ["#{dir}/erect/erect_rails_spec.rb"]
16
- end
17
-
18
- def rails
19
- run ["#{dir}/erect/erect_rails_spec.rb"]
20
- Dir.chdir("#{dir}/rails_root") do
21
- run Dir["spec/**/*_spec.rb"]
22
- end
23
- end
24
-
25
- def run(files)
26
- files.each do |file|
27
- require file
28
- end
29
- end
30
-
31
- protected
32
- def dir
33
- File.dirname(__FILE__)
34
- end
35
- end
36
- end
37
-
38
- if $0 == __FILE__
39
- SpecSuite.all
40
- end