phenomenal_rails 1.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/lib/phenomenal_rails/context.rb +1 -1
  2. data/lib/phenomenal_rails/engine.rb +20 -13
  3. data/lib/phenomenal_rails/loader.rb +60 -0
  4. data/lib/phenomenal_rails/middleware.rb +20 -22
  5. data/lib/phenomenal_rails/path_set.rb +2 -2
  6. data/lib/phenomenal_rails/resolver.rb +10 -4
  7. data/lib/phenomenal_rails/version.rb +1 -1
  8. data/lib/phenomenal_rails.rb +8 -43
  9. data/spec/dummy/app/views/pages/home.html.haml +3 -2
  10. data/spec/dummy/app/views/shared/_partial4.html.haml +1 -0
  11. data/spec/dummy/{phenomenal → app_phenomenal}/persistent_feature/persistent_feature.rb +2 -0
  12. data/spec/dummy/app_phenomenal/persistent_feature/views/shared/_partial3.html.haml +1 -0
  13. data/spec/dummy/app_phenomenal/test_feature/test_feature.rb +1 -0
  14. data/spec/dummy/app_phenomenal/test_feature/views/shared/_partial4.html.haml +1 -0
  15. data/spec/dummy/config/application.rb +0 -2
  16. data/spec/dummy/log/development.log +156 -7055
  17. metadata +25 -24
  18. data/spec/dummy/db/production.sqlite3 +0 -0
  19. data/spec/dummy/db/test.sqlite3 +0 -0
  20. data/spec/dummy/log/production.log +0 -1348
  21. data/spec/dummy/phenomenal/persistent_feature/controllers/application_controller.rb +0 -6
  22. /data/spec/dummy/{app → app_phenomenal/persistent_feature}/controllers/application_controller.rb +0 -0
  23. /data/spec/dummy/{phenomenal → app_phenomenal}/persistent_feature/models/model.rb +0 -0
  24. /data/spec/dummy/{phenomenal → app_phenomenal}/persistent_feature/test_context/test_context.rb +0 -0
  25. /data/spec/dummy/{phenomenal → app_phenomenal}/persistent_feature/test_context/views/shared/_partial1.html.haml +0 -0
  26. /data/spec/dummy/{phenomenal → app_phenomenal}/persistent_feature/test_context/views/shared/_partial2.html.haml +0 -0
@@ -11,7 +11,7 @@ class Phenomenal::Context
11
11
  def to_path
12
12
  if name
13
13
  name.to_s.underscore
14
- elsif self==manager.default_context
14
+ elsif self==manager.default_feature
15
15
  nil
16
16
  elsif manager.combined_contexts[self]
17
17
  manager.combined_contexts[self].flatten.join("/").underscore
@@ -1,13 +1,20 @@
1
- module PhenomenalRails
2
- class Engine < Rails::Engine
3
- isolate_namespace PhenomenalRails
4
- config.app_middleware.use(PhenomenalRails::Middleware)
5
- config.after_initialize do
6
- ActionController::Base.prepend_view_path(Phenomenal::Resolver.instance)
7
- PhenomenalRails.load_dir("#{Rails.root}/phenomenal")
8
- end
9
- end
10
- end
11
-
12
-
13
-
1
+ class PhenomenalRails::Engine < Rails::Engine
2
+ isolate_namespace PhenomenalRails
3
+ config.app_middleware.use(PhenomenalRails::Middleware)
4
+
5
+ config.before_configuration do
6
+ Rails.configuration.autoload_paths += PhenomenalRails::Loader.autoload_paths(File.expand_path(PhenomenalRails::PATH,Rails.root))
7
+ end
8
+
9
+ config.to_prepare do
10
+ PhenomenalRails::Loader.prepare(true)
11
+ end
12
+
13
+ config.after_initialize do
14
+ ActionController::Base.prepend_view_path(PhenomenalRails::Resolver.instance)
15
+ end
16
+
17
+ ActionDispatch::Callbacks.before do |*args|
18
+ PhenomenalRails::Loader.prepare
19
+ end
20
+ end
@@ -0,0 +1,60 @@
1
+ class PhenomenalRails::Loader
2
+ class << self
3
+ def autoload_paths(path,paths=[])
4
+ scan_dir(path) do |filepath, entry|
5
+ if File.directory?(filepath)
6
+ if (filepath.match(/.*\/controllers/) ||
7
+ filepath.match(/.*\/models/) ||
8
+ filepath.match(/.*\/helpers/))
9
+ paths.push(filepath)
10
+ end
11
+ autoload_paths(filepath,paths)
12
+ end
13
+ end
14
+ paths
15
+ end
16
+
17
+ def prepare(loading=false)
18
+ phen_defined_contexts.reverse.each do |context|
19
+ if !context.forgotten && (!context.persistent || !Rails.configuration.cache_classes)
20
+ while phen_context_active?(context) do
21
+ phen_deactivate_context(context)
22
+ end
23
+ if !Rails.configuration.cache_classes
24
+ phen_forget_context(context)
25
+ end
26
+ end
27
+ end
28
+
29
+ if !Rails.configuration.cache_classes || loading
30
+ load_files(File.expand_path(PhenomenalRails::PATH,Rails.root))
31
+ end
32
+ end
33
+
34
+ private
35
+ def scan_dir(path, &block)
36
+ if Dir.exist? path
37
+ Dir.entries(path).each do |entry|
38
+ if entry!="." && entry !=".."
39
+ filepath=File.join(path,entry)
40
+ yield(filepath, entry)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def load_files(path)
47
+ scan_dir(path) do |filepath, entry|
48
+ if File.file?(filepath) && entry.match(/.*\.rb/)
49
+ load filepath
50
+ elsif File.directory?(filepath)
51
+ if !(filepath.match(/.*\/controllers/) ||
52
+ filepath.match(/.*\/models/) ||
53
+ filepath.match(/.*\/helpers/))
54
+ load_files(filepath)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,26 +1,24 @@
1
- module PhenomenalRails
2
- class Middleware
3
- def initialize(app)
4
- @app=app
5
- @activation_conditions=Array.new
6
- Phenomenal::Feature.middleware=self
7
- end
8
-
9
- def add_condition(feature,&block)
10
- @activation_conditions.push([feature,block])
11
- end
1
+ class PhenomenalRails::Middleware
2
+ def initialize(app)
3
+ @app=app
4
+ @activation_conditions=Array.new
5
+ Phenomenal::Feature.middleware=self
6
+ end
7
+
8
+ def add_condition(feature,&block)
9
+ @activation_conditions.push([feature,block])
10
+ end
12
11
 
13
- def call(env)
14
- before_call(env)
15
- @app.call(env)
16
- end
17
-
18
- def before_call(env)
19
- @activation_conditions.each do |feature_block|
20
- feature,block = feature_block
21
- if feature.active?
22
- block.call(env)
23
- end
12
+ def call(env)
13
+ before_call(env)
14
+ @app.call(env)
15
+ end
16
+
17
+ def before_call(env)
18
+ @activation_conditions.each do |feature_block|
19
+ feature,block = feature_block
20
+ if feature.active?
21
+ block.call(env)
24
22
  end
25
23
  end
26
24
  end
@@ -1,4 +1,4 @@
1
- #ActionView::LookupContext.register_detail(:feature) {[false]} -> add the details to the options hash
1
+ ActionView::LookupContext.register_detail(:feature) {[]} #-> add the details to the options hash
2
2
  module ActionView
3
3
  class PathSet
4
4
  def find(*args)
@@ -18,7 +18,7 @@ module ActionView
18
18
  def find_all_inactive(path, prefixes = [], *args)
19
19
  prefixes = [prefixes] if String === prefixes
20
20
  prefixes.each do |prefix|
21
- templates = paths.find{|p| p.is_a?Phenomenal::Resolver}.find_all_inactive(path, prefix, *args)
21
+ templates = paths.find{|p| p.is_a?PhenomenalRails::Resolver}.find_all_inactive(path, prefix, *args)
22
22
  return templates unless templates.empty?
23
23
  end
24
24
  []
@@ -1,20 +1,26 @@
1
- class Phenomenal::Resolver < ActionView::OptimizedFileSystemResolver
1
+ class PhenomenalRails::Resolver < ActionView::OptimizedFileSystemResolver
2
2
  include Singleton
3
3
 
4
4
  def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
5
- contexts = phen_defined_contexts.find_all{|c| c.active?}
5
+ contexts = phen_defined_contexts.find_all do |c|
6
+ c.active? &&
7
+ (details[:feature].empty? ? true : c==feature(*details[:feature]))
8
+ end
6
9
  contexts.sort!{|a,b| Phenomenal::Manager.instance.conflict_policy(a,b)}
7
10
  find_all_contexts(name,contexts, prefix, partial, details, key, locals)
8
11
  end
9
12
 
10
13
  def find_all_inactive(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
11
- contexts = phen_defined_contexts.find_all{|c| !c.active?}
14
+ contexts = phen_defined_contexts.find_all do |c|
15
+ !c.active? &&
16
+ (details[:feature].empty? ? true : c==feature(*details[:feature]))
17
+ end
12
18
  find_all_contexts(name,contexts, prefix, partial, details, key, locals)
13
19
  end
14
20
 
15
21
  private
16
22
  def initialize()
17
- super("phenomenal")
23
+ super(PhenomenalRails::PATH)
18
24
  @cached={}
19
25
  end
20
26
 
@@ -1,3 +1,3 @@
1
1
  module PhenomenalRails
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -1,4 +1,6 @@
1
+
1
2
  require "phenomenal"
3
+ require "phenomenal_rails/loader"
2
4
  require "phenomenal_rails/context"
3
5
  require "phenomenal_rails/feature"
4
6
  require "phenomenal_rails/middleware"
@@ -7,48 +9,11 @@ require "singleton"
7
9
  require "phenomenal_rails/resolver"
8
10
  require "phenomenal_rails/path_set"
9
11
 
10
- # Set default context as persistent
11
- phen_default_context.persistent=true
12
+ # Set default feature as persistent
13
+ phen_default_feature.persistent=true
14
+
12
15
 
13
- module PhenomenalRails
14
- def self.load_dir(path)
15
- if Dir.exist? path
16
- Dir.entries(path).each do |entry|
17
- if entry!="." && entry !=".."
18
- filepath=File.join(path,entry)
19
- if File.file?(filepath) && entry.match(/.*\.rb/)
20
- if !Rails.configuration.cache_classes &&
21
- (path.match(/.*\/controllers/) ||
22
- path.match(/.*\/models/) ||
23
- path.match(/.*\/helpers/))
24
- begin
25
- entry.gsub(/.rb/,"").camelize.constantize
26
- rescue
27
- end
28
- end
29
- load filepath
30
- elsif File.directory?(filepath)
31
- load_dir(filepath)
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- ActionDispatch::Callbacks.before do
39
- phen_defined_contexts.reverse.each do |context|
40
- if !context.forgotten && (!context.persistent || !Rails.configuration.cache_classes)
41
- while phen_context_active?(context) do
42
- phen_deactivate_context(context)
43
- end
44
- # Fix problem without page caching
45
- if !Rails.configuration.cache_classes
46
- phen_forget_context(context)
47
- end
48
- end
49
- end
50
- if !Rails.configuration.cache_classes
51
- PhenomenalRails.load_dir("#{Rails.root}/phenomenal")
52
- end
53
- end
16
+ module PhenomenalRails
17
+ # Phenomenal application folder
18
+ PATH = "app_phenomenal"
54
19
  end
@@ -19,12 +19,13 @@
19
19
  %td=context.active?
20
20
 
21
21
  %br
22
- =render "shared/partial1"
22
+ =render :partial=>"shared/partial1"
23
23
  %br
24
24
  =render "shared/partial2"
25
25
  %br
26
+ =render :partial=>"shared/partial3",:feature=>[:PersistentFeature]
26
27
  %br
27
-
28
+ =render :partial=>"shared/partial4"
28
29
  = ActionController::Base.view_paths.paths
29
30
  %br
30
31
  %br
@@ -0,0 +1 @@
1
+ PARIAL 4 base
@@ -3,8 +3,10 @@ feature :PersistentFeature do
3
3
  activation_condition do |env|
4
4
  if Rack::Request.new(env).params["activated"]
5
5
  activate_context :TestContext
6
+ activate_context :TestFeature
6
7
  else
7
8
  deactivate_context :TestContext
9
+ deactivate_context :TestFeature
8
10
  end
9
11
  end
10
12
  end
@@ -0,0 +1 @@
1
+ Persistent feature only partial
@@ -0,0 +1 @@
1
+ feature :TestFeature
@@ -0,0 +1 @@
1
+ PARTIAL 4 TEST FEATURE
@@ -14,8 +14,6 @@ module Dummy
14
14
 
15
15
  # Custom directories with classes and modules you want to be autoloadable.
16
16
  # config.autoload_paths += %W(#{config.root}/extras)
17
- config.autoload_paths += %W(#{config.root}/app/contexts )
18
-
19
17
 
20
18
  # Only load the plugins named here, in the order given (default is alphabetical).
21
19
  # :all can be used as a placeholder for all plugins not explicitly named.