erector-rails4 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 698a798895f015322b464b08fa3fa1ee83921818
4
- data.tar.gz: ab61ab0f8af649554dd0c3b70fbdabe565ef159f
3
+ metadata.gz: cf70db8bc4222c447f5b7d613fd029da5936df19
4
+ data.tar.gz: b584d63e1e6a78cb7ea1da565859e210a42735c3
5
5
  SHA512:
6
- metadata.gz: 9848215dcb48b74b4a39de690d00ddcd5da95f2426c53252fd81390d0032cb460c01df0ec586a8bd5279e3cabdbd77ef35aa63735b36d3dafd091e2f16c3573a
7
- data.tar.gz: ba35747f63989b18c9d248000a20b1e8195923089ac9fe15d4c7b4b71ec40448d1059441b6161c70c9e102bbb8050b92634f4f39b7891da4514f39f529cd7578
6
+ metadata.gz: 09e3d1a72dda9f47c330b52b929c3ba51b95b011929cd72a1b5e6eb2f84d36028842c77da94e48040346e8204e73752f9f273cca7ce137b1d3bd1ce58efb6722
7
+ data.tar.gz: 611d90b3a8949e4fca8ea50d887de30aae31bcb54d505aaab870e6a22b159624c31292854249ebb554cbe2349406c10b8881063ce2ff2f64f1e17cf9ef2992b3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.0-p353
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- erector-rails4 (0.0.1)
4
+ erector-rails4 (0.0.2)
5
5
  rails (>= 4.0)
6
6
  treetop (>= 1.2.3)
7
7
 
data/lib/erector/cache.rb CHANGED
@@ -18,19 +18,7 @@ module Erector
18
18
  end
19
19
 
20
20
  def transform_key(args)
21
- ['erector'] + args.reject { |x| x.nil? }.map { |x|
22
- if x.is_a?(Hash)
23
- transformed = {}
24
-
25
- x.each do |k, v|
26
- transformed[k] = v.respond_to?(:cache_key) ? v.cache_key : v
27
- end
28
-
29
- transformed
30
- else
31
- x
32
- end
33
- }
21
+ ActiveSupport::Cache.expand_cache_key(args.reject { |x| x.nil? }, 'erector')
34
22
  end
35
23
 
36
24
  end
@@ -2,7 +2,7 @@ module Erector
2
2
  def self.inline(*args, &block)
3
3
  InlineWidget.new(*args, &block)
4
4
  end
5
-
5
+
6
6
  module Inline
7
7
  # Executes the widget's block (the one that was passed in the
8
8
  # constructor). Since "self" is pointing to the new widget, the block does
@@ -17,17 +17,6 @@ module Erector
17
17
  # note that instance_eval seems to pass in self as a parameter to the block
18
18
  instance_eval(&block) if block
19
19
  end
20
-
21
- private
22
- # This is part of the sub-widget/parent feature (see #widget method).
23
- def method_missing(name, *args, &block)
24
- if parent && parent.respond_to?(name)
25
- block ||= lambda {} # captures self HERE
26
- parent.send(name, *args, &block)
27
- else
28
- super
29
- end
30
- end
31
20
  end
32
21
 
33
22
  class InlineWidget < Widget
data/lib/erector/rails.rb CHANGED
@@ -43,16 +43,6 @@ module Erector
43
43
  end
44
44
  end
45
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
46
  def def_rails_form_helper(method_name, explicit_builder = nil)
57
47
  module_eval <<-METHOD_DEF, __FILE__, __LINE__+1
58
48
  def #{method_name}(*args, &block)
@@ -130,11 +120,17 @@ module Erector
130
120
  end
131
121
  end
132
122
 
133
- # Delegate to non-markup producing helpers via method_missing,
134
- # returning their result directly.
123
+ # Delegate to both Rails and custom helpers via method_missing,
124
+ # and output return values that are html_safe
135
125
  def method_missing(name, *args, &block)
136
126
  if helpers.respond_to?(name)
137
- helpers.send(name, *args, &block)
127
+ return_value = helpers.send(name, *args, &block)
128
+
129
+ if return_value.try(:html_safe?)
130
+ text return_value
131
+ else
132
+ return_value
133
+ end
138
134
  else
139
135
  super
140
136
  end
@@ -146,72 +142,6 @@ module Erector
146
142
  super || helpers.respond_to?(name)
147
143
  end
148
144
 
149
- [
150
- # UrlHelper
151
- :link_to,
152
- :button_to,
153
- :link_to_unless_current,
154
- :link_to_unless,
155
- :link_to_if,
156
- :mail_to,
157
-
158
- # FormTagHelper
159
- :form_tag,
160
- :select_tag,
161
- :text_field_tag,
162
- :label_tag,
163
- :hidden_field_tag,
164
- :file_field_tag,
165
- :password_field_tag,
166
- :text_area_tag,
167
- :check_box_tag,
168
- :radio_button_tag,
169
- :submit_tag,
170
- :image_submit_tag,
171
- :field_set_tag,
172
-
173
- # FormHelper
174
- :form_for,
175
- :text_field,
176
- :password_field,
177
- :hidden_field,
178
- :file_field,
179
- :text_area,
180
- :check_box,
181
- :radio_button,
182
-
183
- # AssetTagHelper
184
- :auto_discovery_link_tag,
185
- :javascript_include_tag,
186
- :stylesheet_link_tag,
187
- :favicon_link_tag,
188
- :image_tag,
189
-
190
- # ScriptaculousHelper
191
- :sortable_element,
192
- :sortable_element_js,
193
- :text_field_with_auto_complete,
194
- :draggable_element,
195
- :drop_receiving_element,
196
-
197
- # PrototypeHelper
198
- :link_to_remote,
199
- :button_to_remote,
200
- :periodically_call_remote,
201
- :form_remote_tag,
202
- :submit_to_remote,
203
- :update_page_tag,
204
-
205
- # JavaScriptHelper
206
- :javascript_tag,
207
-
208
- # CsrfHelper
209
- :csrf_meta_tag,
210
- :csrf_meta_tags
211
- ].each do |method_name|
212
- def_simple_rails_helper(method_name)
213
- end
214
-
215
145
  [:form_for, :fields_for].each do |method_name|
216
146
  def_rails_form_helper(method_name)
217
147
  end
@@ -1,5 +1,3 @@
1
- # Erector view framework
2
1
  module Erector
3
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
4
3
  end
5
-
@@ -1,7 +1,12 @@
1
1
  module ApplicationHelper
2
2
 
3
- def user_role
3
+ def user_role_unsafe
4
4
  'admin'
5
5
  end
6
6
 
7
+ def user_role_safe
8
+ 'admin'.html_safe
9
+ end
10
+
11
+
7
12
  end
@@ -18,14 +18,46 @@ describe Erector::Rails do
18
18
  Erector::Rails.render(Erector.inline(&block), @controller.view_context)
19
19
  end
20
20
 
21
- describe "a non-output helper" do
21
+ describe "a user-defined non-output helper" do
22
22
  it "does not render to the output buffer" do
23
23
  test_render do
24
- if user_role == 'admin'
24
+ if user_role_unsafe == 'admin'
25
25
  text 'foo'
26
26
  end
27
27
  end.should == %{foo}
28
28
  end
29
+
30
+ it "renders with the text method" do
31
+ test_render do
32
+ text user_role_unsafe
33
+ end.should == %{admin}
34
+ end
35
+
36
+ it "can be combined with a built-in method" do
37
+ test_render do
38
+ link_to user_role_unsafe, user_role_unsafe
39
+ end.should == %{<a href="admin">admin</a>}
40
+ end
41
+ end
42
+
43
+ describe "a helper intended to output" do
44
+ it "renders when called" do
45
+ test_render do
46
+ user_role_safe
47
+ end.should == %{admin}
48
+ end
49
+
50
+ it "cannot be combined directly with a built-in method" do
51
+ test_render do
52
+ image_tag user_role_safe
53
+ end.should == %{admin<img src="" />}
54
+ end
55
+
56
+ it "can be combined with a built-in method by using capture" do
57
+ test_render do
58
+ image_tag capture {user_role_safe}
59
+ end.should == %{<img alt="Admin" src="/images/admin" />}
60
+ end
29
61
  end
30
62
 
31
63
  describe "#link_to" do
@@ -168,20 +200,6 @@ describe Erector::Rails do
168
200
  end
169
201
  end
170
202
 
171
- if defined?(ActionView::Helpers::ScriptaculousHelper)
172
- [:sortable_element,
173
- :draggable_element,
174
- :drop_receiving_element].each do |helper|
175
- describe "##{helper}" do
176
- it "renders helper js" do
177
- test_render do
178
- send(helper, "rails", :url => "/foo")
179
- end.should =~ %r{<script type="text/javascript">.*</script>}m
180
- end
181
- end
182
- end
183
- end
184
-
185
203
  describe "#render" do
186
204
  it "renders text" do
187
205
  test_render do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector-rails4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-12-19 00:00:00.000000000 Z
16
+ date: 2013-12-31 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rails