erector 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +0 -4
- data/VERSION.yml +1 -1
- data/lib/erector.rb +2 -4
- data/lib/erector/abstract_widget.rb +2 -1
- data/lib/erector/erect/erect.rb +17 -14
- data/lib/erector/erect/rhtml.treetop +18 -10
- data/lib/erector/externals.rb +7 -1
- data/lib/erector/html.rb +30 -39
- data/lib/erector/rails.rb +6 -26
- data/lib/erector/rails/form_builder.rb +36 -0
- data/lib/erector/rails/railtie.rb +11 -0
- data/lib/erector/rails/template_handler.rb +16 -0
- data/lib/erector/rails/widget_renderer.rb +6 -0
- data/lib/erector/rails2.rb +27 -0
- data/lib/erector/{rails → rails2}/extensions/action_controller.rb +1 -1
- data/lib/erector/{rails → rails2}/extensions/rails_helpers.rb +17 -4
- data/lib/erector/{rails → rails2}/extensions/rails_widget.rb +6 -3
- data/lib/erector/{rails → rails2}/rails_form_builder.rb +0 -0
- data/lib/erector/rails2/rails_version.rb +6 -0
- data/lib/erector/{rails → rails2}/template_handlers/ert_handler.rb +0 -0
- data/lib/erector/{rails → rails2}/template_handlers/rb_handler.rb +2 -2
- data/lib/erector/rails3.rb +208 -0
- data/lib/erector/raw_string.rb +4 -0
- data/lib/erector/widgets/external_renderer.rb +8 -0
- data/spec/erect/erect_rails_spec.rb +34 -49
- data/spec/erect/erected_spec.rb +11 -0
- data/spec/rails2/erect_rails_spec.rb +114 -0
- data/spec/rails2/rails_app/Gemfile +12 -0
- data/spec/rails2/rails_app/Gemfile.lock +89 -0
- data/spec/rails2/rails_app/README +243 -0
- data/spec/rails2/rails_app/Rakefile +19 -0
- data/spec/rails2/rails_app/app/controllers/application_controller.rb +10 -0
- data/spec/rails2/rails_app/app/helpers/application_helper.rb +3 -0
- data/spec/rails2/rails_app/app/views/test/_erb.erb +1 -0
- data/spec/rails2/rails_app/app/views/test/_erector.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/_partial_with_locals.rb +7 -0
- data/spec/rails2/rails_app/app/views/test/bare.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/erb_from_erector.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/erector_from_erb.html.erb +1 -0
- data/spec/rails2/rails_app/app/views/test/erector_with_locals_from_erb.html.erb +6 -0
- data/spec/rails2/rails_app/app/views/test/implicit_assigns.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/needs.html.rb +7 -0
- data/spec/rails2/rails_app/app/views/test/needs_subclass.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/protected_instance_variable.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/render_default.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/render_partial.html.rb +5 -0
- data/spec/rails2/rails_app/config/boot.rb +114 -0
- data/spec/rails2/rails_app/config/database.yml +16 -0
- data/spec/rails2/rails_app/config/environment.rb +42 -0
- data/spec/rails2/rails_app/config/environments/development.rb +17 -0
- data/spec/rails2/rails_app/config/environments/production.rb +28 -0
- data/spec/rails2/rails_app/config/environments/test.rb +28 -0
- data/spec/rails2/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails2/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/rails2/rails_app/config/initializers/inflections.rb +10 -0
- data/spec/rails2/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails2/rails_app/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/rails2/rails_app/config/initializers/session_store.rb +15 -0
- data/spec/rails2/rails_app/config/locales/en.yml +5 -0
- data/spec/rails2/rails_app/config/routes.rb +43 -0
- data/spec/rails2/rails_app/db/development.sqlite3 +0 -0
- data/spec/rails2/rails_app/db/schema.rb +14 -0
- data/spec/rails2/rails_app/db/seeds.rb +7 -0
- data/spec/rails2/rails_app/doc/README_FOR_APP +2 -0
- data/spec/rails2/rails_app/log/development.log +76 -0
- data/spec/rails2/rails_app/log/production.log +0 -0
- data/spec/rails2/rails_app/log/server.log +0 -0
- data/spec/rails2/rails_app/log/test.log +4158 -0
- data/spec/rails2/rails_app/public/404.html +30 -0
- data/spec/rails2/rails_app/public/422.html +30 -0
- data/spec/rails2/rails_app/public/500.html +30 -0
- data/spec/rails2/rails_app/public/favicon.ico +0 -0
- data/spec/rails2/rails_app/public/images/rails.png +0 -0
- data/spec/rails2/rails_app/public/index.html +275 -0
- data/spec/rails2/rails_app/public/javascripts/application.js +2 -0
- data/spec/rails2/rails_app/public/javascripts/controls.js +963 -0
- data/spec/rails2/rails_app/public/javascripts/dragdrop.js +973 -0
- data/spec/rails2/rails_app/public/javascripts/effects.js +1128 -0
- data/spec/rails2/rails_app/public/javascripts/prototype.js +4320 -0
- data/spec/rails2/rails_app/public/robots.txt +5 -0
- data/spec/rails2/rails_app/script/about +4 -0
- data/spec/rails2/rails_app/script/console +3 -0
- data/spec/rails2/rails_app/script/dbconsole +3 -0
- data/spec/rails2/rails_app/script/destroy +3 -0
- data/spec/rails2/rails_app/script/generate +3 -0
- data/spec/rails2/rails_app/script/performance/benchmarker +3 -0
- data/spec/rails2/rails_app/script/performance/profiler +3 -0
- data/spec/rails2/rails_app/script/plugin +3 -0
- data/spec/rails2/rails_app/script/runner +3 -0
- data/spec/rails2/rails_app/script/server +3 -0
- data/spec/rails2/rails_app/spec/rails_helpers_spec.rb +255 -0
- data/spec/rails2/rails_app/spec/rails_spec_helper.rb +34 -0
- data/spec/rails2/rails_app/spec/rails_widget_spec.rb +83 -0
- data/spec/rails2/rails_app/spec/render_spec.rb +324 -0
- data/spec/rails2/rails_app/test/performance/browsing_test.rb +9 -0
- data/spec/rails2/rails_app/test/test_helper.rb +38 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/MIT-LICENSE +20 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/README.markdown +90 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/Rakefile +23 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/init.rb +7 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss.rb +3 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/action_view.rb +87 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/erubis.rb +33 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb +52 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/tasks/rails_xss_tasks.rake +4 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/active_record_helper_test.rb +74 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/asset_tag_helper_test.rb +49 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/caching_test.rb +43 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/date_helper_test.rb +29 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/deprecated_output_safety_test.rb +112 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/erb_util_test.rb +36 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_helper_test.rb +1447 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_tag_helper_test.rb +354 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/output_safety_test.rb +115 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/rails_xss_test.rb +23 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/test_helper.rb +5 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/text_helper_test.rb +17 -0
- data/spec/spec_helper.rb +2 -6
- metadata +348 -23
- data/lib/erector/errors.rb +0 -12
- data/lib/erector/extensions/hash.rb +0 -21
- data/lib/erector/extensions/object.rb +0 -18
- data/lib/erector/rails/rails_version.rb +0 -6
- data/rails/init.rb +0 -4
data/README.txt
CHANGED
@@ -67,10 +67,6 @@ When installing this way, erector is automatically available to your Rails code
|
|
67
67
|
|
68
68
|
Three spec rake tasks are provided: spec:core (core functionality),
|
69
69
|
spec:erect (the erector command line tool), and spec:rails (rails integration).
|
70
|
-
You do not need to have Rails installed to run the latter two; they will clone
|
71
|
-
the rails git repository and set it up for testing automatically. You can test
|
72
|
-
against a different version of Rails by changing the constants in
|
73
|
-
lib/erector/rails/rails_version.rb
|
74
70
|
|
75
71
|
'rake spec' will run the complete set of specs.
|
76
72
|
|
data/VERSION.yml
CHANGED
data/lib/erector.rb
CHANGED
@@ -9,9 +9,6 @@ rescue LoadError => e
|
|
9
9
|
# oh well, no Sass
|
10
10
|
end
|
11
11
|
|
12
|
-
require "erector/errors"
|
13
|
-
require "erector/extensions/object"
|
14
|
-
require "erector/extensions/hash"
|
15
12
|
require "erector/raw_string"
|
16
13
|
require "erector/dependencies"
|
17
14
|
require "erector/dependency"
|
@@ -28,7 +25,8 @@ require "erector/abstract_widget"
|
|
28
25
|
require "erector/widget"
|
29
26
|
|
30
27
|
require "erector/inline"
|
31
|
-
require "erector/unicode"
|
32
28
|
require "erector/widgets"
|
33
29
|
require "erector/version"
|
34
30
|
require "erector/mixin"
|
31
|
+
|
32
|
+
require "erector/rails" if defined?(Rails)
|
@@ -32,7 +32,7 @@ module Erector
|
|
32
32
|
|
33
33
|
def initialize(assigns = {}, &block)
|
34
34
|
unless assigns.is_a? Hash
|
35
|
-
raise "Erector widgets are initialized with only a parameter hash. (Other parameters are passed to to_html, or the #widget method.)"
|
35
|
+
raise ArgumentError, "Erector widgets are initialized with only a parameter hash, but you passed #{assigns.class}:#{assigns.inspect}. (Other parameters are passed to to_html, or the #widget method.)"
|
36
36
|
end
|
37
37
|
|
38
38
|
@_assigns = assigns
|
@@ -66,6 +66,7 @@ module Erector
|
|
66
66
|
# Rails view object.
|
67
67
|
# content_method_name:: in case you want to call a method other than
|
68
68
|
# #content, pass its name in here.
|
69
|
+
#
|
69
70
|
def to_html(options = {})
|
70
71
|
raise "Erector::Widget#to_html takes an options hash, not a symbol. Try calling \"to_html(:content_method_name=> :#{options})\"" if options.is_a? Symbol
|
71
72
|
_render(options).to_s
|
data/lib/erector/erect/erect.rb
CHANGED
@@ -3,6 +3,9 @@ require "rake"
|
|
3
3
|
require "erector/erect/erected" # pull this out so we don't recreate the grammar every time
|
4
4
|
|
5
5
|
module Erector
|
6
|
+
|
7
|
+
# "erect" is the erstwhile name of the command-line tool that converts between HTML/ERB and Erector.
|
8
|
+
# It's invoked via "erector --to-html foo.rb" or "erector --to-erector foo.html" (default is --to-erector)
|
6
9
|
class Erect
|
7
10
|
attr_reader :files, :verbose, :mode, :output_dir, :superklass, :method_name
|
8
11
|
def initialize(args)
|
@@ -11,7 +14,7 @@ module Erector
|
|
11
14
|
@output_dir = nil
|
12
15
|
@superklass = 'Erector::Widget'
|
13
16
|
@method_name = 'content'
|
14
|
-
|
17
|
+
|
15
18
|
opts = OptionParser.new do |opts|
|
16
19
|
opts.banner = "Usage: erector [options] [file|dir]*"
|
17
20
|
|
@@ -23,7 +26,7 @@ module Erector
|
|
23
26
|
"Operate silently except in case of error") do |quiet|
|
24
27
|
@verbose = !quiet
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
opts.on("--to-erector", "(default) Convert from html/rhtml to erector classes") do
|
28
31
|
@mode = :to_erector
|
29
32
|
end
|
@@ -31,15 +34,15 @@ module Erector
|
|
31
34
|
opts.on("--to-html", "Convert from erector to html") do
|
32
35
|
@mode = :to_html
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
opts.on("--superclass SUPERCLASS", "Superclass for new widget (default Erector::Widget)") do |superklass|
|
36
39
|
@superklass = superklass
|
37
40
|
end
|
38
|
-
|
41
|
+
|
39
42
|
opts.on("--method METHOD", "Method containing content for widget (default 'content')") do |method_name|
|
40
43
|
@method_name = method_name
|
41
44
|
end
|
42
|
-
|
45
|
+
|
43
46
|
opts.on("-o", "--output-dir DIRECTORY", "Output files to DIRECTORY (default: output files go next to input files)") do |dir|
|
44
47
|
@output_dir = dir
|
45
48
|
end
|
@@ -54,17 +57,17 @@ module Erector
|
|
54
57
|
puts Erector::VERSION
|
55
58
|
exit
|
56
59
|
end
|
57
|
-
|
60
|
+
|
58
61
|
end
|
59
62
|
opts.parse!(args)
|
60
63
|
@files = args
|
61
64
|
explode_dirs
|
62
65
|
end
|
63
|
-
|
66
|
+
|
64
67
|
def say(msg)
|
65
68
|
print msg if verbose
|
66
69
|
end
|
67
|
-
|
70
|
+
|
68
71
|
#todo: unit test
|
69
72
|
def explode_dirs
|
70
73
|
exploded_files = FileList.new
|
@@ -77,7 +80,7 @@ module Erector
|
|
77
80
|
end
|
78
81
|
@files = exploded_files
|
79
82
|
end
|
80
|
-
|
83
|
+
|
81
84
|
def explode(dir)
|
82
85
|
case mode
|
83
86
|
when :to_erector
|
@@ -86,13 +89,13 @@ module Erector
|
|
86
89
|
FileList["#{dir}/**/*.rb"]
|
87
90
|
end
|
88
91
|
end
|
89
|
-
|
92
|
+
|
90
93
|
def run
|
91
94
|
@success = true
|
92
95
|
self.send(mode)
|
93
96
|
@success
|
94
97
|
end
|
95
|
-
|
98
|
+
|
96
99
|
def to_erector
|
97
100
|
files.each do |file|
|
98
101
|
say "Erecting #{file}... "
|
@@ -118,7 +121,7 @@ module Erector
|
|
118
121
|
filename = file.split('/').last.gsub(/\.rb$/, '')
|
119
122
|
widget_name = camelize(filename)
|
120
123
|
widget_class = constantize(widget_name)
|
121
|
-
|
124
|
+
|
122
125
|
if widget_class < Erector::Widget
|
123
126
|
widget = widget_class.new
|
124
127
|
#todo: skip if it's missing a no-arg constructor
|
@@ -139,7 +142,7 @@ module Erector
|
|
139
142
|
end
|
140
143
|
end
|
141
144
|
end
|
142
|
-
|
145
|
+
|
143
146
|
# stolen from activesuppport/lib/inflector.rb
|
144
147
|
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
145
148
|
if first_letter_in_uppercase
|
@@ -154,7 +157,7 @@ module Erector
|
|
154
157
|
end
|
155
158
|
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
156
159
|
end
|
157
|
-
|
160
|
+
|
158
161
|
|
159
162
|
end
|
160
163
|
end
|
@@ -80,11 +80,11 @@ grammar Rhtml
|
|
80
80
|
def convert_removing_trims
|
81
81
|
convert.gsub(/\s*\-\s*$/, '')
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def text_value_removing_trims
|
85
85
|
text_value.gsub(/\s*\-\s*$/, '')
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def convert
|
89
89
|
code = text_value.strip
|
90
90
|
# matches a word, followed by either a word, a string, or a symbol
|
@@ -101,7 +101,7 @@ grammar Rhtml
|
|
101
101
|
end
|
102
102
|
}
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
rule directive
|
106
106
|
'<!' [^>]* '>' <Erector::Indenting> {
|
107
107
|
def convert
|
@@ -113,7 +113,7 @@ grammar Rhtml
|
|
113
113
|
rule tagname
|
114
114
|
[A-Za-z0-9_:-]+
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
rule varname
|
118
118
|
[A-Za-z0-9_]+
|
119
119
|
end
|
@@ -157,7 +157,7 @@ grammar Rhtml
|
|
157
157
|
if stripped.empty?
|
158
158
|
""
|
159
159
|
else
|
160
|
-
line "text '#{stripped.
|
160
|
+
line "text '#{CGI.unescapeHTML(stripped).gsub(/\'/, "\\\\'")
|
161
161
|
}'"
|
162
162
|
end
|
163
163
|
end
|
@@ -197,19 +197,27 @@ grammar Rhtml
|
|
197
197
|
def value
|
198
198
|
val.text_value
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
def convert
|
202
202
|
extract_erb(val.text_value)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
def parenthesize_if_necessary(s)
|
206
206
|
return s if s.strip =~ /^\(.*\)$/ || s =~ /^[A-Z0-9_]*$/i
|
207
207
|
"(" + s + ")"
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
|
+
def escape_single_quotes(s)
|
211
|
+
s.gsub(/[']/, '\\\\\'')
|
212
|
+
end
|
213
|
+
|
214
|
+
def escape_quoted(s)
|
215
|
+
escape_single_quotes(CGI.unescapeHTML(s))
|
216
|
+
end
|
217
|
+
|
210
218
|
def extract_erb(s, parenthesize = true)
|
211
219
|
if s =~ /^(.*?)<%=(.*?)%>(.*?)$/
|
212
|
-
pre, code, post = $1
|
220
|
+
pre, code, post = escape_quoted($1), $2, escape_quoted($3)
|
213
221
|
out = ""
|
214
222
|
out = "'#{pre}' + " unless pre.length == 0
|
215
223
|
out += parenthesize_if_necessary(code.strip)
|
@@ -220,7 +228,7 @@ grammar Rhtml
|
|
220
228
|
out = parenthesize_if_necessary(out) if parenthesize
|
221
229
|
out
|
222
230
|
else
|
223
|
-
"'" + s
|
231
|
+
"'" + escape_quoted(s) + "'"
|
224
232
|
end
|
225
233
|
end
|
226
234
|
}
|
data/lib/erector/externals.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
module Erector
|
2
|
+
|
3
|
+
# Externals are a mechanism by which a widget can declare page-level
|
4
|
+
# resources upon which it depends. They are not emitted during the widget's
|
5
|
+
# normal rendering process. Rather, the Erector::Widget::Page keeps track of
|
6
|
+
# all the widgets it renders, then goes back and inserts the proper tags for
|
7
|
+
# all the externals inside its HEAD element.
|
2
8
|
module Externals
|
3
9
|
def self.included(base)
|
4
10
|
base.extend ClassMethods
|
@@ -45,7 +51,7 @@ module Erector
|
|
45
51
|
def my_dependencies
|
46
52
|
@my_dependencies ||= Dependencies.new
|
47
53
|
end
|
48
|
-
|
54
|
+
|
49
55
|
private
|
50
56
|
INFERABLE_TYPES = [:css, :js]
|
51
57
|
|
data/lib/erector/html.rb
CHANGED
@@ -177,6 +177,7 @@ module Erector
|
|
177
177
|
# Return a character given its unicode code point or unicode name.
|
178
178
|
def character(code_point_or_name)
|
179
179
|
if code_point_or_name.is_a?(Symbol)
|
180
|
+
require "erector/unicode"
|
180
181
|
found = Erector::CHARACTERS[code_point_or_name]
|
181
182
|
if found.nil?
|
182
183
|
raise "Unrecognized character #{code_point_or_name}"
|
@@ -203,7 +204,7 @@ module Erector
|
|
203
204
|
#
|
204
205
|
# Since "Authors should avoid putting two or more adjacent hyphens inside comments,"
|
205
206
|
# we emit a warning if you do that.
|
206
|
-
def comment(text = ''
|
207
|
+
def comment(text = '')
|
207
208
|
puts "Warning: Authors should avoid putting two or more adjacent hyphens inside comments." if text =~ /--/
|
208
209
|
|
209
210
|
conditional = text =~ /\[if .*\]/
|
@@ -212,9 +213,9 @@ module Erector
|
|
212
213
|
rawtext text
|
213
214
|
rawtext ">" if conditional
|
214
215
|
|
215
|
-
if
|
216
|
+
if block_given?
|
216
217
|
rawtext "\n"
|
217
|
-
|
218
|
+
yield
|
218
219
|
rawtext "\n"
|
219
220
|
end
|
220
221
|
|
@@ -224,43 +225,33 @@ module Erector
|
|
224
225
|
|
225
226
|
# Emits a javascript block inside a +script+ tag, wrapped in CDATA
|
226
227
|
# doohickeys like all the cool JS kids do.
|
227
|
-
def javascript(
|
228
|
-
if
|
229
|
-
|
228
|
+
def javascript(value = nil, attributes = {})
|
229
|
+
if value.is_a?(Hash)
|
230
|
+
attributes = value
|
231
|
+
value = nil
|
232
|
+
elsif block_given? && value
|
233
|
+
raise ArgumentError, "You can't pass both a block and a value to javascript -- please choose one."
|
230
234
|
end
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
value
|
237
|
-
|
238
|
-
|
239
|
-
|
235
|
+
|
236
|
+
script(attributes.merge(:type => "text/javascript")) do
|
237
|
+
# Shouldn't this be a "cdata" HtmlPart?
|
238
|
+
# (maybe, but the syntax is specific to javascript; it isn't
|
239
|
+
# really a generic XML CDATA section. Specifically,
|
240
|
+
# ]]> within value is not treated as ending the
|
241
|
+
# CDATA section by Firefox2 when parsing text/html,
|
242
|
+
# although I guess we could refuse to generate ]]>
|
243
|
+
# there, for the benefit of XML/XHTML parsers).
|
244
|
+
output << raw("\n// <![CDATA[\n")
|
245
|
+
if block_given?
|
246
|
+
yield
|
247
|
+
else
|
248
|
+
output << raw(value)
|
240
249
|
end
|
250
|
+
output << raw("\n// ]]>")
|
251
|
+
output.append_newline # this forces a newline even if we're not in pretty mode
|
241
252
|
end
|
242
|
-
attributes ||= {}
|
243
|
-
attributes[:type] = "text/javascript"
|
244
|
-
open_tag 'script', attributes
|
245
|
-
|
246
|
-
# Shouldn't this be a "cdata" HtmlPart?
|
247
|
-
# (maybe, but the syntax is specific to javascript; it isn't
|
248
|
-
# really a generic XML CDATA section. Specifically,
|
249
|
-
# ]]> within value is not treated as ending the
|
250
|
-
# CDATA section by Firefox2 when parsing text/html,
|
251
|
-
# although I guess we could refuse to generate ]]>
|
252
|
-
# there, for the benefit of XML/XHTML parsers).
|
253
|
-
rawtext "\n// <![CDATA[\n"
|
254
|
-
if block
|
255
|
-
instance_eval(&block)
|
256
|
-
else
|
257
|
-
rawtext value
|
258
|
-
end
|
259
|
-
rawtext "\n// ]]>"
|
260
|
-
output.append_newline # this forces a newline even if we're not in pretty mode
|
261
253
|
|
262
|
-
|
263
|
-
rawtext "\n"
|
254
|
+
output << raw("\n")
|
264
255
|
end
|
265
256
|
|
266
257
|
protected
|
@@ -322,7 +313,7 @@ module Erector
|
|
322
313
|
results << "#{key}=\"#{h(value)}\""
|
323
314
|
end
|
324
315
|
end
|
325
|
-
|
316
|
+
results.join(' ')
|
326
317
|
end
|
327
318
|
|
328
319
|
def sorted(attributes)
|
@@ -330,7 +321,7 @@ module Erector
|
|
330
321
|
attributes.each do |key, value|
|
331
322
|
stringized << [key.to_s, value]
|
332
323
|
end
|
333
|
-
|
324
|
+
stringized.sort
|
334
325
|
end
|
335
326
|
|
336
327
|
def sort_for_xml_declaration(attributes)
|
@@ -340,7 +331,7 @@ module Erector
|
|
340
331
|
attributes.each do |key, value|
|
341
332
|
stringized << [key.to_s, value]
|
342
333
|
end
|
343
|
-
|
334
|
+
stringized.sort{|a, b| b <=> a}
|
344
335
|
end
|
345
336
|
|
346
337
|
NON_NEWLINEY = {'i' => true, 'b' => true, 'small' => true,
|
data/lib/erector/rails.rb
CHANGED
@@ -1,27 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
require
|
6
|
-
require "erector/rails/extensions/rails_widget"
|
7
|
-
require "erector/rails/template_handlers/rb_handler"
|
8
|
-
require "erector/rails/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
|
1
|
+
require 'rails/version'
|
2
|
+
if Rails::VERSION::MAJOR == 2
|
3
|
+
require 'erector/rails2'
|
4
|
+
else
|
5
|
+
require 'erector/rails3'
|
27
6
|
end
|
7
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Erector
|
2
|
+
module Rails
|
3
|
+
class FormBuilder
|
4
|
+
class_attribute :parent_builder_class
|
5
|
+
self.parent_builder_class = ActionView::Base.default_form_builder
|
6
|
+
|
7
|
+
def self.wrapping(parent_builder_class)
|
8
|
+
return self if parent_builder_class.nil?
|
9
|
+
Class.new(self).tap do |klass|
|
10
|
+
klass.parent_builder_class = parent_builder_class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :parent, :template
|
15
|
+
|
16
|
+
def initialize(object_name, object, template, options, proc)
|
17
|
+
@template = template
|
18
|
+
@parent = parent_builder_class.new(object_name, object, template, options, proc)
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(method_name, *args, &block)
|
22
|
+
if parent.respond_to?(method_name)
|
23
|
+
return_value = parent.send(method_name, *args, &block)
|
24
|
+
if return_value.is_a?(String)
|
25
|
+
template.concat(return_value)
|
26
|
+
nil
|
27
|
+
else
|
28
|
+
return_value
|
29
|
+
end
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|