ghazel-erubis_rails_helper 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +66 -0
- data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
- data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
- data/lib/erubis_rails_helper.rb +20 -0
- data/test/abstract_unit.rb +51 -0
- data/test/controller/action_pack_assertions_test.rb +516 -0
- data/test/controller/addresses_render_test.rb +37 -0
- data/test/controller/assert_select_test.rb +734 -0
- data/test/controller/base_test.rb +217 -0
- data/test/controller/benchmark_test.rb +32 -0
- data/test/controller/caching_test.rb +690 -0
- data/test/controller/capture_test.rb +66 -0
- data/test/controller/content_type_test.rb +168 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +111 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
- data/test/controller/dispatcher_test.rb +103 -0
- data/test/controller/fake_controllers.rb +33 -0
- data/test/controller/fake_models.rb +19 -0
- data/test/controller/filter_params_test.rb +49 -0
- data/test/controller/filters_test.rb +885 -0
- data/test/controller/flash_test.rb +142 -0
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +224 -0
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/document_test.rb +148 -0
- data/test/controller/html-scanner/node_test.rb +89 -0
- data/test/controller/html-scanner/sanitizer_test.rb +273 -0
- data/test/controller/html-scanner/tag_node_test.rb +238 -0
- data/test/controller/html-scanner/text_node_test.rb +50 -0
- data/test/controller/html-scanner/tokenizer_test.rb +131 -0
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +417 -0
- data/test/controller/layout_test.rb +204 -0
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +536 -0
- data/test/controller/mime_type_test.rb +93 -0
- data/test/controller/polymorphic_routes_test.rb +293 -0
- data/test/controller/rack_test.rb +294 -0
- data/test/controller/record_identifier_test.rb +139 -0
- data/test/controller/redirect_test.rb +282 -0
- data/test/controller/render_test.rb +1752 -0
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +246 -0
- data/test/controller/request_test.rb +407 -0
- data/test/controller/rescue_test.rb +536 -0
- data/test/controller/resources_test.rb +1341 -0
- data/test/controller/routing_test.rb +2557 -0
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +161 -0
- data/test/controller/session/cookie_store_test.rb +239 -0
- data/test/controller/session/mem_cache_store_test.rb +127 -0
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +692 -0
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +359 -0
- data/test/controller/verification_test.rb +270 -0
- data/test/controller/view_paths_test.rb +141 -0
- data/test/controller/webservice_test.rb +260 -0
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/company.rb +10 -0
- data/test/fixtures/developer.rb +9 -0
- data/test/fixtures/helpers/abc_helper.rb +5 -0
- data/test/fixtures/helpers/fun/games_helper.rb +3 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/template/asset_tag_helper_test.rb +713 -0
- data/test/template/atom_feed_helper_test.rb +286 -0
- data/test/template/benchmark_helper_test.rb +86 -0
- data/test/template/compiled_templates_test.rb +203 -0
- data/test/template/date_helper_i18n_test.rb +120 -0
- data/test/template/date_helper_test.rb +2469 -0
- data/test/template/erb_util_test.rb +24 -0
- data/test/template/form_helper_test.rb +1176 -0
- data/test/template/form_options_helper_test.rb +751 -0
- data/test/template/form_tag_helper_test.rb +327 -0
- data/test/template/javascript_helper_test.rb +106 -0
- data/test/template/number_helper_i18n_test.rb +69 -0
- data/test/template/number_helper_test.rb +128 -0
- data/test/template/prototype_helper_test.rb +639 -0
- data/test/template/record_tag_helper_test.rb +58 -0
- data/test/template/render_test.rb +291 -0
- data/test/template/sanitize_helper_test.rb +48 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/tag_helper_test.rb +97 -0
- data/test/template/test_test.rb +54 -0
- data/test/template/text_helper_test.rb +520 -0
- data/test/template/translation_helper_test.rb +32 -0
- data/test/template/url_helper_test.rb +614 -0
- data/test/test_erubis_rails_helper.rb +4 -0
- data/test/testing_sandbox.rb +15 -0
- data/test/view/test_case_test.rb +8 -0
- metadata +174 -0
data/README.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= erubis_rails_helper
|
2
|
+
|
3
|
+
* http://github.com/elkinsware/erubis_rails_helper/tree/master
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This is a fix for Erubis integration with Rails 2.3. It is a drop in replacement for the rails helper in the Erubis gem.
|
8
|
+
|
9
|
+
The code makes a few tweaks to the Erubis 2.6.4 Rails Helper along with the Generator class. The main issue with getting
|
10
|
+
Erubis and Rails 2.3 to work together is to replace "_buf" with "@output_buffer" in the generator code. Rails 2.3 relies on
|
11
|
+
for "@output_buffer" to be used in the generated code to make helpers like capture_helper.rb work properly.
|
12
|
+
|
13
|
+
== FEATURES/PROBLEMS:
|
14
|
+
|
15
|
+
* Drop in replacement for the Erubis Rails Helper in the Erubis gem.
|
16
|
+
|
17
|
+
* Using the tests from actionpack-2.3, this passes all but two tests currently. The two failures are because
|
18
|
+
there are two end of line characters instead of one end of line characters. I think that is none critical for
|
19
|
+
the moment.
|
20
|
+
|
21
|
+
== SYNOPSIS:
|
22
|
+
|
23
|
+
inside config/environment.rb and the following
|
24
|
+
config.gem 'erubis' , :version => '2.6.4'
|
25
|
+
config.gem 'elkinsware-erubis_rails_helper', :lib => 'erubis_rails_helper', :source => 'http://gems.github.com'
|
26
|
+
|
27
|
+
#you can customize some of the options for Erubis still if you want to by
|
28
|
+
#add config/initializers/erubis_config.rb
|
29
|
+
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
30
|
+
#Erubis::Helpers::RailsHelper.init_properties = {}
|
31
|
+
Erubis::Helpers::RailsHelper.show_src = false
|
32
|
+
Erubis::Helpers::RailsHelper.preprocessing = true
|
33
|
+
|
34
|
+
== REQUIREMENTS:
|
35
|
+
|
36
|
+
* Rails 2.3
|
37
|
+
* Erubis 2.6.4
|
38
|
+
|
39
|
+
== INSTALL:
|
40
|
+
|
41
|
+
* sudo gem install elkinsware-erubis_rails_helper
|
42
|
+
|
43
|
+
== LICENSE:
|
44
|
+
|
45
|
+
(The MIT License)
|
46
|
+
|
47
|
+
Copyright (c) 2009 Dave Elkins (elkinsware)
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of this software and associated documentation files (the
|
51
|
+
'Software'), to deal in the Software without restriction, including
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
55
|
+
the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be
|
58
|
+
included in all copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
63
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
64
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
65
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
66
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,100 @@
|
|
1
|
+
##
|
2
|
+
## This is a copy of the generator.rb from the Erubis 2.6.4 gem
|
3
|
+
## The modification I made was that you can substitute any variable name (i.e. @output_buffer) for _buf.
|
4
|
+
## This is necessary for Erubis to work with Rails 2.3 and 2.2 because ActionView code like CaptureHelper
|
5
|
+
## relies on @output_buffer to be used and not _buf to work correctly.
|
6
|
+
##
|
7
|
+
|
8
|
+
##
|
9
|
+
## $Rev: 77 $
|
10
|
+
## $Release: 2.6.4 $
|
11
|
+
## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
|
12
|
+
##
|
13
|
+
|
14
|
+
require 'erubis/engine'
|
15
|
+
require 'erubis/enhancer'
|
16
|
+
|
17
|
+
|
18
|
+
module Erubis
|
19
|
+
|
20
|
+
|
21
|
+
##
|
22
|
+
## code generator for Ruby
|
23
|
+
##
|
24
|
+
module RubyGenerator
|
25
|
+
include Generator
|
26
|
+
#include ArrayBufferEnhancer
|
27
|
+
include StringBufferEnhancer
|
28
|
+
|
29
|
+
def init_generator(properties={})
|
30
|
+
super
|
31
|
+
|
32
|
+
@escapefunc ||= "Erubis::XmlHelper.escape_xml"
|
33
|
+
|
34
|
+
set_eoutvar(properties[:eoutvar] || '_buf')
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.supported_properties() # :nodoc:
|
38
|
+
return []
|
39
|
+
end
|
40
|
+
|
41
|
+
def escape_text(text)
|
42
|
+
text.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
|
43
|
+
end
|
44
|
+
|
45
|
+
def escaped_expr(code)
|
46
|
+
return "#{@escapefunc}(#{code})"
|
47
|
+
end
|
48
|
+
|
49
|
+
#--
|
50
|
+
#def add_preamble(src)
|
51
|
+
# src << "_buf = [];"
|
52
|
+
#end
|
53
|
+
#++
|
54
|
+
|
55
|
+
def add_text(src, text)
|
56
|
+
#src << " _buf << '" << escape_text(text) << "';" unless text.empty?
|
57
|
+
src << " #{eoutvar} << '" << escape_text(text) << "';" unless text.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_stmt(src, code)
|
61
|
+
#src << code << ';'
|
62
|
+
src << code
|
63
|
+
src << ';' unless code[-1] == ?\n
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_expr_literal(src, code)
|
67
|
+
#src << ' _buf << (' << code << ').to_s;'
|
68
|
+
src << " #{eoutvar} << (" << code << ").to_s;"
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_expr_escaped(src, code)
|
72
|
+
#src << ' _buf << ' << escaped_expr(code) << ';'
|
73
|
+
src << " #{eoutvar} << " << escaped_expr(code) << ';'
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_expr_debug(src, code)
|
77
|
+
code.strip!
|
78
|
+
s = (code.dump =~ /\A"(.*)"\z/) && $1
|
79
|
+
src << ' $stderr.puts("*** debug: ' << s << '=#{(' << code << ').inspect}");'
|
80
|
+
end
|
81
|
+
|
82
|
+
#--
|
83
|
+
#def add_postamble(src)
|
84
|
+
# src << "\n_buf.join\n"
|
85
|
+
#end
|
86
|
+
#++
|
87
|
+
|
88
|
+
private
|
89
|
+
##
|
90
|
+
## Added to set the buffer variable name. defaults to _buf.
|
91
|
+
##
|
92
|
+
def set_eoutvar(new_eoutvar = '_buf')
|
93
|
+
@eoutvar = new_eoutvar
|
94
|
+
end
|
95
|
+
|
96
|
+
def eoutvar
|
97
|
+
@eoutvar || '_buf'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,260 @@
|
|
1
|
+
module Erubis
|
2
|
+
##
|
3
|
+
## convert "<h1><%=title%></h1>" into "@output_buffer << %Q`<h1>#{title}</h1>`"
|
4
|
+
##
|
5
|
+
## this is only for Eruby.
|
6
|
+
##
|
7
|
+
module InterpolationEnhancer
|
8
|
+
|
9
|
+
def self.desc # :nodoc:
|
10
|
+
"convert '<p><%=text%></p>' into '@output_buffer << %Q`<p>\#{text}</p>`'"
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert_input(src, input)
|
14
|
+
pat = @pattern
|
15
|
+
regexp = pat.nil? || pat == '<% %>' ? Basic::Converter::DEFAULT_REGEXP : pattern_regexp(pat)
|
16
|
+
pos = 0
|
17
|
+
is_bol = true # is beginning of line
|
18
|
+
str = ''
|
19
|
+
input.scan(regexp) do |indicator, code, tailch, rspace|
|
20
|
+
match = Regexp.last_match()
|
21
|
+
len = match.begin(0) - pos
|
22
|
+
text = input[pos, len]
|
23
|
+
pos = match.end(0)
|
24
|
+
ch = indicator ? indicator[0] : nil
|
25
|
+
lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol)
|
26
|
+
is_bol = rspace ? true : false
|
27
|
+
_add_text_to_str(str, text)
|
28
|
+
## * when '<%= %>', do nothing
|
29
|
+
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
30
|
+
if ch == ?= # <%= %>
|
31
|
+
rspace = nil if tailch && !tailch.empty?
|
32
|
+
str << lspace if lspace
|
33
|
+
add_expr(str, code, indicator)
|
34
|
+
str << rspace if rspace
|
35
|
+
elsif ch == ?\# # <%# %>
|
36
|
+
n = code.count("\n") + (rspace ? 1 : 0)
|
37
|
+
if @trim && lspace && rspace
|
38
|
+
add_text(src, str)
|
39
|
+
str = ''
|
40
|
+
add_stmt(src, "\n" * n)
|
41
|
+
else
|
42
|
+
str << lspace if lspace
|
43
|
+
add_text(src, str)
|
44
|
+
str = ''
|
45
|
+
add_stmt(src, "\n" * n)
|
46
|
+
str << rspace if rspace
|
47
|
+
end
|
48
|
+
else # <% %>
|
49
|
+
if @trim && lspace && rspace
|
50
|
+
add_text(src, str)
|
51
|
+
str = ''
|
52
|
+
add_stmt(src, "#{lspace}#{code}#{rspace}")
|
53
|
+
else
|
54
|
+
str << lspace if lspace
|
55
|
+
add_text(src, str)
|
56
|
+
str = ''
|
57
|
+
add_stmt(src, code)
|
58
|
+
str << rspace if rspace
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
#rest = $' || input # ruby1.8
|
63
|
+
rest = pos == 0 ? input : input[pos..-1] # ruby1.9
|
64
|
+
_add_text_to_str(str, rest)
|
65
|
+
add_text(src, str)
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_text(src, text)
|
69
|
+
return if !text || text.empty?
|
70
|
+
#src << " _buf << %Q`" << text << "`;"
|
71
|
+
if text[-1] == ?\n
|
72
|
+
text[-1] = "\\n"
|
73
|
+
src << " @output_buffer << %Q`" << text << "`\n"
|
74
|
+
else
|
75
|
+
src << " @output_buffer << %Q`" << text << "`;"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def _add_text_to_str(str, text)
|
80
|
+
return if !text || text.empty?
|
81
|
+
text.gsub!(/['\#\\]/, '\\\\\&')
|
82
|
+
str << text
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_expr_escaped(str, code)
|
86
|
+
str << "\#{#{escaped_expr(code)}}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_expr_literal(str, code)
|
90
|
+
str << "\#{#{code}}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module OutputBufferEnhancer
|
95
|
+
def self.desc # :nodoc:
|
96
|
+
"set '@output_buffer = _buf = \"\";'"
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_preamble(src)
|
100
|
+
src << "@output_buffer = _buf = '';"
|
101
|
+
end
|
102
|
+
|
103
|
+
def add_postamble(src)
|
104
|
+
src << "\n" unless src[-1] == ?\n
|
105
|
+
src << "@output_buffer.to_s\n"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class Eruby
|
110
|
+
include ::Erubis::PercentLineEnhancer
|
111
|
+
include ::Erubis::DeleteIndentEnhancer
|
112
|
+
include OutputBufferEnhancer
|
113
|
+
end
|
114
|
+
|
115
|
+
class FastEruby
|
116
|
+
include ::Erubis::PercentLineEnhancer
|
117
|
+
include ::Erubis::DeleteIndentEnhancer
|
118
|
+
include OutputBufferEnhancer
|
119
|
+
end
|
120
|
+
|
121
|
+
module Helpers
|
122
|
+
##
|
123
|
+
## helper module for Ruby on Rails
|
124
|
+
##
|
125
|
+
## howto:
|
126
|
+
##
|
127
|
+
## 1. add the folliwng code in your 'config/environment.rb'
|
128
|
+
##
|
129
|
+
## require 'erubis/helpers/rails_helper'
|
130
|
+
## #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
131
|
+
## #Erubis::Helpers::RailsHelper.init_properties = {}
|
132
|
+
## #Erubis::Helpers::RailsHelper.show_src = false # set true for debugging
|
133
|
+
## #Erubis::Helpers::RailsHelper.preprocessing = true # set true to enable preprocessing
|
134
|
+
##
|
135
|
+
## 2. restart web server.
|
136
|
+
##
|
137
|
+
## if Erubis::Helper::Rails.show_src is true, Erubis prints converted Ruby code
|
138
|
+
## into log file ('log/development.log' or so). if false, it doesn't.
|
139
|
+
## if nil, Erubis prints converted Ruby code if ENV['RAILS_ENV'] == 'development'.
|
140
|
+
##
|
141
|
+
module RailsHelper
|
142
|
+
#cattr_accessor :init_properties
|
143
|
+
@@engine_class = ::Erubis::Eruby
|
144
|
+
#@@engine_class = ::Erubis::FastEruby
|
145
|
+
def self.engine_class
|
146
|
+
@@engine_class
|
147
|
+
end
|
148
|
+
def self.engine_class=(klass)
|
149
|
+
@@engine_class = klass
|
150
|
+
end
|
151
|
+
|
152
|
+
#cattr_accessor :init_properties
|
153
|
+
@@init_properties = {}
|
154
|
+
def self.init_properties
|
155
|
+
@@init_properties
|
156
|
+
end
|
157
|
+
def self.init_properties=(hash)
|
158
|
+
@@init_properties = hash
|
159
|
+
end
|
160
|
+
|
161
|
+
#cattr_accessor :show_src
|
162
|
+
@@show_src = nil
|
163
|
+
def self.show_src
|
164
|
+
@@show_src
|
165
|
+
end
|
166
|
+
def self.show_src=(flag)
|
167
|
+
@@show_src = flag
|
168
|
+
end
|
169
|
+
|
170
|
+
#cattr_accessor :preprocessing
|
171
|
+
@@preprocessing = false
|
172
|
+
def self.preprocessing
|
173
|
+
@@preprocessing
|
174
|
+
end
|
175
|
+
def self.preprocessing=(flag)
|
176
|
+
@@preprocessing = flag
|
177
|
+
end
|
178
|
+
|
179
|
+
## define class for backward-compatibility
|
180
|
+
class PreprocessingEruby < Erubis::PreprocessingEruby # :nodoc:
|
181
|
+
end
|
182
|
+
|
183
|
+
module TemplateConverter
|
184
|
+
def _convert_template(template) # :nodoc:
|
185
|
+
|
186
|
+
klass = ::Erubis::Helpers::RailsHelper.engine_class
|
187
|
+
properties = ::Erubis::Helpers::RailsHelper.init_properties || {}
|
188
|
+
|
189
|
+
if preprocess?
|
190
|
+
preprocessor = _create_preprocessor(template)
|
191
|
+
template = preprocessor.evaluate(_preprocessing_context_object())
|
192
|
+
end
|
193
|
+
|
194
|
+
src = klass.new(template, properties.merge(:eoutvar => "@output_buffer")).src
|
195
|
+
return src
|
196
|
+
end
|
197
|
+
|
198
|
+
def _create_preprocessor(template)
|
199
|
+
return PreprocessingEruby.new(template, :escape=>true)
|
200
|
+
end
|
201
|
+
|
202
|
+
def _preprocessing_context_object
|
203
|
+
return self
|
204
|
+
end
|
205
|
+
|
206
|
+
def preprocess?
|
207
|
+
::Erubis::Helpers::RailsHelper.preprocessing
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
class ActionView::Base # :nodoc:
|
215
|
+
include ::Erubis::Helpers::RailsHelper::TemplateConverter
|
216
|
+
include ::Erubis::PreprocessingHelper
|
217
|
+
|
218
|
+
private
|
219
|
+
# convert template into ruby code
|
220
|
+
def convert_template_into_ruby_code(template)
|
221
|
+
#ERB.new(template, nil, @@erb_trim_mode).src
|
222
|
+
return _convert_template(template)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
module ActionView
|
227
|
+
module TemplateHandlers
|
228
|
+
class Erubis < TemplateHandler
|
229
|
+
include Compilable
|
230
|
+
include ::Erubis::Helpers::RailsHelper::TemplateConverter
|
231
|
+
include ::Erubis::PreprocessingHelper
|
232
|
+
|
233
|
+
def compile(template)
|
234
|
+
src = _convert_template("#{template.source}")
|
235
|
+
|
236
|
+
if show_source?
|
237
|
+
logger.debug("** Erubis: src==<<'END'\n#{src}END\n") if logger
|
238
|
+
end
|
239
|
+
|
240
|
+
# Ruby 1.9 prepends an encoding to the source. However this is
|
241
|
+
# useless because you can only set an encoding on the first line
|
242
|
+
RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src
|
243
|
+
end
|
244
|
+
|
245
|
+
protected
|
246
|
+
def logger
|
247
|
+
@logger ||= ActionController::Base.new.logger
|
248
|
+
end
|
249
|
+
|
250
|
+
def show_source?
|
251
|
+
return ::Erubis::Helpers::RailsHelper.show_src if not ::Erubis::Helpers::RailsHelper.show_src.nil?
|
252
|
+
ENV['RAILS_ENV'] == 'development' if ::Erubis::Helpers::RailsHelper.show_src.nil?
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
handler_klass = TemplateHandlers::Erubis
|
257
|
+
Template.register_default_template_handler(:erb, handler_klass)
|
258
|
+
Template.register_template_handler(:rhtml, handler_klass)
|
259
|
+
end
|
260
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
unless defined?(Rails) and defined?(ActionController)
|
2
|
+
$stderr.puts %[This erubis_rails requires actionpack 2.2.2 or higher]
|
3
|
+
end
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'erubis'
|
7
|
+
require 'erubis/preprocessing'
|
8
|
+
rescue LoadError
|
9
|
+
$stderr.puts %[This erubis_rails requires erubis 2.6.4\n
|
10
|
+
Add "config.gem 'erubis', :version => 2.6.4" to config/environment.rb]
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'erubis_rails_helper/erubis/generator'
|
14
|
+
require 'erubis_rails_helper/template_handlers/erubis'
|
15
|
+
|
16
|
+
## finish
|
17
|
+
if defined?(Rails) and defined?(ActionController)
|
18
|
+
ActionController::Base.new.logger.info "** Erubis #{::Erubis::VERSION}"
|
19
|
+
end
|
20
|
+
$stdout.puts "** Erubis #{::Erubis::VERSION}"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
#$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
|
4
|
+
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'yaml'
|
8
|
+
require 'stringio'
|
9
|
+
require 'test/unit'
|
10
|
+
|
11
|
+
gem 'mocha', '>= 0.9.5'
|
12
|
+
require 'mocha'
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'ruby-debug'
|
16
|
+
Debugger.settings[:autoeval] = true
|
17
|
+
Debugger.start
|
18
|
+
rescue LoadError
|
19
|
+
# Debugging disabled. `gem install ruby-debug` to enable.
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'action_controller'
|
23
|
+
require 'action_controller/cgi_ext'
|
24
|
+
require 'action_controller/test_process'
|
25
|
+
require 'action_view/test_case'
|
26
|
+
|
27
|
+
#puts "#{File.dirname(__FILE__) + '/../lib/erubis_rails_helper'}\n"
|
28
|
+
#require File.dirname(__FILE__) + '/../lib/erubis_rails_helper'
|
29
|
+
|
30
|
+
require 'erubis'
|
31
|
+
require 'erubis_rails_helper'
|
32
|
+
|
33
|
+
# Show backtraces for deprecated behavior for quicker cleanup.
|
34
|
+
ActiveSupport::Deprecation.debug = true
|
35
|
+
|
36
|
+
ActionController::Base.logger = nil
|
37
|
+
ActionController::Routing::Routes.reload rescue nil
|
38
|
+
|
39
|
+
ActionController::Base.session_store = nil
|
40
|
+
|
41
|
+
# Register danish language for testing
|
42
|
+
I18n.backend.store_translations 'da', {}
|
43
|
+
I18n.backend.store_translations 'pt-BR', {}
|
44
|
+
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort
|
45
|
+
|
46
|
+
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
47
|
+
ActionView::Base.cache_template_loading = true
|
48
|
+
ActionController::Base.view_paths = FIXTURE_LOAD_PATH
|
49
|
+
CACHED_VIEW_PATHS = ActionView::Base.cache_template_loading? ?
|
50
|
+
ActionController::Base.view_paths :
|
51
|
+
ActionController::Base.view_paths.map {|path| ActionView::Template::EagerPath.new(path.to_s)}
|