erector 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/README.txt +0 -4
  2. data/VERSION.yml +1 -1
  3. data/lib/erector.rb +2 -4
  4. data/lib/erector/abstract_widget.rb +2 -1
  5. data/lib/erector/erect/erect.rb +17 -14
  6. data/lib/erector/erect/rhtml.treetop +18 -10
  7. data/lib/erector/externals.rb +7 -1
  8. data/lib/erector/html.rb +30 -39
  9. data/lib/erector/rails.rb +6 -26
  10. data/lib/erector/rails/form_builder.rb +36 -0
  11. data/lib/erector/rails/railtie.rb +11 -0
  12. data/lib/erector/rails/template_handler.rb +16 -0
  13. data/lib/erector/rails/widget_renderer.rb +6 -0
  14. data/lib/erector/rails2.rb +27 -0
  15. data/lib/erector/{rails → rails2}/extensions/action_controller.rb +1 -1
  16. data/lib/erector/{rails → rails2}/extensions/rails_helpers.rb +17 -4
  17. data/lib/erector/{rails → rails2}/extensions/rails_widget.rb +6 -3
  18. data/lib/erector/{rails → rails2}/rails_form_builder.rb +0 -0
  19. data/lib/erector/rails2/rails_version.rb +6 -0
  20. data/lib/erector/{rails → rails2}/template_handlers/ert_handler.rb +0 -0
  21. data/lib/erector/{rails → rails2}/template_handlers/rb_handler.rb +2 -2
  22. data/lib/erector/rails3.rb +208 -0
  23. data/lib/erector/raw_string.rb +4 -0
  24. data/lib/erector/widgets/external_renderer.rb +8 -0
  25. data/spec/erect/erect_rails_spec.rb +34 -49
  26. data/spec/erect/erected_spec.rb +11 -0
  27. data/spec/rails2/erect_rails_spec.rb +114 -0
  28. data/spec/rails2/rails_app/Gemfile +12 -0
  29. data/spec/rails2/rails_app/Gemfile.lock +89 -0
  30. data/spec/rails2/rails_app/README +243 -0
  31. data/spec/rails2/rails_app/Rakefile +19 -0
  32. data/spec/rails2/rails_app/app/controllers/application_controller.rb +10 -0
  33. data/spec/rails2/rails_app/app/helpers/application_helper.rb +3 -0
  34. data/spec/rails2/rails_app/app/views/test/_erb.erb +1 -0
  35. data/spec/rails2/rails_app/app/views/test/_erector.rb +5 -0
  36. data/spec/rails2/rails_app/app/views/test/_partial_with_locals.rb +7 -0
  37. data/spec/rails2/rails_app/app/views/test/bare.rb +5 -0
  38. data/spec/rails2/rails_app/app/views/test/erb_from_erector.html.rb +5 -0
  39. data/spec/rails2/rails_app/app/views/test/erector_from_erb.html.erb +1 -0
  40. data/spec/rails2/rails_app/app/views/test/erector_with_locals_from_erb.html.erb +6 -0
  41. data/spec/rails2/rails_app/app/views/test/implicit_assigns.html.rb +5 -0
  42. data/spec/rails2/rails_app/app/views/test/needs.html.rb +7 -0
  43. data/spec/rails2/rails_app/app/views/test/needs_subclass.html.rb +5 -0
  44. data/spec/rails2/rails_app/app/views/test/protected_instance_variable.html.rb +5 -0
  45. data/spec/rails2/rails_app/app/views/test/render_default.html.rb +5 -0
  46. data/spec/rails2/rails_app/app/views/test/render_partial.html.rb +5 -0
  47. data/spec/rails2/rails_app/config/boot.rb +114 -0
  48. data/spec/rails2/rails_app/config/database.yml +16 -0
  49. data/spec/rails2/rails_app/config/environment.rb +42 -0
  50. data/spec/rails2/rails_app/config/environments/development.rb +17 -0
  51. data/spec/rails2/rails_app/config/environments/production.rb +28 -0
  52. data/spec/rails2/rails_app/config/environments/test.rb +28 -0
  53. data/spec/rails2/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/rails2/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
  55. data/spec/rails2/rails_app/config/initializers/inflections.rb +10 -0
  56. data/spec/rails2/rails_app/config/initializers/mime_types.rb +5 -0
  57. data/spec/rails2/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  58. data/spec/rails2/rails_app/config/initializers/session_store.rb +15 -0
  59. data/spec/rails2/rails_app/config/locales/en.yml +5 -0
  60. data/spec/rails2/rails_app/config/routes.rb +43 -0
  61. data/spec/rails2/rails_app/db/development.sqlite3 +0 -0
  62. data/spec/rails2/rails_app/db/schema.rb +14 -0
  63. data/spec/rails2/rails_app/db/seeds.rb +7 -0
  64. data/spec/rails2/rails_app/doc/README_FOR_APP +2 -0
  65. data/spec/rails2/rails_app/log/development.log +76 -0
  66. data/spec/rails2/rails_app/log/production.log +0 -0
  67. data/spec/rails2/rails_app/log/server.log +0 -0
  68. data/spec/rails2/rails_app/log/test.log +4158 -0
  69. data/spec/rails2/rails_app/public/404.html +30 -0
  70. data/spec/rails2/rails_app/public/422.html +30 -0
  71. data/spec/rails2/rails_app/public/500.html +30 -0
  72. data/spec/rails2/rails_app/public/favicon.ico +0 -0
  73. data/spec/rails2/rails_app/public/images/rails.png +0 -0
  74. data/spec/rails2/rails_app/public/index.html +275 -0
  75. data/spec/rails2/rails_app/public/javascripts/application.js +2 -0
  76. data/spec/rails2/rails_app/public/javascripts/controls.js +963 -0
  77. data/spec/rails2/rails_app/public/javascripts/dragdrop.js +973 -0
  78. data/spec/rails2/rails_app/public/javascripts/effects.js +1128 -0
  79. data/spec/rails2/rails_app/public/javascripts/prototype.js +4320 -0
  80. data/spec/rails2/rails_app/public/robots.txt +5 -0
  81. data/spec/rails2/rails_app/script/about +4 -0
  82. data/spec/rails2/rails_app/script/console +3 -0
  83. data/spec/rails2/rails_app/script/dbconsole +3 -0
  84. data/spec/rails2/rails_app/script/destroy +3 -0
  85. data/spec/rails2/rails_app/script/generate +3 -0
  86. data/spec/rails2/rails_app/script/performance/benchmarker +3 -0
  87. data/spec/rails2/rails_app/script/performance/profiler +3 -0
  88. data/spec/rails2/rails_app/script/plugin +3 -0
  89. data/spec/rails2/rails_app/script/runner +3 -0
  90. data/spec/rails2/rails_app/script/server +3 -0
  91. data/spec/rails2/rails_app/spec/rails_helpers_spec.rb +255 -0
  92. data/spec/rails2/rails_app/spec/rails_spec_helper.rb +34 -0
  93. data/spec/rails2/rails_app/spec/rails_widget_spec.rb +83 -0
  94. data/spec/rails2/rails_app/spec/render_spec.rb +324 -0
  95. data/spec/rails2/rails_app/test/performance/browsing_test.rb +9 -0
  96. data/spec/rails2/rails_app/test/test_helper.rb +38 -0
  97. data/spec/rails2/rails_app/vendor/plugins/rails_xss/MIT-LICENSE +20 -0
  98. data/spec/rails2/rails_app/vendor/plugins/rails_xss/README.markdown +90 -0
  99. data/spec/rails2/rails_app/vendor/plugins/rails_xss/Rakefile +23 -0
  100. data/spec/rails2/rails_app/vendor/plugins/rails_xss/init.rb +7 -0
  101. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss.rb +3 -0
  102. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/action_view.rb +87 -0
  103. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/erubis.rb +33 -0
  104. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb +52 -0
  105. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/tasks/rails_xss_tasks.rake +4 -0
  106. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/active_record_helper_test.rb +74 -0
  107. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/asset_tag_helper_test.rb +49 -0
  108. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/caching_test.rb +43 -0
  109. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/date_helper_test.rb +29 -0
  110. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/deprecated_output_safety_test.rb +112 -0
  111. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/erb_util_test.rb +36 -0
  112. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_helper_test.rb +1447 -0
  113. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_tag_helper_test.rb +354 -0
  114. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/output_safety_test.rb +115 -0
  115. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/rails_xss_test.rb +23 -0
  116. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/test_helper.rb +5 -0
  117. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/text_helper_test.rb +17 -0
  118. data/spec/spec_helper.rb +2 -6
  119. metadata +348 -23
  120. data/lib/erector/errors.rb +0 -12
  121. data/lib/erector/extensions/hash.rb +0 -21
  122. data/lib/erector/extensions/object.rb +0 -18
  123. data/lib/erector/rails/rails_version.rb +0 -6
  124. data/rails/init.rb +0 -4
@@ -0,0 +1,11 @@
1
+ module Erector
2
+ class Railtie < ::Rails::Railtie
3
+ # config.generators.template_engine :rb
4
+
5
+ # TODO: automatically add app directory to app.config.autoload_paths,
6
+ # so that Views::Foo::Bar autoloads, and 'require "views/foo/bar.html"'
7
+ # works. For now, you must add the following to config/application.rb:
8
+ #
9
+ # config.autoload_paths += %W(#{config.root}/app)
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Erector
2
+ module Rails
3
+ class TemplateHandler
4
+ def call(template)
5
+ require_dependency template.identifier
6
+ widget_class_name = "views/#{template.identifier =~ %r(views/([^.]*)(\..*)?\.rb) && $1}".camelize
7
+ is_partial = File.basename(template.identifier) =~ /^_/
8
+ <<-SRC
9
+ Erector::Rails.render(#{widget_class_name}, self, local_assigns, #{!!is_partial})
10
+ SRC
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ ActionView::Template.register_template_handler :rb, Erector::Rails::TemplateHandler.new
@@ -0,0 +1,6 @@
1
+ require 'action_controller/metal/renderers'
2
+
3
+ ActionController.add_renderer :widget do |widget, options|
4
+ self.content_type ||= options[:content_type] || Mime[:html]
5
+ Erector::Rails.render(widget, view_context, {}, false, options)
6
+ end
@@ -0,0 +1,27 @@
1
+ require "action_controller"
2
+ require "erector/rails2/rails_version"
3
+ require "erector/rails2/rails_form_builder"
4
+ require "erector/rails2/extensions/action_controller"
5
+ require "erector/rails2/extensions/rails_helpers"
6
+ require "erector/rails2/extensions/rails_widget"
7
+ require "erector/rails2/template_handlers/rb_handler"
8
+ require "erector/rails2/template_handlers/ert_handler"
9
+
10
+ module Erector
11
+ def self.init_rails(binding)
12
+ # Rails defaults do not include app/views in the eager load path.
13
+ # It needs to be there, because erector views are .rb files.
14
+ if config = eval("config if defined? config", binding)
15
+ view_path = config.view_path
16
+ config.load_paths << view_path unless config.load_paths.include?(view_path)
17
+ config.eager_load_paths << view_path unless config.eager_load_paths.include?(view_path)
18
+
19
+ # Rails probably already ran Initializer#set_load_path and
20
+ # #set_autoload_paths by the time we got here.
21
+ $LOAD_PATH.unshift(view_path) unless $LOAD_PATH.include?(view_path)
22
+ unless ActiveSupport::Dependencies.load_paths.include?(view_path)
23
+ ActiveSupport::Dependencies.load_paths << view_path
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,6 +1,6 @@
1
1
  ActionController::Base.class_eval do
2
2
  class_inheritable_accessor :ert_template_base_class
3
-
3
+
4
4
  def render_widget(widget_class, assigns=nil, options={})
5
5
  render options.merge(:text => Erector::Rails.render(widget_class, response.template, assigns, options))
6
6
  end
@@ -13,6 +13,7 @@ module Erector
13
13
  def self.def_simple_rails_helper(method_name)
14
14
  module_eval(<<-METHOD_DEF, __FILE__, __LINE__+1)
15
15
  def #{method_name}(*args, &block)
16
+ # i wonder why this is text and not rawtext
16
17
  text parent.#{method_name}(*args, &block)
17
18
  end
18
19
  METHOD_DEF
@@ -93,20 +94,32 @@ module Erector
93
94
  if block_given?
94
95
  parent.#{method_name}(*args, &block)
95
96
  else
96
- text parent.#{method_name}(*args, &block)
97
+ rails_helper_output = parent.#{method_name}(*args, &block)
98
+ # i wonder why this is text and not rawtext
99
+ text rails_helper_output
97
100
  end
98
101
  end
99
102
  METHOD_DEF
100
103
  end
101
104
 
102
- [:link_to,
103
- :form_tag,
105
+ [:form_tag,
104
106
  :field_set_tag,
105
107
  :form_remote_tag,
106
108
  :javascript_tag].each do |method_name|
107
109
  def_block_rails_helper(method_name)
108
110
  end
109
111
 
112
+ def link_to(*args, &block)
113
+ if block_given?
114
+ parent.link_to(*args, &block)
115
+ else
116
+ args[0] = CGI.escapeHTML(args[0])
117
+ rails_helper_output = parent.link_to(*args, &block)
118
+ # i wonder why this is text and not rawtext
119
+ text rails_helper_output
120
+ end
121
+ end
122
+
110
123
  # Delegate to non-markup producing helpers via method_missing,
111
124
  # returning their result directly.
112
125
  def method_missing(name, *args, &block)
@@ -144,7 +157,7 @@ module Erector
144
157
  args.push(options)
145
158
  parent.fields_for(record_or_name_or_array, *args, &proc)
146
159
  end
147
-
160
+
148
161
  def flash
149
162
  parent.controller.send(:flash)
150
163
  end
@@ -43,11 +43,14 @@ module Erector
43
43
 
44
44
  view.send(:_evaluate_assigns_and_ivars)
45
45
 
46
- view.with_output_buffer do
46
+ output_buffer = view.with_output_buffer do
47
47
  # Set parent to the view and use Rails's output buffer.
48
+ new_output = Output.new { view.output_buffer }
48
49
  widget.to_html(options.merge(:parent => view,
49
- :output => Output.new { view.output_buffer }))
50
+ :output => new_output))
50
51
  end
52
+ output_buffer
53
+
51
54
  end
52
55
 
53
56
  module WidgetExtensions
@@ -100,7 +103,7 @@ module Erector
100
103
  @controller_assigns_propagate_to_partials = (new_value ? :true : :false)
101
104
  end
102
105
  end
103
-
106
+
104
107
  def self.included(base)
105
108
  base.extend(ClassMethods)
106
109
  end
@@ -0,0 +1,6 @@
1
+ module Erector
2
+ module Rails
3
+ RAILS_VERSION = "2.3.11"
4
+ RAILS_VERSION_TAG = "v2.3.11"
5
+ end
6
+ end
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  # Out of the box, the Cells plugin for Rails (http://cells.rubyforge.org/)
20
20
  # does not work with Erector, because Erector tries to grab instance variables
21
- # off the controller, rather than the cell itself.
21
+ # off the controller, rather than the cell itself.
22
22
  #
23
23
  # This code patches up Cell::View to make it work, but only if the Cells plugin
24
24
  # is installed. (That's the bare "Cell::View" at the top, and rescue NameError
@@ -28,7 +28,7 @@ end
28
28
  # loaded at all.
29
29
  begin
30
30
  Cell::View
31
-
31
+
32
32
  class Cell::View < ActionView::Base
33
33
  def instance_variables_for_widget_assignment
34
34
  instance_variables_for_widget_assignment_for(cell)
@@ -0,0 +1,208 @@
1
+ require "erector/rails/template_handler"
2
+ require "erector/rails/railtie"
3
+ require "erector/rails/widget_renderer"
4
+ require "erector/rails/form_builder"
5
+
6
+ module Erector
7
+ module Rails
8
+ class << self
9
+ def should_assign?(name, widget_class, is_partial)
10
+ (!widget_class.ignore_extra_controller_assigns || widget_class.needs?(name)) &&
11
+ (!is_partial || widget_class.controller_assigns_propagate_to_partials)
12
+ end
13
+
14
+ def assigns_for(widget_class, view, local_assigns, is_partial)
15
+ assigns = {}
16
+
17
+ view.assigns.each do |name, value|
18
+ name = name.to_sym
19
+ assigns[name] = value if should_assign?(name, widget_class, is_partial)
20
+ end
21
+
22
+ assigns.merge!(filter_local_assigns_for_partial(widget_class, local_assigns)) if is_partial
23
+
24
+ assigns
25
+ end
26
+
27
+ def filter_local_assigns_for_partial(widget_class, local_assigns)
28
+ widget_class_variable_name = widget_class.name.underscore
29
+ widget_class_variable_name = $1 if widget_class_variable_name =~ %r{.*/(.*?)$}
30
+
31
+ local_assigns.reject do |name, value|
32
+ name == :object || name == widget_class_variable_name.to_sym
33
+ end
34
+ end
35
+
36
+ def render(widget, view, local_assigns = {}, is_partial = false, options = {})
37
+ widget = widget.new(assigns_for(widget, view, local_assigns, is_partial)) if widget.is_a?(Class)
38
+ view.with_output_buffer do
39
+ # Set parent and helpers to the view and use Rails's output buffer.
40
+ widget.to_html(options.merge(:helpers => view,
41
+ :parent => view,
42
+ :output => Output.new { view.output_buffer }))
43
+ end
44
+ end
45
+
46
+ # Wrappers for rails helpers that produce markup. Erector needs to
47
+ # manually emit their result.
48
+ def def_simple_rails_helper(method_name)
49
+ module_eval <<-METHOD_DEF, __FILE__, __LINE__+1
50
+ def #{method_name}(*args, &block)
51
+ text helpers.#{method_name}(*args, &block)
52
+ end
53
+ METHOD_DEF
54
+ end
55
+
56
+ def def_rails_form_helper(method_name)
57
+ module_eval <<-METHOD_DEF, __FILE__, __LINE__+1
58
+ def #{method_name}(*args, &block)
59
+ options = args.extract_options!
60
+ args << options.merge(:builder => FormBuilder.wrapping(options[:builder]))
61
+ text helpers.#{method_name}(*args, &block)
62
+ end
63
+ METHOD_DEF
64
+ end
65
+ end
66
+
67
+ extend ActiveSupport::Concern
68
+
69
+ included do
70
+ # Often, large Rails applications will assign many controller instance variables.
71
+ # Sometimes these aren't used by a view: ApplicationController might assign
72
+ # variables that are used by many, but not all, views; and various other things
73
+ # may accumulate, especially if you've been using templating systems that are
74
+ # more forgiving than Erector. If you then migrate to Erector, you're stuck using
75
+ # no "needs" declaration at all, because it needs to contain every assigned
76
+ # variable, or Erector will raise an exception.
77
+ #
78
+ # If you set this to true (and it's inherited through to subclasses), however,
79
+ # then "needs" declarations on the widget will cause excess controller variables
80
+ # to be ignored -- they'll be unavailable to the widget (so 'needs' still means
81
+ # something), but they won't cause widget instantiation to fail, either. This
82
+ # can let a large Rails project transition to Erector more smoothly.
83
+ class_attribute :ignore_extra_controller_assigns
84
+ self.ignore_extra_controller_assigns = true
85
+
86
+ # In ERb templates, controller instance variables are available to any partial
87
+ # that gets rendered by the view, no matter how deeply-nested. This effectively
88
+ # makes controller instance variables "globals". In small view hierarchies this
89
+ # probably isn't an issue, but in large ones it can make debugging and
90
+ # reasoning about the code very difficult.
91
+ #
92
+ # If you set this to true (and it's inherited through to subclasses), then any
93
+ # widget that's getting rendered as a partial will only have access to locals
94
+ # explicitly passed to it (render :partial => ..., :locals => ...). (This
95
+ # doesn't change the behavior of widgets that are explicitly rendered, as they
96
+ # don't have this issue.) This can allow for cleaner encapsulation of partials,
97
+ # as they must be passed everything they use and can't rely on controller
98
+ # instance variables.
99
+ class_attribute :controller_assigns_propagate_to_partials
100
+ self.controller_assigns_propagate_to_partials = true
101
+ end
102
+
103
+ # We need to delegate #capture to helpers.capture, so that when
104
+ # the captured block is executed, both erector and Rails output
105
+ # from within the block go to the appropriate buffer.
106
+ def capture(&block)
107
+ if helpers.respond_to?(:capture)
108
+ raw(helpers.capture(&block).to_s)
109
+ else
110
+ super
111
+ end
112
+ end
113
+
114
+ def render(*args, &block)
115
+ captured = helpers.capture do
116
+ helpers.concat(helpers.render(*args, &block))
117
+ helpers.output_buffer.to_s
118
+ end
119
+ rawtext(captured)
120
+ end
121
+
122
+ # Delegate to non-markup producing helpers via method_missing,
123
+ # returning their result directly.
124
+ def method_missing(name, *args, &block)
125
+ if helpers.respond_to?(name)
126
+ helpers.send(name, *args, &block)
127
+ else
128
+ super
129
+ end
130
+ end
131
+
132
+ # Since we delegate method_missing to helpers, we need to delegate
133
+ # respond_to? as well.
134
+ def respond_to?(name)
135
+ super || helpers.respond_to?(name)
136
+ end
137
+
138
+ [
139
+ # UrlHelper
140
+ :link_to,
141
+ :button_to,
142
+ :link_to_unless_current,
143
+ :link_to_unless,
144
+ :link_to_if,
145
+ :mail_to,
146
+
147
+ # FormTagHelper
148
+ :form_tag,
149
+ :select_tag,
150
+ :text_field_tag,
151
+ :label_tag,
152
+ :hidden_field_tag,
153
+ :file_field_tag,
154
+ :password_field_tag,
155
+ :text_area_tag,
156
+ :check_box_tag,
157
+ :radio_button_tag,
158
+ :submit_tag,
159
+ :image_submit_tag,
160
+ :field_set_tag,
161
+
162
+ # FormHelper
163
+ :form_for,
164
+ :text_field,
165
+ :password_field,
166
+ :hidden_field,
167
+ :file_field,
168
+ :text_area,
169
+ :check_box,
170
+ :radio_button,
171
+
172
+ # AssetTagHelper
173
+ :auto_discovery_link_tag,
174
+ :javascript_include_tag,
175
+ :stylesheet_link_tag,
176
+ :image_tag,
177
+
178
+ # ScriptaculousHelper
179
+ :sortable_element,
180
+ :sortable_element_js,
181
+ :text_field_with_auto_complete,
182
+ :draggable_element,
183
+ :drop_receiving_element,
184
+
185
+ # PrototypeHelper
186
+ :link_to_remote,
187
+ :button_to_remote,
188
+ :periodically_call_remote,
189
+ :form_remote_tag,
190
+ :submit_to_remote,
191
+ :update_page_tag,
192
+
193
+ # JavaScriptHelper
194
+ :javascript_tag,
195
+
196
+ # CsrfHelper
197
+ :csrf_meta_tag
198
+ ].each do |method_name|
199
+ def_simple_rails_helper(method_name)
200
+ end
201
+
202
+ [:form_for, :fields_for].each do |method_name|
203
+ def_rails_form_helper(method_name)
204
+ end
205
+
206
+ Erector::Widget.send :include, self
207
+ end
208
+ end
@@ -4,5 +4,9 @@ module Erector
4
4
  def html_safe?
5
5
  true
6
6
  end
7
+
8
+ def to_s
9
+ self
10
+ end
7
11
  end
8
12
  end
@@ -33,6 +33,14 @@ class ExternalRenderer < Erector::Widget
33
33
  rawtext external.text
34
34
  end
35
35
  end
36
+
37
+ if Object.const_defined?(:Sass)
38
+ rendered_externals(:scss).each do |external|
39
+ style({:type => "text/css", 'xml:space' => 'preserve'}.merge(external.options)) do
40
+ rawtext Sass.compile(external.text)
41
+ end
42
+ end
43
+ end
36
44
  end
37
45
 
38
46
  def inline_scripts
@@ -1,6 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
- require "erector/rails"
3
- require "rails/version"
1
+ require File.expand_path("../../spec_helper", __FILE__)
4
2
 
5
3
  # backport mktmpdir so this test will work on Ruby 1.8.6
6
4
  unless Dir.respond_to?(:mktmpdir)
@@ -49,60 +47,47 @@ end
49
47
  # converter tool on a newly generated scaffold app (like we brag about in the
50
48
  # user guide).
51
49
  #
52
- module Erector
53
- describe "the Rails version" do
54
- it "should be #{Erector::Rails::RAILS_VERSION}" do
55
- ::Rails::VERSION::STRING.should == Erector::Rails::RAILS_VERSION
50
+ describe "the 'erector' command" do
51
+ def run(cmd)
52
+ stderr_file = Dir.tmpdir + "/stderr.txt"
53
+ stdout = IO.popen(cmd + " 2>#{stderr_file}") do |pipe|
54
+ pipe.read
56
55
  end
57
- end
58
-
59
- describe "Erect in a Rails app" do
60
- def run(cmd)
61
- stderr_file = Dir.tmpdir + "/stderr.txt"
62
- stdout = IO.popen(cmd + " 2>#{stderr_file}") do |pipe|
63
- pipe.read
64
- end
65
- stderr = File.open(stderr_file) {|f| f.read}
66
- FileUtils.rm_f(stderr_file)
67
- if $?.exitstatus != 0
68
- raise "Command #{cmd} failed\nDIR:\n #{Dir.getwd}\nSTDOUT:\n#{indent stdout}\nSTDERR:\n#{indent stderr}"
69
- else
70
- return stdout
71
- end
72
- end
73
-
74
- def indent(s)
75
- s.gsub(/^/, ' ')
56
+ stderr = File.open(stderr_file) {|f| f.read}
57
+ FileUtils.rm_f(stderr_file)
58
+ if $?.exitstatus != 0 || stdout =~ /\berror\b/
59
+ run_info = "Command #{cmd} failed\nDIR:\n #{Dir.getwd}\nSTDOUT:\n#{indent stdout}\nSTDERR:\n#{indent stderr}"
60
+ raise run_info
61
+ else
62
+ return stdout
76
63
  end
64
+ end
77
65
 
78
- it "works like we say it does in the user guide" do
79
- erector_dir = File.expand_path("#{File.dirname(__FILE__)}/../..")
80
-
81
- # We add the paths to our vendored copy of rails to the load paths, so
82
- # that this spec can be run without having a version of Rails (which may
83
- # not match the version we wish to test against) installed.
84
- rails_libs_argument = "-I'#{RAILS_LOAD_PATHS.join("':'")}'"
85
-
86
- Dir.mktmpdir do |app_dir|
87
- run "ruby #{rails_libs_argument} '#{VENDOR_RAILS}/railties/bin/rails' '#{app_dir}'"
88
-
89
- FileUtils.cp_r(VENDOR_RAILS, "#{app_dir}/vendor/rails")
66
+ def indent(s)
67
+ s.gsub(/^/, ' ')
68
+ end
90
69
 
91
- FileUtils.mkdir_p(app_dir + "/vendor/gems")
92
- FileUtils.cp_r(erector_dir, "#{app_dir}/vendor/gems/erector")
70
+ it "works like we say it does in the user guide" do
71
+ erector_dir = File.expand_path("../../..", __FILE__)
72
+ Dir.mktmpdir do |app_dir|
73
+ FileUtils.cd(app_dir) do
74
+ run "bundle exec rails new dummy"
93
75
 
94
- FileUtils.cd(app_dir) do
95
- run "script/generate scaffold post title:string body:text published:boolean"
76
+ File.open('dummy/Gemfile', 'a+') do |gemfile|
77
+ require 'rails/version'
78
+ gemfile.write <<-GEMFILE.strip
79
+ gem "erector", :path => "#{erector_dir}"
80
+ GEMFILE
81
+ end
96
82
 
97
- # The 'erector' binary would normally have been installed through rubygems,
98
- # providing it with a wrapper script which requires rubygems. But here we
99
- # run it directly, so we need to require rubygems explicitly before running
100
- # the main script.
101
- run "ruby #{rails_libs_argument} -I'#{erector_dir}/lib' " +
102
- "-e \"require 'rubygems'; load '#{erector_dir}/bin/erector'\" app/views/posts"
83
+ FileUtils.cd('dummy') do
84
+ # puts File.read("./Gemfile")
85
+ run "BUNDLE_GEMFILE=./Gemfile bundle install"
86
+ run "BUNDLE_GEMFILE=./Gemfile bundle exec rails generate scaffold post title:string body:text published:boolean"
87
+ run "BUNDLE_GEMFILE=./Gemfile bundle exec #{erector_dir}/bin/erector ./app/views/posts"
103
88
 
104
89
  FileUtils.rm_f("app/views/posts/*.erb")
105
- run "rake --trace db:migrate"
90
+ run "BUNDLE_GEMFILE=./Gemfile bundle exec rake --trace db:migrate"
106
91
 
107
92
  # run "script/server" # todo: launch in background; use mechanize or something to crawl it; then kill it
108
93
  # perhaps use open4?