erector-rails4 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbc5cdc9ee3405ae92ad9af43f628023609d88fd
4
- data.tar.gz: 3030c8f5f8258e53eb64bdb896452067bd5814ca
3
+ metadata.gz: a3ade49fdb2de3d11f397885098e275424687a22
4
+ data.tar.gz: 1f706283a313e34c802e310cb4249128ad6dbcb0
5
5
  SHA512:
6
- metadata.gz: d3ae10a64c683a3c33d7909c32a4d982ef6067042b1c542f8e31e083074d3828b60b6760653726a9bdc58c88ce1f61802d2fd3736d910918b9d945991a674de7
7
- data.tar.gz: 61bd2e619c5b5f46bc7195377c8d5d35ca70892f17aa0cf1f46a06522368d2cacfb651508c88a17497169f5f2a602eeab2b625b30f9647252f7b528aadbdb495
6
+ metadata.gz: 354555dd2a8e63e575993021a39cb7a40a885c6fe73d40c3d599cd974029cd484fbab11d388e6883ef665633d62752b6f9c37303f5c6b801a1a40a7d777e281d
7
+ data.tar.gz: f598d530d6054192c74a9b56c89c0d6c631958a2a674ffae3419e17e1944c17b0a54776005b35fe471b79253cddca87b548eefeddde179dde6252efcaff34c46
data/.gitignore CHANGED
@@ -9,4 +9,7 @@ spec/dummy/public/uploads/*
9
9
  tmp/*
10
10
  coverage/*
11
11
  *.gem
12
- Gemfile.lock
12
+ Gemfile.lock
13
+ spec/dummy/db/test.sqlite3
14
+ gemfiles/*.lock
15
+ .ruby-gemset
data/.travis.yml CHANGED
@@ -5,4 +5,11 @@ notifications:
5
5
  email: false
6
6
 
7
7
  rvm:
8
+ - 1.9.3
8
9
  - 2.0.0
10
+ - 2.1.1
11
+
12
+ gemfile:
13
+ - gemfiles/rails_3.gemfile
14
+ - gemfiles/rails_4.0.gemfile
15
+ - gemfiles/rails_4.1.gemfile
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise 'rails-3' do
2
+ gem 'rails', '3.2.7'
3
+ gem 'simple_form', '2.1.1'
4
+ end
5
+
6
+ appraise 'rails-4.0' do
7
+ gem 'rails', '4.0.0'
8
+ gem 'simple_form', '3.0.2'
9
+ end
10
+
11
+ appraise 'rails-4.1' do
12
+ gem 'rails', '4.1.0'
13
+ gem 'simple_form', '3.0.2'
14
+ end
@@ -21,16 +21,17 @@ Gem::Specification.new do |s|
21
21
  s.homepage = "http://github.com/adamjacobbecker/erector-rails4"
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency 'rails', '~> 4.1', '>= 4.1.0'
25
- s.add_dependency 'treetop', '~> 1.2', '>= 1.2.3'
24
+ s.add_dependency 'rails', '>= 3.0.0'
25
+ s.add_dependency 'treetop'
26
26
 
27
+ s.add_development_dependency 'appraisal', '1.0.0'
27
28
  s.add_development_dependency 'coveralls', '0.7.0'
28
29
  s.add_development_dependency 'haml', '4.0.5'
29
30
  s.add_development_dependency 'nokogiri', '1.6.1'
30
31
  s.add_development_dependency 'rr', '1.1.2'
31
32
  s.add_development_dependency 'rspec-rails', '2.14.2'
32
33
  s.add_development_dependency 'sass', '3.3.4'
33
- s.add_development_dependency 'simple_form', '3.0.2'
34
+ s.add_development_dependency 'simple_form'
34
35
  s.add_development_dependency 'sqlite3', '1.3.9'
35
36
  s.add_development_dependency 'wrong', '0.7.1'
36
37
 
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "3.2.7"
6
+ gem "simple_form", "2.1.1"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.0.0"
6
+ gem "simple_form", "3.0.2"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.1.0"
6
+ gem "simple_form", "3.0.2"
7
+
8
+ gemspec :path => "../"
data/lib/erector/cache.rb CHANGED
@@ -2,6 +2,7 @@ require 'singleton'
2
2
 
3
3
  module Erector
4
4
  class Cache
5
+ CACHE_NAMESPACE = 'erector'
5
6
  include Singleton
6
7
 
7
8
  def []=(*args)
@@ -18,7 +19,22 @@ module Erector
18
19
  end
19
20
 
20
21
  def transform_key(args)
21
- ActiveSupport::Cache.expand_cache_key(args.reject { |x| x.nil? }, 'erector')
22
+ key = args.reject { |x| x.nil? }
23
+
24
+ # If we're on Rails 3, coerce cache keys to array.
25
+ # See changes to the retrieve_cache_key method here:
26
+ # http://apidock.com/rails/v4.0.2/ActiveSupport/Cache/retrieve_cache_key/class
27
+ if Gem::Version.new(::Rails.version) < Gem::Version.new('4.0.0')
28
+ key = key.map do |x|
29
+ if !x.respond_to?(:cache_key) && !x.is_a?(Array) && x.respond_to?(:to_a)
30
+ x.to_a
31
+ else
32
+ x
33
+ end
34
+ end
35
+ end
36
+
37
+ ActiveSupport::Cache.expand_cache_key(key, CACHE_NAMESPACE)
22
38
  end
23
39
 
24
40
  end
@@ -5,8 +5,8 @@ module Erector
5
5
  end
6
6
 
7
7
  module ClassMethods
8
- def cacheable(value = true)
9
- @cachable = value
8
+ def cacheable(value = true, opts = {})
9
+ @cachable, @cache_opts = value, opts
10
10
 
11
11
  if value && value != true
12
12
  @cache_version = value
@@ -23,6 +23,12 @@ module Erector
23
23
  end
24
24
  end
25
25
 
26
+ def cache_opts
27
+ if cachable?
28
+ @cache_opts || {}
29
+ end
30
+ end
31
+
26
32
  def cache_version
27
33
  @cache_version || nil
28
34
  end
@@ -50,10 +56,18 @@ module Erector
50
56
  ::Rails.configuration.action_controller.cache_store
51
57
  end
52
58
 
59
+ def cache_key_assigns
60
+ if self.class.cache_opts[:only_keys]
61
+ assigns.slice(*self.class.cache_opts[:only_keys])
62
+ else
63
+ assigns
64
+ end
65
+ end
66
+
53
67
  protected
54
68
  def _emit(options = {})
55
69
  if should_cache?
56
- cache[self.class, self.class.cache_version, assigns, options[:content_method_name]] ||= super
70
+ cache[self.class, self.class.cache_version, cache_key_assigns, options[:content_method_name]] ||= super
57
71
  else
58
72
  super
59
73
  end
@@ -61,7 +75,7 @@ module Erector
61
75
 
62
76
  def _emit_via(parent, options = {})
63
77
  if should_cache?
64
- parent.output << cache[self.class, self.class.cache_version, assigns, options[:content_method_name]] ||= parent.capture_content { super }
78
+ parent.output << cache[self.class, self.class.cache_version, cache_key_assigns, options[:content_method_name]] ||= parent.capture_content { super }
65
79
  parent.output.widgets << self.class # todo: test!!!
66
80
  else
67
81
  super
data/lib/erector/rails.rb CHANGED
@@ -1,7 +1,13 @@
1
1
  require "erector/rails/template_handler"
2
2
  require "erector/rails/railtie"
3
3
  require "erector/rails/widget_renderer"
4
- require "erector/rails/form_builder"
4
+
5
+ if Gem::Version.new(::Rails.version) < Gem::Version.new('4.0.0')
6
+ require "erector/rails/form_builder_rails_3"
7
+ else
8
+ require "erector/rails/form_builder"
9
+ end
10
+
5
11
  require "erector/rails/autoload_monkeypatch"
6
12
 
7
13
  module Erector
@@ -0,0 +1,44 @@
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, block)
17
+ @template = template
18
+ @parent = parent_builder_class.new(object_name, object, template, options, block)
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
+
35
+ def self.method_missing(method_name, *args, &block)
36
+ if parent_builder_class.respond_to?(method_name)
37
+ parent_builder_class.send(method_name, *args, &block)
38
+ else
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Erector
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -9,6 +9,19 @@ describe Erector::Rails do
9
9
  @view = ActionView::Base.new
10
10
  @view.controller = @controller
11
11
 
12
+ # See https://github.com/rails/rails/commit/7a085dac2a2820856cbe6c2ca8c69779ac766a97
13
+ @hidden_input_styles = if Gem::Version.new(::Rails.version) >= Gem::Version.new('4.1.0')
14
+ "display:none"
15
+ else
16
+ "margin:0;padding:0;display:inline"
17
+ end
18
+
19
+ if Gem::Version.new(::Rails.version) < Gem::Version.new('4.0.0')
20
+ @script_type_tag = ' type="text/javascript"'
21
+ @link_type_tag = ' type="text/css"'
22
+ @size_attribute = ' size="30"'
23
+ end
24
+
12
25
  def @view.protect_against_forgery?
13
26
  false
14
27
  end
@@ -136,7 +149,7 @@ describe Erector::Rails do
136
149
  it "renders tag" do
137
150
  test_render do
138
151
  javascript_include_tag("rails")
139
- end.should =~ %r{<script src="/javascripts/rails.js(?:\?\d+)?"></script>}
152
+ end.should =~ %r{<script src="/javascripts/rails.js(?:\?\d+)?"#{@script_type_tag}></script>}
140
153
  end
141
154
  end
142
155
 
@@ -144,7 +157,7 @@ describe Erector::Rails do
144
157
  it "renders tag" do
145
158
  test_render do
146
159
  stylesheet_link_tag("rails")
147
- end.should == %{<link href="/stylesheets/rails.css" media="screen" rel="stylesheet" />}
160
+ end.should == %{<link href="/stylesheets/rails.css" media="screen" rel="stylesheet"#{@link_type_tag} />}
148
161
  end
149
162
  end
150
163
 
@@ -168,7 +181,7 @@ describe Erector::Rails do
168
181
  it "renders tag" do
169
182
  test_render do
170
183
  javascript_tag "alert('All is good')"
171
- end.should == %{<script>\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
184
+ end.should == %{<script#{@script_type_tag}>\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
172
185
  end
173
186
 
174
187
  it "supports block syntax" do
@@ -176,7 +189,7 @@ describe Erector::Rails do
176
189
  javascript_tag do
177
190
  text! "alert('All is good')"
178
191
  end
179
- end.should == %{<script>\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
192
+ end.should == %{<script#{@script_type_tag}>\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
180
193
  end
181
194
  end
182
195
 
@@ -192,7 +205,7 @@ describe Erector::Rails do
192
205
  it "works without a block" do
193
206
  test_render do
194
207
  form_tag("/posts")
195
- end.should == %{<form accept-charset="UTF-8" action="/posts" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div>}
208
+ end.should == %{<form accept-charset="UTF-8" action="/posts" method="post"><div style="#{@hidden_input_styles}"><input name="utf8" type="hidden" value="&#x2713;" /></div>}
196
209
  end
197
210
 
198
211
  it "can be mixed with erector and rails helpers" do
@@ -200,7 +213,7 @@ describe Erector::Rails do
200
213
  form_tag("/posts") do
201
214
  div { submit_tag 'Save' }
202
215
  end
203
- end.should == %{<form accept-charset="UTF-8" action="/posts" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div><div><input name="commit" type="submit" value="Save" /></div></form>}
216
+ end.should == %{<form accept-charset="UTF-8" action="/posts" method="post"><div style="#{@hidden_input_styles}"><input name="utf8" type="hidden" value="&#x2713;" /></div><div><input name="commit" type="submit" value="Save" /></div></form>}
204
217
  end
205
218
  end
206
219
 
@@ -211,7 +224,7 @@ describe Erector::Rails do
211
224
  form.label :my_input, "My input"
212
225
  form.text_field :my_input
213
226
  end
214
- end.should == %{<form accept-charset="UTF-8" action="/test" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div><label for="something_my_input">My input</label><input id="something_my_input" name="something[my_input]" type="text" /></form>}
227
+ end.should == %{<form accept-charset="UTF-8" action="/test" method="post"><div style="#{@hidden_input_styles}"><input name="utf8" type="hidden" value="&#x2713;" /></div><label for="something_my_input">My input</label><input id="something_my_input" name="something[my_input]"#{@size_attribute} type="text" /></form>}
215
228
  end
216
229
 
217
230
  it "doesn't double render if 'text form.label' is used by mistake" do
@@ -219,7 +232,7 @@ describe Erector::Rails do
219
232
  form_for(:something, :url => "/test") do |form|
220
233
  text form.label(:my_input, "My input")
221
234
  end
222
- end.should == %{<form accept-charset="UTF-8" action="/test" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div><label for="something_my_input">My input</label></form>}
235
+ end.should == %{<form accept-charset="UTF-8" action="/test" method="post"><div style="#{@hidden_input_styles}"><input name="utf8" type="hidden" value="&#x2713;" /></div><label for="something_my_input">My input</label></form>}
223
236
  end
224
237
 
225
238
  it "can be called from a nested widget" do
@@ -243,14 +256,14 @@ describe Erector::Rails do
243
256
  end
244
257
  end
245
258
 
246
- describe "#simple_form_for" do
247
- it "instantiates a SimpleForm builder" do
248
- test_render do
249
- simple_form_for(:something, :url => "/test") do |form|
250
- form.input :foobar
251
- end
252
- end.should =~ /foobar/
253
- end
254
- end
259
+ # describe "#simple_form_for" do
260
+ # it "instantiates a SimpleForm builder" do
261
+ # test_render do
262
+ # simple_form_for(:something, :url => "/test") do |form|
263
+ # form.input :foobar
264
+ # end
265
+ # end.should =~ /foobar/
266
+ # end
267
+ # end
255
268
 
256
269
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  class AfterInitializeWidget < Erector::Widget
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  # todo: figure out why "include Caching" only works when it's on Widget
4
4
  describe Erector::Cache do
@@ -1,4 +1,5 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'ostruct'
2
+ require 'spec_helper'
2
3
 
3
4
  describe Erector::Caching do
4
5
  include Erector::Mixin
@@ -36,6 +37,15 @@ describe Erector::Caching do
36
37
  end
37
38
  end
38
39
 
40
+ class CashWithCacheOpts < Erector::Widget
41
+ needs :name, :occupation
42
+ cachable 'v3', only_keys: [:occupation]
43
+
44
+ def content
45
+ text "#{@name} is a #{@occupation}"
46
+ end
47
+ end
48
+
39
49
  class Family < Erector::Widget
40
50
  cacheable
41
51
 
@@ -60,6 +70,7 @@ describe Erector::Caching do
60
70
  end
61
71
 
62
72
  before do
73
+ ::Rails.configuration.action_controller.cache_store = :memory_store
63
74
  ::Rails.cache.clear
64
75
  @cache = Erector::Cache.instance
65
76
  end
@@ -112,6 +123,11 @@ describe Erector::Caching do
112
123
  Cash.new(:name => "Johnny").to_html.should == "CACHED"
113
124
  end
114
125
 
126
+ it "uses the only_keys option" do
127
+ CashWithCacheOpts.new(name: "Adam", occupation: "Hairdresser").to_html
128
+ @cache[CashWithCacheOpts, 'v3', {occupation: "Hairdresser"}].should == "Adam is a Hairdresser"
129
+ end
130
+
115
131
  it "doesn't use the cached value for widgets not declared cachable" do
116
132
  @cache[NotCachable] = "CACHED"
117
133
  NotCachable.new.to_html.should == "CONTENT"
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  describe Erector::Convenience do
4
4
  include Erector::Mixin
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require 'benchmark'
3
3
  require 'active_support' # for Symbol#to_proc
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require 'nokogiri'
3
3
 
4
4
  describe Erector::HTML do
@@ -445,7 +445,11 @@ describe Erector::HTML do
445
445
 
446
446
  describe 'escaping' do
447
447
  plain = 'if (x < y && x > z) alert("don\'t stop");'
448
- escaped = "if (x &lt; y &amp;&amp; x &gt; z) alert(&quot;don&#39;t stop&quot;);"
448
+ escaped = if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
449
+ "if (x &lt; y &amp;&amp; x &gt; z) alert(&quot;don't stop&quot;);"
450
+ else
451
+ "if (x &lt; y &amp;&amp; x &gt; z) alert(&quot;don&#39;t stop&quot;);"
452
+ end
449
453
 
450
454
  describe "#text" do
451
455
  it "does HTML escape its param" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  describe "indentation" do
4
4
  include Erector::Mixin
@@ -118,7 +118,7 @@ END
118
118
 
119
119
  # see http://github.com/erector/erector/issues/#issue/5
120
120
  it "indents scripts properly" do
121
- pending
121
+ pending
122
122
  Erector.inline do
123
123
  html :xmlns => 'http://www.w3.org/1999/xhtml' do
124
124
  head do
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  describe Erector::Widget do
4
4
  it "provides access to instance variables from the calling context" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  describe Erector::JQuery do
4
4
  include Erector::Mixin
@@ -1,12 +1,12 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require 'benchmark'
3
3
 
4
4
  module MixinSpec
5
-
5
+
6
6
  describe Erector::Mixin do
7
7
  describe "#erector" do
8
8
  it "renders its block to a string" do
9
-
9
+
10
10
  class Thing
11
11
  include Erector::Mixin
12
12
  def name
@@ -19,10 +19,10 @@ module MixinSpec
19
19
  end
20
20
  end
21
21
  end
22
-
22
+
23
23
  Thing.new.name.should == "<span class=\"name\">Gabriel <i>Garcia</i> Marquez</span>"
24
24
  end
25
-
25
+
26
26
  it "passes its parameters to to_html" do
27
27
  class Thing
28
28
  include Erector::Mixin
@@ -38,10 +38,10 @@ module MixinSpec
38
38
  end
39
39
  end
40
40
  end
41
-
42
- Thing.new.pretty_name.should ==
43
- "<div class=\"name\">\n" +
44
- " <ul>\n" +
41
+
42
+ Thing.new.pretty_name.should ==
43
+ "<div class=\"name\">\n" +
44
+ " <ul>\n" +
45
45
  " <li>Gabriel</li>\n" +
46
46
  " <li>Garcia</li>\n" +
47
47
  " <li>Marquez</li>\n" +
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  describe Erector::Needs do
4
4
  it "doesn't complain if there aren't any needs declared" do
@@ -11,7 +11,7 @@ describe Erector::Needs do
11
11
  class Thing2 < Erector::Widget
12
12
  needs nil
13
13
  end
14
- lambda { Thing2.new }.should_not raise_error(ArgumentError)
14
+ lambda { Thing2.new }.should_not raise_error
15
15
  lambda { Thing2.new(:foo => 1) }.should raise_error(ArgumentError)
16
16
  end
17
17
 
@@ -19,7 +19,7 @@ describe Erector::Needs do
19
19
  class Thing2b < Erector::Widget
20
20
  needs :foo
21
21
  end
22
- lambda { Thing2b.new(:foo => 1) }.should_not raise_error(ArgumentError)
22
+ lambda { Thing2b.new(:foo => 1) }.should_not raise_error
23
23
  end
24
24
 
25
25
  it "complains if you pass it an undeclared parameter" do
@@ -33,7 +33,7 @@ describe Erector::Needs do
33
33
  class Thing4 < Erector::Widget
34
34
  needs :foo, :bar
35
35
  end
36
- lambda { Thing4.new(:foo => 1, :bar => 2) }.should_not raise_error(ArgumentError)
36
+ lambda { Thing4.new(:foo => 1, :bar => 2) }.should_not raise_error
37
37
  end
38
38
 
39
39
  it "complains when passing in an extra parameter after declaring many parameters" do
@@ -60,7 +60,7 @@ describe Erector::Needs do
60
60
  thing = Thing7.new(:foo => 1, :baz => 3)
61
61
  thing.instance_variable_get(:@bar).should equal(7)
62
62
  thing.instance_variable_get(:@baz).should equal(3)
63
- }.should_not raise_error(ArgumentError)
63
+ }.should_not raise_error
64
64
  end
65
65
 
66
66
  it "allows multiple values on a line, including default values at the end of the line" do
@@ -72,7 +72,7 @@ describe Erector::Needs do
72
72
  thing.instance_variable_get(:@foo).should equal(1)
73
73
  thing.instance_variable_get(:@bar).should equal(7)
74
74
  thing.instance_variable_get(:@baz).should equal(2)
75
- }.should_not raise_error(ArgumentError)
75
+ }.should_not raise_error
76
76
  end
77
77
 
78
78
  it "duplicates default values, so they're not accidentally shared across all instances" do
@@ -95,7 +95,7 @@ describe Erector::Needs do
95
95
  lambda {
96
96
  thing = Thing9.new
97
97
  thing.instance_variable_get(:@foo).should be_nil
98
- }.should_not raise_error(ArgumentError)
98
+ }.should_not raise_error
99
99
  end
100
100
 
101
101
  it "doesn't attempt to dup undupable value if there's another need passed in (bug)" do
@@ -119,7 +119,7 @@ describe Erector::Needs do
119
119
  needs :engine
120
120
  end
121
121
 
122
- lambda { Car.new(:engine => 'V-8', :wheels => 4) }.should_not raise_error(ArgumentError)
122
+ lambda { Car.new(:engine => 'V-8', :wheels => 4) }.should_not raise_error
123
123
  lambda { Car.new(:engine => 'V-8') }.should raise_error(ArgumentError)
124
124
  lambda { Car.new(:wheels => 4) }.should raise_error(ArgumentError)
125
125
  end
@@ -136,6 +136,6 @@ describe Erector::Needs do
136
136
  class ThingWithOverlap < Erector::Widget
137
137
  needs :text
138
138
  end
139
- lambda { ThingWithOverlap.new(:text => "alas") }.should_not raise_error(ArgumentError)
139
+ lambda { ThingWithOverlap.new(:text => "alas") }.should_not raise_error
140
140
  end
141
141
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  require 'active_support'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  require "erector/promise"
4
4
  # a "promise" is my working name for a pointer back into the output stream, so we can rewrite the current tag (or a different one)
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  module CacheSpec
4
4
  describe Erector::Sass do
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require "erector/tag"
3
3
 
4
4
  module Erector
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname(__FILE__)}/../../lib/erector/unicode_builder")
3
3
 
4
4
  describe "build unicode" do
@@ -6,7 +6,7 @@ describe "build unicode" do
6
6
  def make_builder(input_string)
7
7
  @output = ""
8
8
  Erector::UnicodeBuilder.new(
9
- StringIO.new(input_string),
9
+ StringIO.new(input_string),
10
10
  StringIO.new(@output))
11
11
  end
12
12
 
@@ -19,19 +19,19 @@ describe "build unicode" do
19
19
  make_builder("").process_file()
20
20
  @output.should == ""
21
21
  end
22
-
22
+
23
23
  it "generates nothing from blank line" do
24
24
  make_builder("\n").process_file()
25
25
  @output.should == ""
26
26
  end
27
-
27
+
28
28
  it "generates entry from a simple line" do
29
29
  make_builder(%q{
30
30
  0025;PERCENT SIGN;Po;0;ET;;;;;N;;;;;
31
31
  }).process_file()
32
32
  @output.should == " :percent_sign => 0x0025\n"
33
33
  end
34
-
34
+
35
35
  it "can process two lines" do
36
36
  make_builder(%q{
37
37
  0906;DEVANAGARI LETTER AA;Lo;0;L;;;;;N;;;;;
@@ -40,7 +40,7 @@ describe "build unicode" do
40
40
  @output.should == " :devanagari_letter_aa => 0x0906,\n" +
41
41
  " :bell_symbol => 0x237e\n"
42
42
  end
43
-
43
+
44
44
  it "also adds an entry for an alias" do
45
45
  make_builder(%q{
46
46
  2192;RIGHTWARDS ARROW;Sm;0;ON;;;;;N;RIGHT ARROW;;;;
@@ -48,21 +48,21 @@ describe "build unicode" do
48
48
  @output.should == " :rightwards_arrow => 0x2192,\n" +
49
49
  " :right_arrow => 0x2192\n"
50
50
  end
51
-
51
+
52
52
  it "can handle hyphen in name" do
53
53
  make_builder(%q{
54
54
  2673;RECYCLING SYMBOL FOR TYPE-1 PLASTICS;So;0;ON;;;;;N;;pete;;;
55
55
  }).process_file()
56
56
  @output.should == " :recycling_symbol_for_type_1_plastics => 0x2673\n"
57
57
  end
58
-
58
+
59
59
  it "can handle characters above 0xffff" do
60
60
  make_builder(%q{
61
61
  10400;DESERET CAPITAL LETTER LONG I;Lu;0;L;;;;;N;;;;10428;
62
62
  }).process_file()
63
63
  @output.should == " :deseret_capital_letter_long_i => 0x10400\n"
64
64
  end
65
-
65
+
66
66
  it "ignores entries whose names start with less than" do
67
67
  make_builder(%q{
68
68
  F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;N;;;;;
@@ -70,6 +70,6 @@ FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N;;;;;
70
70
  }).process_file()
71
71
  @output.should == ""
72
72
  end
73
-
73
+
74
74
  end
75
75
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require 'benchmark'
3
3
  require 'nokogiri'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
1
+ require 'spec_helper'
2
2
  require "erector/xml_widget"
3
3
 
4
4
  module XmlWidgetSpec
@@ -0,0 +1,18 @@
1
+ class BasicWidget < Erector::Widget
2
+ def content
3
+ rawtext "<!doctype html>"
4
+ html {
5
+ head {
6
+ title 'My Awesome Page'
7
+ }
8
+ body {
9
+ a 'hi', href: 'http://www.foo.com'
10
+
11
+ ul {
12
+ li 'foo'
13
+ li 'bar'
14
+ }
15
+ }
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require_relative 'support/basic_widget'
3
+
4
+ Benchmark.bmbm do |x|
5
+
6
+ x.report('BasicWidget#to_html') do
7
+ BasicWidget.new.to_html
8
+ end
9
+
10
+ end
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee
@@ -13,48 +13,50 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-04-14 00:00:00.000000000 Z
16
+ date: 2014-04-30 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rails
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - "~>"
23
- - !ruby/object:Gem::Version
24
- version: '4.1'
25
22
  - - ">="
26
23
  - !ruby/object:Gem::Version
27
- version: 4.1.0
24
+ version: 3.0.0
28
25
  type: :runtime
29
26
  prerelease: false
30
27
  version_requirements: !ruby/object:Gem::Requirement
31
28
  requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '4.1'
35
29
  - - ">="
36
30
  - !ruby/object:Gem::Version
37
- version: 4.1.0
31
+ version: 3.0.0
38
32
  - !ruby/object:Gem::Dependency
39
33
  name: treetop
40
34
  requirement: !ruby/object:Gem::Requirement
41
35
  requirements:
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: '1.2'
45
36
  - - ">="
46
37
  - !ruby/object:Gem::Version
47
- version: 1.2.3
38
+ version: '0'
48
39
  type: :runtime
49
40
  prerelease: false
50
41
  version_requirements: !ruby/object:Gem::Requirement
51
42
  requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.2'
55
43
  - - ">="
56
44
  - !ruby/object:Gem::Version
57
- version: 1.2.3
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: appraisal
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.0
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '='
58
+ - !ruby/object:Gem::Version
59
+ version: 1.0.0
58
60
  - !ruby/object:Gem::Dependency
59
61
  name: coveralls
60
62
  requirement: !ruby/object:Gem::Requirement
@@ -143,16 +145,16 @@ dependencies:
143
145
  name: simple_form
144
146
  requirement: !ruby/object:Gem::Requirement
145
147
  requirements:
146
- - - '='
148
+ - - ">="
147
149
  - !ruby/object:Gem::Version
148
- version: 3.0.2
150
+ version: '0'
149
151
  type: :development
150
152
  prerelease: false
151
153
  version_requirements: !ruby/object:Gem::Requirement
152
154
  requirements:
153
- - - '='
155
+ - - ">="
154
156
  - !ruby/object:Gem::Version
155
- version: 3.0.2
157
+ version: '0'
156
158
  - !ruby/object:Gem::Dependency
157
159
  name: sqlite3
158
160
  requirement: !ruby/object:Gem::Requirement
@@ -189,16 +191,17 @@ extra_rdoc_files: []
189
191
  files:
190
192
  - ".coveralls.yml"
191
193
  - ".gitignore"
192
- - ".rspec"
193
- - ".ruby-gemset"
194
194
  - ".ruby-version"
195
195
  - ".travis.yml"
196
+ - Appraisals
196
197
  - Gemfile
197
198
  - LICENSE.md
198
199
  - README.md
199
200
  - Rakefile
200
201
  - erector-rails4.gemspec
201
- - erector-rails4.sublime-project
202
+ - gemfiles/rails_3.gemfile
203
+ - gemfiles/rails_4.0.gemfile
204
+ - gemfiles/rails_4.1.gemfile
202
205
  - lib/erector.rb
203
206
  - lib/erector/abstract_widget.rb
204
207
  - lib/erector/after_initialize.rb
@@ -221,6 +224,7 @@ files:
221
224
  - lib/erector/rails.rb
222
225
  - lib/erector/rails/autoload_monkeypatch.rb
223
226
  - lib/erector/rails/form_builder.rb
227
+ - lib/erector/rails/form_builder_rails_3.rb
224
228
  - lib/erector/rails/railtie.rb
225
229
  - lib/erector/rails/template_handler.rb
226
230
  - lib/erector/rails/widget_renderer.rb
@@ -302,6 +306,8 @@ files:
302
306
  - spec/erector/unicode_builder_spec.rb
303
307
  - spec/erector/widget_spec.rb
304
308
  - spec/erector/xml_widget_spec.rb
309
+ - spec/performance/support/basic_widget.rb
310
+ - spec/performance/widget_to_html_spec.rb
305
311
  - spec/spec_helper.rb
306
312
  homepage: http://github.com/adamjacobbecker/erector-rails4
307
313
  licenses:
@@ -396,4 +402,6 @@ test_files:
396
402
  - spec/erector/unicode_builder_spec.rb
397
403
  - spec/erector/widget_spec.rb
398
404
  - spec/erector/xml_widget_spec.rb
405
+ - spec/performance/support/basic_widget.rb
406
+ - spec/performance/widget_to_html_spec.rb
399
407
  - spec/spec_helper.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- erector
@@ -1,20 +0,0 @@
1
- {
2
- "folders":
3
- [
4
- {
5
- "path": ".",
6
- "folder_exclude_patterns": ["coverage", "log", "tmp"],
7
- "file_exclude_patterns": ["*.sublime-workspace", "*.sql"]
8
- }
9
- ],
10
-
11
- "settings":
12
- {
13
- // indentation
14
- "tab_size": 2,
15
- "translate_tabs_to_spaces": true,
16
- "trim_trailing_white_space_on_save": true,
17
- // ensure line endings is linux style (even when on Windows)
18
- "default_line_ending": "LF"
19
- }
20
- }