fortitude 0.0.10 → 0.9.0

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: 8bb4132288b19b7135818f839fdad33953691ae3
4
- data.tar.gz: ec5255b4ff32bc3415f71598b23bd08e234b23c9
3
+ metadata.gz: ef3f1d9ea4fed42b18ff222ae38850effb0f9fae
4
+ data.tar.gz: 555f72bda0961a863c4c418ffe59fbaee11250cd
5
5
  SHA512:
6
- metadata.gz: 3479f4ef5ad1ba1a8bd09eb0a0f22f1359817dc9e60835ec88ffdd4533b3c1a1be0afe2fc643a2879478351dfbd20f02b502e45f197b23dec52e7d8c035bc559
7
- data.tar.gz: 7fed6d1581ab88a136174d0930a576dde5659a53cc6510822da2f0b47dfaf49f24eabbb50c6ca5ad5ee2792a35ee24c11e378e6dca333ad45fc9a9194d79270c
6
+ metadata.gz: e4491a8d9a39112a5ba3b39ae093d2d312eb1507eab816fe13846c7b8d92f4fc4239057f9751ab1019462795d5c19f3994d9ceb56dd9eaf76934be7e41339686
7
+ data.tar.gz: 9308e4d70f1cc45765e731983d02262dbab9988bb59a0092ef78c701196ec2e76a1025331c288ebafaa16ccfa340e0ba8ec1bc19590165e9c413475feff37c5f
data/CHANGES.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Fortitude Releases
2
2
 
3
+ ## 0.9.0, 29 November 2014
4
+
5
+ Updated Fortitude's version number to 0.9.0: at this point, Fortitude should be considered fully production-ready,
6
+ as it is used successfully in multiple very large systems and bug reports are increasingly rare. I don't want to
7
+ release a 1.0 until there's excellent documentation, but the codebase seems to be ready.
8
+
9
+ * Added explicit support for eager-loading Fortitude widget classes under `views/` for Rails applications. This both
10
+ should improve first-run performance of Fortitude-using Rails applications in production, and should avoid an
11
+ occasional problem where Fortitude widget classes were not properly loaded in environments that used eager loading,
12
+ rather than autoloading, for classes.
13
+
3
14
  ## 0.0.10, 25 November 2014
4
15
 
5
16
  * Fixed an issue where `#capture` was not working properly if you rendered a widget using `render :widget =>` in a
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem 'erector'
7
7
  # gem 'erector-rails4', :path => '../erector-rails4'
8
+ gem 'oop_rails_server', :path => '../oop_rails_server'
@@ -17,7 +17,8 @@ else
17
17
  rescue LoadError => le
18
18
  $stderr.puts <<-EOM
19
19
  WARNING: The Fortitude gem cannot load its native extensions. Performance may be reduced by a factor of 3-5x!
20
- Load path: #{$:.inspect}
20
+ Load path:
21
+ #{$:.join("\n ")}
21
22
  Error: #{le.message} (#{le.class})
22
23
  EOM
23
24
  native_loaded = false
@@ -71,6 +71,10 @@ module Fortitude
71
71
  ::ActiveSupport::Dependencies.module_eval do
72
72
  @@_fortitude_views_root = views_root
73
73
 
74
+ def self._fortitude_views_root
75
+ @@_fortitude_views_root
76
+ end
77
+
74
78
  # This is the method that gets called to auto-generate namespacing empty
75
79
  # modules (_e.g._, the toplevel <tt>Views::</tt> module) for directories
76
80
  # under an autoload path.
@@ -176,8 +180,54 @@ module Fortitude
176
180
  alias_method_chain :search_for_file, :fortitude
177
181
  end
178
182
 
183
+ # Two important comments here:
184
+ #
185
+ # 1: We also need to patch ::Rails::Engine.eager_load! so that it loads classes under app/views/. However, we
186
+ # can't just add it to the normal eager load paths, because that will allow people to do "require 'foo/bar'"
187
+ # and have it match app/views/foo/bar.rb, which we don't want. So, instead, we load these classes ourselves.
188
+ # Note that we ALSO have to do things slightly differently than Rails does it, because we need to skip loading
189
+ # 'foo.rb' if 'foo.html.rb' exists -- and because we have to require the fully-qualified pathname, since
190
+ # app/views is not actually on the load path.
191
+ #
192
+ # 2: I (ageweke) added this very late in the path of Fortitude development, after trying to use Fortitude in a
193
+ # deployment (production) environment in which widgets just weren't getting loaded at all. Yet there's something
194
+ # I don't understand: clearly, without this code, widgets will not be eager-loaded (which is probably not a
195
+ # great thing for performance reasons)...but I think they still should get auto-loaded and hence actually work
196
+ # just fine. But they don't in that environment (you'll get errors like "uninitialized constant Views::Base").
197
+ # Since I understand what's going on and have the fix for it here, that's fine...except that I can't seem to
198
+ # write a spec for it, because I don't know how to actually *make* it fail. If anybody comes along later and
199
+ # knows what would make it fail (and I double-checked, and we don't have autoloading disabled in production or
200
+ # anything like that), let me know, so that I can write a spec for this. Thanks!
201
+ ::Rails::Engine.class_eval do
202
+ def eager_load_with_fortitude!
203
+ eager_load_without_fortitude!
204
+ eager_load_fortitude_views!
205
+ end
206
+
207
+ def eager_load_fortitude_views!
208
+ load_path = ::ActiveSupport::Dependencies._fortitude_views_root
209
+ all_files = Dir.glob("#{load_path}/**/*.rb")
210
+ matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
211
+
212
+ all_files.sort.each do |full_path|
213
+ filename = File.basename(full_path, ".rb")
214
+ directory = File.dirname(full_path)
215
+
216
+ longer_name_regex = /^#{Regexp.escape(filename)}\..+\.rb$/i
217
+ longer_name = Dir.entries(directory).detect { |e| e =~ longer_name_regex }
218
+
219
+ unless longer_name
220
+ require_dependency File.join('views', full_path.sub(matcher, '\1'))
221
+ end
222
+ end
223
+ end
224
+
225
+ alias_method_chain :eager_load!, :fortitude
226
+ end
227
+
179
228
  # And, finally, this is where we add our root to the set of autoload paths.
180
229
  ::ActiveSupport::Dependencies.autoload_paths << views_root
230
+ # app.config.eager_load_paths << views_root
181
231
 
182
232
  # This is our support for partials. Fortitude doesn't really have a distinction between
183
233
  # partials and "full" templates -- everything is just a widget, which is much more elegant --
@@ -1,3 +1,3 @@
1
1
  module Fortitude
2
- VERSION = "0.0.10"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -1,11 +1,6 @@
1
1
  describe "Rails class-loading support", :type => :rails do
2
2
  uses_rails_with_template :class_loading_system_spec
3
3
 
4
- it "should not load classes under app/views without the Views:: prefix" do
5
- expect_exception('the_class_should_not_load', 'NameError',
6
- /uninitialized constant ClassLoadingSystemSpec::ClassShouldNotLoad/i)
7
- end
8
-
9
4
  it "should allow me to define classes under Views:: outside of app/views, like in lib/views" do
10
5
  expect_match('lib_views', /hello: i am lib\/views/)
11
6
  end
@@ -53,9 +48,9 @@ describe "Rails class-loading support", :type => :rails do
53
48
  expect_match('bar', /bar WITH html/)
54
49
  end
55
50
 
56
- # it "should not let me define a widget in a file starting with an underscore, and autoload it" do
57
- # expect_exception('underscore_widget', 'NameError', /uninitialized constant Views::ClassLoadingSystemSpec::UnderscoreWidget/)
58
- # end
51
+ it "should let me define a widget in a file starting with an underscore, and autoload it" do
52
+ expect_match('underscore_widget_surrounding', /surrounding_widget before.*this is underscore_widget.*surrounding_widget after/)
53
+ end
59
54
 
60
55
  it "should not let me 'require' files in app/views without a views/ prefix" do
61
56
  expect_exception('require_loaded_underscore_widget_without_views', 'LoadError', /(cannot load such file|no such file to load)/)
@@ -68,4 +63,8 @@ describe "Rails class-loading support", :type => :rails do
68
63
  it "should let me render a widget defined outside of app/views/ if I use render :widget" do
69
64
  expect_match('render_widget_outside_app_views', /arbitrary_name_some_widget/)
70
65
  end
66
+
67
+ it "should not load view classes with any module nesting applied" do
68
+ expect_match('show_module_nesting', /module_nesting: \[\]/)
69
+ end
71
70
  end
@@ -23,6 +23,11 @@ describe "Rails development-mode support", :type => :rails do
23
23
  expect_match("reload_widget_with_html_extension", /with_html_extension.*helper: yo/)
24
24
  end
25
25
 
26
+ it "should not autoload classes that live under views/ but don't start with a Views:: prefix" do
27
+ expect_exception('the_class_should_not_load', 'NameError',
28
+ /uninitialized constant DevelopmentModeSystemSpec::ClassShouldNotLoad/i)
29
+ end
30
+
26
31
  it "should let you change the controller, and that should work fine, too" do
27
32
  expect(rails_server.get("replaced/reload_widget")).to match(/datum\s+one\s+datum/)
28
33
  sleep 1
@@ -1,8 +1,4 @@
1
1
  class ClassLoadingSystemSpecController < ApplicationController
2
- def the_class_should_not_load
3
- render :text => ::ClassLoadingSystemSpec::ClassShouldNotLoad.name
4
- end
5
-
6
2
  def lib_views
7
3
  # nothing here
8
4
  end
@@ -53,6 +49,10 @@ class ClassLoadingSystemSpecController < ApplicationController
53
49
  # nothing here
54
50
  end
55
51
 
52
+ def underscore_widget_surrounding
53
+ # nothing here
54
+ end
55
+
56
56
  def foo
57
57
  # nothing here
58
58
  end
@@ -75,4 +75,8 @@ class ClassLoadingSystemSpecController < ApplicationController
75
75
  require 'arbitrary_name/some_widget'
76
76
  render :widget => ArbitraryName::SomeWidget.new
77
77
  end
78
+
79
+ def show_module_nesting
80
+ # nothing here
81
+ end
78
82
  end
@@ -0,0 +1,7 @@
1
+ $_show_module_nesting = Module.nesting
2
+
3
+ class Views::ClassLoadingSystemSpec::ShowModuleNesting < Fortitude::Widgets::Html5
4
+ def content
5
+ text "module_nesting: #{$_show_module_nesting.inspect}"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Views::ClassLoadingSystemSpec::UnderscoreWidget < Fortitude::Widgets::Html5
2
+ def content
3
+ text "this is underscore_widget"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Views::ClassLoadingSystemSpec::UnderscoreWidgetSurrounding < Fortitude::Widgets::Html5
2
+ def content
3
+ text "surrounding_widget before"
4
+ widget Views::ClassLoadingSystemSpec::UnderscoreWidget
5
+ text "surrounding_widget after"
6
+ end
7
+ end
@@ -1,4 +1,8 @@
1
1
  class DevelopmentModeSystemSpecController < ApplicationController
2
+ def the_class_should_not_load
3
+ render :text => ::DevelopmentModeSystemSpec::ClassShouldNotLoad.name
4
+ end
5
+
2
6
  def reload_widget
3
7
  @datum = "one"
4
8
  end
@@ -1,4 +1,4 @@
1
- module ClassLoadingSystemSpec
1
+ module DevelopmentModeSystemSpec
2
2
  class ClassShouldNotLoad
3
3
  class << self
4
4
  def is_loaded
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortitude
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Geweke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -277,9 +277,11 @@ files:
277
277
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/autoload_one_widget_from_another.rb
278
278
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.html.rb
279
279
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.rb
280
- - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/class_should_not_load.rb
281
280
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/foo.rb
282
281
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/lib_views.rb
282
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/show_module_nesting.rb
283
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget.rb
284
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget_surrounding.rb
283
285
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_lib_widget_from_view_widget.rb
284
286
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_models_widget_from_view_widget.rb
285
287
  - spec/rails/templates/class_loading_system_spec/app/views/some_namespace/some_other_namespace/.git_keep
@@ -340,6 +342,7 @@ files:
340
342
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb
341
343
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb
342
344
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb
345
+ - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/class_should_not_load.rb
343
346
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/form.rb
344
347
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb
345
348
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb
@@ -622,9 +625,11 @@ test_files:
622
625
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/autoload_one_widget_from_another.rb
623
626
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.html.rb
624
627
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.rb
625
- - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/class_should_not_load.rb
626
628
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/foo.rb
627
629
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/lib_views.rb
630
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/show_module_nesting.rb
631
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget.rb
632
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget_surrounding.rb
628
633
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_lib_widget_from_view_widget.rb
629
634
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_models_widget_from_view_widget.rb
630
635
  - spec/rails/templates/class_loading_system_spec/app/views/some_namespace/some_other_namespace/.git_keep
@@ -685,6 +690,7 @@ test_files:
685
690
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb
686
691
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb
687
692
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb
693
+ - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/class_should_not_load.rb
688
694
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/form.rb
689
695
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb
690
696
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb