phenomenal_rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,3 +1,3 @@
1
- = PhenomenalRails
1
+ Phenomenal Gem is a context-oriented framework implemented in Ruby that allows context-oriented programming in Ruby and Ruby on Rails applications.
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ See www.phenomenal-gem.com for more details
@@ -3,7 +3,8 @@ module PhenomenalRails
3
3
  isolate_namespace PhenomenalRails
4
4
  config.app_middleware.use(PhenomenalRails::Middleware)
5
5
  config.after_initialize do
6
- ActionController::Base.view_paths.paths.insert(0,Phenomenal::Resolver.instance)
6
+ ActionController::Base.prepend_view_path(Phenomenal::Resolver.instance)
7
+ PhenomenalRails.load_dir("#{Rails.root}/phenomenal")
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,9 @@
1
+ class Phenomenal::Feature
2
+ def self.middleware=(middleware)
3
+ @@middleware=middleware
4
+ end
5
+
6
+ def activation_condition(&block)
7
+ @@middleware.add_condition(self,&block)
8
+ end
9
+ end
@@ -2,14 +2,26 @@ module PhenomenalRails
2
2
  class Middleware
3
3
  def initialize(app)
4
4
  @app=app
5
+ @activation_conditions=Array.new
6
+ Phenomenal::Feature.middleware=self
5
7
  end
6
8
 
9
+ def add_condition(feature,&block)
10
+ @activation_conditions.push([feature,block])
11
+ end
12
+
7
13
  def call(env)
8
- PhenomenalRails::Middleware.activation_handler(env)
14
+ before_call(env)
9
15
  @app.call(env)
10
16
  end
11
17
 
12
- def self.activation_handler(env)
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
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -0,0 +1,27 @@
1
+ #ActionView::LookupContext.register_detail(:feature) {[false]} -> add the details to the options hash
2
+ module ActionView
3
+ class PathSet
4
+ def find(*args)
5
+ templates = find_all(*args)
6
+ if templates.empty?
7
+ if find_all_inactive(*args).empty?
8
+ raise(MissingTemplate.new(self, *args))
9
+ else
10
+ ActionView::Template::Text.new("","text")
11
+ end
12
+ else
13
+ templates.first || raise(MissingTemplate.new(self, *args))
14
+ end
15
+ end
16
+
17
+ private
18
+ def find_all_inactive(path, prefixes = [], *args)
19
+ prefixes = [prefixes] if String === prefixes
20
+ prefixes.each do |prefix|
21
+ templates = paths.find{|p| p.is_a?Phenomenal::Resolver}.find_all_inactive(path, prefix, *args)
22
+ return templates unless templates.empty?
23
+ end
24
+ []
25
+ end
26
+ end
27
+ end
@@ -1,8 +1,32 @@
1
- class Phenomenal::Resolver < ActionView::FileSystemResolver
1
+ class Phenomenal::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 = find_sorted_active_contexts
5
+ contexts = phen_defined_contexts.find_all{|c| c.active?}
6
+ contexts.sort!{|a,b| Phenomenal::Manager.instance.conflict_policy(a,b)}
7
+ find_all_contexts(name,contexts, prefix, partial, details, key, locals)
8
+ end
9
+
10
+ def find_all_inactive(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
11
+ contexts = phen_defined_contexts.find_all{|c| !c.active?}
12
+ find_all_contexts(name,contexts, prefix, partial, details, key, locals)
13
+ end
14
+
15
+ private
16
+ def initialize()
17
+ super("phenomenal")
18
+ @cached={}
19
+ end
20
+
21
+ def cached(template, path, formats)
22
+ if caching?
23
+ @cached[template]||=yield
24
+ else
25
+ yield
26
+ end
27
+ end
28
+
29
+ def find_all_contexts(name,contexts, prefix=nil, partial=false, details={}, key=nil, locals=[])
6
30
  contexts.each do |context|
7
31
  context_path = context.to_path
8
32
  if !context_path.nil?
@@ -36,23 +60,4 @@ class Phenomenal::Resolver < ActionView::FileSystemResolver
36
60
  end
37
61
  }
38
62
  end
39
-
40
- private
41
- def initialize()
42
- super("app/contexts")
43
- @cached={}
44
- end
45
-
46
- def cached(template, path, formats)
47
- if caching?
48
- @cached[template]||=yield
49
- else
50
- yield
51
- end
52
- end
53
-
54
- def find_sorted_active_contexts
55
- contexts = phen_defined_contexts.find_all{|c| c.active?}
56
- contexts.sort!{|a,b| Phenomenal::Manager.instance.conflict_policy(a,b)}
57
- end
58
63
  end
@@ -1,3 +1,3 @@
1
1
  module PhenomenalRails
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,9 +1,11 @@
1
1
  require "phenomenal"
2
2
  require "phenomenal_rails/context"
3
+ require "phenomenal_rails/feature"
3
4
  require "phenomenal_rails/middleware"
4
5
  require "phenomenal_rails/engine"
5
6
  require "singleton"
6
7
  require "phenomenal_rails/resolver"
8
+ require "phenomenal_rails/path_set"
7
9
 
8
10
  # Set default context as persistent
9
11
  phen_default_context.persistent=true
@@ -15,6 +17,15 @@ module PhenomenalRails
15
17
  if entry!="." && entry !=".."
16
18
  filepath=File.join(path,entry)
17
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
18
29
  load filepath
19
30
  elsif File.directory?(filepath)
20
31
  load_dir(filepath)
@@ -37,7 +48,7 @@ module PhenomenalRails
37
48
  end
38
49
  end
39
50
  if !Rails.configuration.cache_classes
40
- PhenomenalRails.load_dir("#{Rails.root}/app/contexts")
51
+ PhenomenalRails.load_dir("#{Rails.root}/phenomenal")
41
52
  end
42
53
  end
43
54
  end
@@ -1,5 +1,5 @@
1
1
  module ApplicationHelper
2
2
  def test
3
- "not adapted helper"
3
+ "Not adapted helper"
4
4
  end
5
5
  end
@@ -1,4 +1,6 @@
1
- %h1 HOME
1
+ %h1
2
+ HOME
3
+ =@test_title
2
4
  %p
3
5
  =test
4
6
  %p
@@ -19,6 +21,9 @@
19
21
  %br
20
22
  =render "shared/partial1"
21
23
  %br
24
+ =render "shared/partial2"
25
+ %br
26
+ %br
22
27
 
23
28
  = ActionController::Base.view_paths.paths
24
29
  %br