modular 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -3
- data/.travis.yml +1 -1
- data/CHANGELOG +8 -0
- data/lib/modular.rb +0 -4
- data/lib/modular/action_controller_extension.rb +5 -5
- data/lib/modular/components/base.rb +4 -1
- data/lib/modular/components/container.rb +14 -0
- data/lib/modular/layout_generator.rb +7 -3
- data/lib/modular/rendering.rb +3 -6
- data/lib/modular/version.rb +1 -1
- data/spec/controllers/layout_test_controller_spec.rb +23 -2
- data/spec/internal/app/models/simple_model.rb +1 -11
- data/spec/internal/config/initializers/modular.rb +0 -4
- data/spec/modular/finders_spec.rb +52 -0
- metadata +6 -15
- data/TODO +0 -3
- data/lib/modular/caching.rb +0 -62
- data/spec/controllers/cached_for_time_controller_spec.rb +0 -20
- data/spec/controllers/cached_forever_controller_spec.rb +0 -17
- data/spec/internal/app/components/cached_for_time.rb +0 -8
- data/spec/internal/app/components/cached_forever.rb +0 -8
- data/spec/internal/app/controllers/cached_for_time_controller.rb +0 -7
- data/spec/internal/app/controllers/cached_forever_controller.rb +0 -6
- data/spec/internal/app/views/cached_for_time/index.html.erb +0 -2
- data/spec/internal/app/views/cached_forever/index.html.erb +0 -0
- data/spec/internal/app/views/indirect_render/index.html.erb +0 -2
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
rvm:
|
1
|
+
rvm:
|
2
2
|
- 1.9.3
|
data/CHANGELOG
ADDED
data/lib/modular.rb
CHANGED
@@ -7,19 +7,19 @@ module Modular::ActionControllerExtension
|
|
7
7
|
|
8
8
|
def get_layout_path(name)
|
9
9
|
if name.is_a?(Symbol)
|
10
|
-
|
11
10
|
name = self.__send__(name)
|
12
11
|
end
|
13
12
|
|
14
|
-
path =
|
15
|
-
|
16
|
-
path
|
13
|
+
path = ::Modular::LayoutGenerator.generate(name)
|
14
|
+
|
15
|
+
#cutting off '.html.erb' and relative path prefix
|
16
|
+
|
17
|
+
"../../../#{path[0, path.length-9]}"
|
17
18
|
end
|
18
19
|
|
19
20
|
module ClassMethods
|
20
21
|
def modular_layout(name)
|
21
22
|
proc = Proc.new do |controller|
|
22
|
-
|
23
23
|
controller.send(:get_layout_path, name)
|
24
24
|
end
|
25
25
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'abstract_controller'
|
2
2
|
require "modular/rendering"
|
3
|
-
require "modular/caching"
|
4
3
|
require 'active_model'
|
5
4
|
|
6
5
|
module Modular
|
@@ -97,6 +96,10 @@ EOF
|
|
97
96
|
valid? #this call is used to make validation calls
|
98
97
|
{ uniqid => errors.to_a }
|
99
98
|
end
|
99
|
+
|
100
|
+
def find_by_uniqid(id)
|
101
|
+
self if id.to_s == uniqid.to_s
|
102
|
+
end
|
100
103
|
end
|
101
104
|
end
|
102
105
|
end
|
@@ -53,6 +53,20 @@ module Modular
|
|
53
53
|
|
54
54
|
errs
|
55
55
|
end
|
56
|
+
def find_by_uniqid(id)
|
57
|
+
id = id.to_s
|
58
|
+
|
59
|
+
result = super
|
60
|
+
|
61
|
+
if result.nil?
|
62
|
+
children.each do |child|
|
63
|
+
result = child.find_by_uniqid(id)
|
64
|
+
return result unless result.nil?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
result
|
69
|
+
end
|
56
70
|
end
|
57
71
|
end
|
58
72
|
end
|
@@ -34,12 +34,16 @@ module Modular
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def filename
|
37
|
-
foldername + (@id.to_s +
|
37
|
+
foldername + (@id.to_s + @params[:cache_key].to_s + '.html.erb')
|
38
|
+
end
|
39
|
+
|
40
|
+
def full_filepath
|
41
|
+
"#{Rails.root}/#{filename}"
|
38
42
|
end
|
39
43
|
|
40
44
|
def layout_exists?
|
41
45
|
if Rails.configuration.action_controller.perform_caching
|
42
|
-
File.exists?(
|
46
|
+
File.exists?(full_filepath)
|
43
47
|
else
|
44
48
|
false
|
45
49
|
end
|
@@ -55,7 +59,7 @@ module Modular
|
|
55
59
|
template = ERB.new File.new(Gem.loaded_specs['modular'].full_gem_path + '/templates/layout.erb').read
|
56
60
|
output = template.result(ERBContext.new(template_variables).get_binding)
|
57
61
|
|
58
|
-
File.open(
|
62
|
+
File.open(full_filepath, 'w') do |f|
|
59
63
|
f.write(output)
|
60
64
|
end
|
61
65
|
end
|
data/lib/modular/rendering.rb
CHANGED
@@ -8,16 +8,13 @@ module Modular::Rendering
|
|
8
8
|
def execute
|
9
9
|
end
|
10
10
|
|
11
|
-
def render
|
11
|
+
def render(args = {})
|
12
12
|
execute
|
13
|
-
|
13
|
+
render_to_string :file => 'components/' + action_name, :locals => args
|
14
14
|
end
|
15
15
|
|
16
16
|
protected
|
17
|
-
|
18
|
-
render_to_string :file => 'components/' + action_name, :locals => args
|
19
|
-
end
|
20
|
-
|
17
|
+
|
21
18
|
module ClassMethods
|
22
19
|
def view_context_class
|
23
20
|
context = super
|
data/lib/modular/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe LayoutTestController do
|
4
|
-
describe "
|
4
|
+
describe "requirements" do
|
5
5
|
it "should render itself" do
|
6
6
|
Modular.layout(:nested).render
|
7
7
|
end
|
@@ -33,6 +33,27 @@ describe LayoutTestController do
|
|
33
33
|
it "should not be cached" do
|
34
34
|
get 'index'
|
35
35
|
end
|
36
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
it "it should not call render twice" do
|
39
|
+
File.unlink("#{Rails.root}/tmp/modular/nested.html.erb") rescue
|
40
|
+
|
41
|
+
Rails.configuration.action_controller.perform_caching = true
|
42
|
+
|
43
|
+
SimpleModel.should_receive(:foobar_method).twice
|
44
|
+
|
45
|
+
get 'index'
|
46
|
+
|
47
|
+
Rails.configuration.action_controller.perform_caching = true
|
48
|
+
|
49
|
+
get 'index'
|
50
|
+
get 'index'
|
51
|
+
|
52
|
+
File.unlink("#{Rails.root}/tmp/modular/nested.html.erb") rescue
|
53
|
+
|
54
|
+
get 'index'
|
55
|
+
|
56
|
+
get 'index'
|
57
|
+
get 'index'
|
37
58
|
end
|
38
59
|
end
|
@@ -18,8 +18,4 @@ Modular.configure do
|
|
18
18
|
add Modular.layout(:mustached)
|
19
19
|
add :mustached, :text => 'Other text from template settings'
|
20
20
|
end
|
21
|
-
|
22
|
-
register_layout :cached_forever, Modular.create(:CachedForever)
|
23
|
-
|
24
|
-
register_layout :cached_for_time, Modular.create(:CachedForTime)
|
25
21
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Modular, ' finders ' do
|
4
|
+
describe "simple objects" do
|
5
|
+
let(:element) { Modular.create(:fake_news_feed, :news_count => 50, :title => 'Best news feed', :uniqid => 'asdf') }
|
6
|
+
|
7
|
+
it "finds itself" do
|
8
|
+
element.find_by_uniqid('asdf').should be element
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does not find itself if id is wrong" do
|
12
|
+
element.find_by_uniqid('qwe').should be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "containers" do
|
17
|
+
let(:element) { Modular.create(:container, :uniqid => 'asdf') }
|
18
|
+
|
19
|
+
it "finds itself" do
|
20
|
+
element.find_by_uniqid('asdf').should be element
|
21
|
+
end
|
22
|
+
|
23
|
+
it "finds itself as symbol" do
|
24
|
+
element.find_by_uniqid(:asdf).should be element
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does not find itself if id is wrong" do
|
28
|
+
element.find_by_uniqid('qwe').should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "finds children in containers" do
|
32
|
+
element.children.push(child = Modular.create(:fake_news_feed, :uniqid => 'gfsd'))
|
33
|
+
element.find_by_uniqid('gfsd').should be child
|
34
|
+
end
|
35
|
+
|
36
|
+
it "finds children in children containers" do
|
37
|
+
element.children.push(child_cont = Modular.create(:container))
|
38
|
+
child_cont.children.push(child = Modular.create(:fake_news_feed, :uniqid => 'gfsd'))
|
39
|
+
|
40
|
+
element.find_by_uniqid('gfsd').should be child
|
41
|
+
end
|
42
|
+
|
43
|
+
it "does not find if nothing to be found" do
|
44
|
+
element.children.push(child = Modular.create(:fake_news_feed, :uniqid => '1'))
|
45
|
+
|
46
|
+
element.children.push(child_cont = Modular.create(:container))
|
47
|
+
child_cont.children.push(child = Modular.create(:fake_news_feed, :uniqid => '2'))
|
48
|
+
|
49
|
+
element.find_by_uniqid('3').should be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -53,15 +53,14 @@ files:
|
|
53
53
|
- .gitignore
|
54
54
|
- .rvmrc
|
55
55
|
- .travis.yml
|
56
|
+
- CHANGELOG
|
56
57
|
- Gemfile
|
57
58
|
- LICENSE
|
58
59
|
- README.rdoc
|
59
60
|
- Rakefile
|
60
|
-
- TODO
|
61
61
|
- config.ru
|
62
62
|
- lib/modular.rb
|
63
63
|
- lib/modular/action_controller_extension.rb
|
64
|
-
- lib/modular/caching.rb
|
65
64
|
- lib/modular/components.rb
|
66
65
|
- lib/modular/components/base.rb
|
67
66
|
- lib/modular/components/container.rb
|
@@ -83,13 +82,9 @@ files:
|
|
83
82
|
- spec/components/hello_world_spec.rb
|
84
83
|
- spec/components/helpers_example_spec.rb
|
85
84
|
- spec/components/spec/internal/log/test.log
|
86
|
-
- spec/controllers/cached_for_time_controller_spec.rb
|
87
|
-
- spec/controllers/cached_forever_controller_spec.rb
|
88
85
|
- spec/controllers/callback_layout_controller_spec.rb
|
89
86
|
- spec/controllers/layout_test_controller_spec.rb
|
90
87
|
- spec/controllers/rendering_spec.rb
|
91
|
-
- spec/internal/app/components/cached_for_time.rb
|
92
|
-
- spec/internal/app/components/cached_forever.rb
|
93
88
|
- spec/internal/app/components/fake_news_feed.rb
|
94
89
|
- spec/internal/app/components/foobar.rb
|
95
90
|
- spec/internal/app/components/hello_world.rb
|
@@ -99,14 +94,10 @@ files:
|
|
99
94
|
- spec/internal/app/components/validated.rb
|
100
95
|
- spec/internal/app/components/vertical.rb
|
101
96
|
- spec/internal/app/controllers/application_controller.rb
|
102
|
-
- spec/internal/app/controllers/cached_for_time_controller.rb
|
103
|
-
- spec/internal/app/controllers/cached_forever_controller.rb
|
104
97
|
- spec/internal/app/controllers/callback_layout_controller.rb
|
105
98
|
- spec/internal/app/controllers/example_controller.rb
|
106
99
|
- spec/internal/app/controllers/layout_test_controller.rb
|
107
100
|
- spec/internal/app/models/simple_model.rb
|
108
|
-
- spec/internal/app/views/cached_for_time/index.html.erb
|
109
|
-
- spec/internal/app/views/cached_forever/index.html.erb
|
110
101
|
- spec/internal/app/views/callback_layout/index.html.erb
|
111
102
|
- spec/internal/app/views/components/cached_for_time.html.erb
|
112
103
|
- spec/internal/app/views/components/cached_forever.html.erb
|
@@ -121,7 +112,6 @@ files:
|
|
121
112
|
- spec/internal/app/views/example/index.html.erb
|
122
113
|
- spec/internal/app/views/example/mustache.html.erb
|
123
114
|
- spec/internal/app/views/example/mustache_nested.html.erb
|
124
|
-
- spec/internal/app/views/indirect_render/index.html.erb
|
125
115
|
- spec/internal/app/views/layout_test/index.html.erb
|
126
116
|
- spec/internal/app/views/layouts/application.html.erb
|
127
117
|
- spec/internal/config/database.yml
|
@@ -133,6 +123,7 @@ files:
|
|
133
123
|
- spec/internal/tmp/.gitkeep
|
134
124
|
- spec/modular/configuration_spec.rb
|
135
125
|
- spec/modular/creation_spec.rb
|
126
|
+
- spec/modular/finders_spec.rb
|
136
127
|
- spec/modular/validation_spec.rb
|
137
128
|
- spec/spec_helper.rb
|
138
129
|
- templates/components/container.html.erb
|
@@ -151,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
142
|
version: '0'
|
152
143
|
segments:
|
153
144
|
- 0
|
154
|
-
hash:
|
145
|
+
hash: 926453680788598348
|
155
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
147
|
none: false
|
157
148
|
requirements:
|
@@ -160,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
151
|
version: '0'
|
161
152
|
segments:
|
162
153
|
- 0
|
163
|
-
hash:
|
154
|
+
hash: 926453680788598348
|
164
155
|
requirements: []
|
165
156
|
rubyforge_project: modular
|
166
157
|
rubygems_version: 1.8.22
|
data/TODO
DELETED
data/lib/modular/caching.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
module Modular
|
2
|
-
module Components
|
3
|
-
module Caching
|
4
|
-
def self.included(base)
|
5
|
-
base.cattr_accessor :cache_options
|
6
|
-
|
7
|
-
base.class_eval do
|
8
|
-
def self.cache(*args, &block)
|
9
|
-
self.cache_options = args.extract_options!
|
10
|
-
self.cache_options[:cache_key] = block if block_given?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def render
|
16
|
-
if cache_options.nil?
|
17
|
-
super
|
18
|
-
elsif cached?
|
19
|
-
get_cached
|
20
|
-
else
|
21
|
-
data = super
|
22
|
-
do_caching data
|
23
|
-
data
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def cache_store
|
28
|
-
::ActionController::Base.cache_store
|
29
|
-
end
|
30
|
-
|
31
|
-
def cache_options
|
32
|
-
self.class.cache_options
|
33
|
-
end
|
34
|
-
|
35
|
-
def clear_cache
|
36
|
-
cache_store.delete cache_key
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
def cache_key
|
41
|
-
key = cache_options[:cache_key]
|
42
|
-
key = key.call(self) if key.is_a? Proc
|
43
|
-
key = self.to_json if key.nil?
|
44
|
-
|
45
|
-
::ActiveSupport::Cache.expand_cache_key key, :modular
|
46
|
-
end
|
47
|
-
|
48
|
-
def cached?
|
49
|
-
cache_store.exist? cache_key
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_cached
|
53
|
-
cache_store.read cache_key
|
54
|
-
end
|
55
|
-
|
56
|
-
def do_caching(data)
|
57
|
-
cache_store.write cache_key, data, cache_options
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CachedForTimeController do
|
4
|
-
render_views
|
5
|
-
|
6
|
-
it "should expire cache" do
|
7
|
-
obj = Modular.layout('cached_for_time')
|
8
|
-
obj.clear_cache
|
9
|
-
SimpleModel.should_receive(:called_by_cached_for_time).once
|
10
|
-
|
11
|
-
get 'index'
|
12
|
-
get 'index'
|
13
|
-
|
14
|
-
sleep 2
|
15
|
-
|
16
|
-
SimpleModel.should_receive(:called_by_cached_for_time).once
|
17
|
-
get 'index'
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CachedForeverController do
|
4
|
-
render_views
|
5
|
-
|
6
|
-
it "should do caching" do
|
7
|
-
Modular.layout('cached_forever').clear_cache
|
8
|
-
SimpleModel.should_receive(:called_by_cached_forever).once
|
9
|
-
|
10
|
-
get 'index'
|
11
|
-
|
12
|
-
Modular.layout('cached_forever').should_receive(:cached?).and_return(true)
|
13
|
-
Modular.layout('cached_forever').should_receive(:get_cached)
|
14
|
-
|
15
|
-
get 'index'
|
16
|
-
end
|
17
|
-
end
|
File without changes
|