phenomenal_rails 1.0.0 → 1.1.0
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.
- data/README.rdoc +2 -2
- data/lib/phenomenal_rails/engine.rb +2 -1
- data/lib/phenomenal_rails/feature.rb +9 -0
- data/lib/phenomenal_rails/middleware.rb +14 -2
- data/lib/phenomenal_rails/path_set.rb +27 -0
- data/lib/phenomenal_rails/resolver.rb +26 -21
- data/lib/phenomenal_rails/version.rb +1 -1
- data/lib/phenomenal_rails.rb +12 -1
- data/spec/dummy/app/helpers/application_helper.rb +1 -1
- data/spec/dummy/app/views/pages/home.html.haml +6 -1
- data/spec/dummy/log/development.log +4948 -0
- data/spec/dummy/log/production.log +213 -0
- data/spec/dummy/phenomenal/persistent_feature/controllers/application_controller.rb +6 -0
- data/spec/dummy/phenomenal/persistent_feature/models/model.rb +2 -0
- data/spec/dummy/{app/contexts → phenomenal}/persistent_feature/persistent_feature.rb +1 -3
- data/spec/dummy/{app/contexts → phenomenal}/persistent_feature/test_context/test_context.rb +2 -2
- data/spec/dummy/phenomenal/persistent_feature/test_context/views/shared/_partial2.html.haml +1 -0
- metadata +119 -104
- /data/spec/dummy/{app/contexts → phenomenal}/persistent_feature/test_context/views/shared/_partial1.html.haml +0 -0
data/README.rdoc
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
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
|
-
|
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.
|
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
|
@@ -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
|
-
|
14
|
+
before_call(env)
|
9
15
|
@app.call(env)
|
10
16
|
end
|
11
17
|
|
12
|
-
def
|
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::
|
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 =
|
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
|
data/lib/phenomenal_rails.rb
CHANGED
@@ -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}/
|
51
|
+
PhenomenalRails.load_dir("#{Rails.root}/phenomenal")
|
41
52
|
end
|
42
53
|
end
|
43
54
|
end
|