modular 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/Gemfile +4 -0
  2. data/README +0 -0
  3. data/Rakefile +2 -0
  4. data/TODO +2 -0
  5. data/autotest/discover.rb +12 -0
  6. data/lib/generators/component/USAGE +9 -0
  7. data/lib/generators/component/component_generator.rb +16 -0
  8. data/lib/generators/component/templates/component.rb.erb +6 -0
  9. data/lib/generators/component/templates/template.erb +2 -0
  10. data/lib/modular/abstract_model.rb +74 -0
  11. data/lib/modular/caching.rb +62 -0
  12. data/lib/modular/components/base.rb +29 -0
  13. data/lib/modular/components/container.rb +39 -0
  14. data/lib/modular/components/main_content.rb +9 -0
  15. data/lib/modular/configuration.rb +31 -0
  16. data/lib/modular/layout_generator.rb +66 -0
  17. data/lib/modular/rails.rb +16 -0
  18. data/lib/modular/rendering.rb +72 -0
  19. data/lib/modular/version.rb +3 -0
  20. data/lib/modular.rb +57 -0
  21. data/modular-app/Gemfile +20 -0
  22. data/modular-app/Rakefile +7 -0
  23. data/modular-app/app/components/cached_for_time.rb +10 -0
  24. data/modular-app/app/components/cached_forever.rb +10 -0
  25. data/modular-app/app/components/fake_news_feed.rb +9 -0
  26. data/modular-app/app/components/foobar.rb +7 -0
  27. data/modular-app/app/components/heavy_task.rb +5 -0
  28. data/modular-app/app/components/validated.rb +10 -0
  29. data/modular-app/app/components/vertical.rb +4 -0
  30. data/modular-app/app/controllers/application_controller.rb +3 -0
  31. data/modular-app/app/controllers/cached_for_time_controller.rb +7 -0
  32. data/modular-app/app/controllers/cached_forever_controller.rb +6 -0
  33. data/modular-app/app/controllers/callback_layout_controller.rb +11 -0
  34. data/modular-app/app/controllers/example_controller.rb +5 -0
  35. data/modular-app/app/controllers/indirect_render_controller.rb +7 -0
  36. data/modular-app/app/controllers/layout_test_controller.rb +6 -0
  37. data/modular-app/app/helpers/application_helper.rb +2 -0
  38. data/modular-app/app/helpers/callback_layout_helper.rb +2 -0
  39. data/modular-app/app/helpers/example_helper.rb +2 -0
  40. data/modular-app/app/helpers/indirect_render_helper.rb +2 -0
  41. data/modular-app/app/models/simple_model.rb +14 -0
  42. data/modular-app/app/views/cached_for_time/index.html.erb +2 -0
  43. data/modular-app/app/views/cached_forever/index.html.erb +0 -0
  44. data/modular-app/app/views/callback_layout/index.html.erb +2 -0
  45. data/modular-app/app/views/components/cached_for_time.html.erb +2 -0
  46. data/modular-app/app/views/components/cached_forever.html.erb +2 -0
  47. data/modular-app/app/views/components/container.html.erb +7 -0
  48. data/modular-app/app/views/components/fake_news_feed.html.erb +1 -0
  49. data/modular-app/app/views/components/foobar.html.erb +4 -0
  50. data/modular-app/app/views/components/heavy_task.html.erb +1 -0
  51. data/modular-app/app/views/components/validated.html.erb +2 -0
  52. data/modular-app/app/views/components/vertical.html.erb +2 -0
  53. data/modular-app/app/views/example/index.html.erb +2 -0
  54. data/modular-app/app/views/indirect_render/index.html.erb +2 -0
  55. data/modular-app/app/views/layout_test/index.html.erb +1 -0
  56. data/modular-app/app/views/layouts/application.html.erb +16 -0
  57. data/modular-app/config/application.rb +42 -0
  58. data/modular-app/config/boot.rb +6 -0
  59. data/modular-app/config/database.yml +22 -0
  60. data/modular-app/config/environment.rb +5 -0
  61. data/modular-app/config/environments/development.rb +26 -0
  62. data/modular-app/config/environments/production.rb +49 -0
  63. data/modular-app/config/environments/test.rb +35 -0
  64. data/modular-app/config/initializers/backtrace_silencers.rb +7 -0
  65. data/modular-app/config/initializers/inflections.rb +10 -0
  66. data/modular-app/config/initializers/mime_types.rb +5 -0
  67. data/modular-app/config/initializers/modular.rb +20 -0
  68. data/modular-app/config/initializers/secret_token.rb +7 -0
  69. data/modular-app/config/initializers/session_store.rb +8 -0
  70. data/modular-app/config/locales/en.yml +5 -0
  71. data/modular-app/config/routes.rb +7 -0
  72. data/modular-app/config.ru +4 -0
  73. data/modular-app/db/migrate/20110721090602_create_simple_models.rb +12 -0
  74. data/modular-app/db/schema.rb +20 -0
  75. data/modular-app/db/seeds.rb +7 -0
  76. data/modular-app/script/rails +6 -0
  77. data/modular-app/spec/components/base.rb +33 -0
  78. data/modular-app/spec/components/container.rb +34 -0
  79. data/modular-app/spec/components/validated.rb +15 -0
  80. data/modular-app/spec/controllers/cached_for_time_controller_spec.rb +20 -0
  81. data/modular-app/spec/controllers/cached_forever_controller_spec.rb +17 -0
  82. data/modular-app/spec/controllers/callback_layout_controller_spec.rb +12 -0
  83. data/modular-app/spec/controllers/example_controller_spec.rb +12 -0
  84. data/modular-app/spec/controllers/indirect_render_controller_spec.rb +13 -0
  85. data/modular-app/spec/controllers/layout_test_controller_spec.rb +38 -0
  86. data/modular-app/spec/helpers/indirect_render_helper_spec.rb +14 -0
  87. data/modular-app/spec/spec_helper.rb +27 -0
  88. data/modular-app/spec/views/indirect_render/index.html.erb_spec.rb +4 -0
  89. data/modular.gemspec +25 -0
  90. data/spec/base.rb +37 -0
  91. data/spec/configuration.rb +74 -0
  92. data/spec/spec_helper.rb +7 -0
  93. data/templates/layout.erb +17 -0
  94. metadata +202 -0
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe LayoutTestController do
4
+ describe "prerequirements" do
5
+ it "should render itself" do
6
+ Modular.layout(:nested).indirect_render
7
+ end
8
+ end
9
+
10
+ describe "GET 'index'" do
11
+ render_views
12
+
13
+ before :each do
14
+ get 'index'
15
+ end
16
+
17
+ it "should have text from controller" do
18
+ response.body.should contain 'Some text in controller template'
19
+ end
20
+
21
+ it "should have text from layout" do
22
+ response.body.should contain 'Some Text in layout'
23
+ end
24
+
25
+ it "should have text from modular layout" do
26
+ response.body.should contain 'Template - Best news feed'
27
+ end
28
+
29
+ it "should have text from nested modular layout component" do
30
+ response.body.should contain 'Nested component'
31
+ end
32
+
33
+ it "should not be cached" do
34
+ get 'index'
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the IndirectRenderHelper. For example:
5
+ #
6
+ # describe IndirectRenderHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe IndirectRenderHelper do
14
+ end
@@ -0,0 +1,27 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ # == Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+ config.mock_with :rspec
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe "indirect_render/index.html.erb" do
4
+ end
data/modular.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'modular/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "modular"
7
+ s.version = Modular::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Alex Rozumiy"]
10
+ s.email = ["brain-geek@yandex.ua"]
11
+ s.homepage = "http://zn.ua"
12
+ s.summary = %q{This gem provides functionality for modular frontend layout}
13
+ s.description = %q{This gem provides functionality for modular frontend layout}
14
+
15
+ s.rubyforge_project = "modular"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rails"
23
+ s.add_development_dependency "rspec", ">= 2.0.0"
24
+ s.add_development_dependency "autotest"
25
+ end
data/spec/base.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Modular, ' as modular ' do
4
+ it "should fail creating non-existant class" do
5
+ lambda { Modular.create(:fdgasdasdfasdfasdfasdf) }.should raise_error
6
+ end
7
+
8
+ it "should create existant class" do
9
+ cmp = Modular.create(:FakeNewsFeed)
10
+ cmp.should be_a_kind_of Modular::Components::FakeNewsFeed
11
+ end
12
+
13
+ it "should create class from global namespace" do
14
+ cmp = Modular.create(:Foobar)
15
+ cmp.should be_a_kind_of Modular::Components::Base
16
+ cmp.should be_a_kind_of Foobar
17
+ end
18
+
19
+ it "should unserialize components correctly" do
20
+ serialized = Modular.create(:FakeNewsFeed, :news_count => 50, :title => 'Best news feed').to_json
21
+
22
+ cmp_uns = Modular.from_json(serialized)
23
+ cmp_uns.news_count.to_i.should === 50
24
+ cmp_uns.title.should === 'Best news feed'
25
+ end
26
+
27
+ it "should return list of layouts" do
28
+ Modular.configure do
29
+ register_layout :simple_existing, :Container do |layout|
30
+ end
31
+ end
32
+
33
+ Modular.layouts.should be_a_kind_of Array
34
+ Modular.layouts.should include 'simple_existing'
35
+ end
36
+
37
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Modular::Configuration, ' as modular config' do
4
+
5
+ it "should use defaults from config" do
6
+ Modular.configure
7
+
8
+ Modular.config.columns.should_not be nil
9
+ Modular.config.column_width.should_not be nil
10
+ Modular.config.padding_width.should_not be nil
11
+ end
12
+
13
+ it "should be configurable by lambda" do
14
+ Modular.configure do |c|
15
+ c.columns = 99
16
+ c.column_width = 999
17
+ c.padding_width = 9999
18
+ end
19
+
20
+ Modular.config.columns.should === 99
21
+ Modular.config.column_width.should === 999
22
+ Modular.config.padding_width.should === 9999
23
+ end
24
+
25
+ it "should export configuration as json" do
26
+ Modular.configure do |c|
27
+ c.columns = 12
28
+ c.column_width = 100
29
+ c.padding_width = 10
30
+
31
+ end
32
+
33
+ lambda { Modular.config.to_json }.should_not raise_error
34
+
35
+ target = ActiveSupport::JSON::decode(Modular.config.to_json).with_indifferent_access
36
+
37
+ target[:columns].should === 12
38
+ target[:column_width].should === 100
39
+ target[:padding_width].should === 10
40
+ end
41
+
42
+ it "should register layout" do
43
+ component = Modular.create :FakeNewsFeed, :news_count => 50, :title => 'Best news feed'
44
+
45
+ Modular.configure do
46
+ register_layout :simple, component
47
+ end
48
+
49
+ Modular.layout(:simple).to_json == component
50
+ end
51
+
52
+ it "should have DSL for registering layout" do
53
+ Modular.configure do
54
+ register_layout :simple, :Container do
55
+ add :FakeNewsFeed, :title => 'Best news feed'
56
+ add :FakeNewsFeed, :title => 'Just news feed'
57
+
58
+ add :container do
59
+ add :FakeNewsFeed, :title => 'Worst news feed'
60
+ end
61
+ end
62
+ end
63
+
64
+ l = Modular.layout(:simple)
65
+
66
+ l.should be_a_kind_of Modular::Components::Container
67
+
68
+ l.components[0..1].each do |e|
69
+ e.should be_a_kind_of Modular::Components::FakeNewsFeed
70
+ end
71
+ l.components.length.should == 3
72
+ end
73
+
74
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'modular'
4
+
5
+ Dir.glob('modular-app/app/components/*.rb').each {|f| require f }
6
+
7
+ Bundler.require(:default, :development)
@@ -0,0 +1,17 @@
1
+ <%% @layout_id = '<%=@layout_id%>'.to_sym %>
2
+
3
+
4
+
5
+ <% layout = Modular.layout(@layout_id) %>
6
+
7
+ <% if layout.is_a? Modular::Components::IndirectRender %>
8
+ <%= layout.indirect_render %>
9
+ <% else %>
10
+ <%%= Modular.layout('<%=@layout_id%>').render %>
11
+ <% end %>
12
+
13
+ <%%
14
+ layout = 'application'
15
+ @_content_for[:layout] = self.output_buffer
16
+ self.output_buffer = render(:file => "layouts/#{layout}")
17
+ %>
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modular
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Alex Rozumiy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-22 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 15
43
+ segments:
44
+ - 2
45
+ - 0
46
+ - 0
47
+ version: 2.0.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: autotest
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ description: This gem provides functionality for modular frontend layout
65
+ email:
66
+ - brain-geek@yandex.ua
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - Gemfile
75
+ - README
76
+ - Rakefile
77
+ - TODO
78
+ - autotest/discover.rb
79
+ - lib/generators/component/USAGE
80
+ - lib/generators/component/component_generator.rb
81
+ - lib/generators/component/templates/component.rb.erb
82
+ - lib/generators/component/templates/template.erb
83
+ - lib/modular.rb
84
+ - lib/modular/abstract_model.rb
85
+ - lib/modular/caching.rb
86
+ - lib/modular/components/base.rb
87
+ - lib/modular/components/container.rb
88
+ - lib/modular/components/main_content.rb
89
+ - lib/modular/configuration.rb
90
+ - lib/modular/layout_generator.rb
91
+ - lib/modular/rails.rb
92
+ - lib/modular/rendering.rb
93
+ - lib/modular/version.rb
94
+ - modular-app/Gemfile
95
+ - modular-app/Rakefile
96
+ - modular-app/app/components/cached_for_time.rb
97
+ - modular-app/app/components/cached_forever.rb
98
+ - modular-app/app/components/fake_news_feed.rb
99
+ - modular-app/app/components/foobar.rb
100
+ - modular-app/app/components/heavy_task.rb
101
+ - modular-app/app/components/validated.rb
102
+ - modular-app/app/components/vertical.rb
103
+ - modular-app/app/controllers/application_controller.rb
104
+ - modular-app/app/controllers/cached_for_time_controller.rb
105
+ - modular-app/app/controllers/cached_forever_controller.rb
106
+ - modular-app/app/controllers/callback_layout_controller.rb
107
+ - modular-app/app/controllers/example_controller.rb
108
+ - modular-app/app/controllers/indirect_render_controller.rb
109
+ - modular-app/app/controllers/layout_test_controller.rb
110
+ - modular-app/app/helpers/application_helper.rb
111
+ - modular-app/app/helpers/callback_layout_helper.rb
112
+ - modular-app/app/helpers/example_helper.rb
113
+ - modular-app/app/helpers/indirect_render_helper.rb
114
+ - modular-app/app/models/simple_model.rb
115
+ - modular-app/app/views/cached_for_time/index.html.erb
116
+ - modular-app/app/views/cached_forever/index.html.erb
117
+ - modular-app/app/views/callback_layout/index.html.erb
118
+ - modular-app/app/views/components/cached_for_time.html.erb
119
+ - modular-app/app/views/components/cached_forever.html.erb
120
+ - modular-app/app/views/components/container.html.erb
121
+ - modular-app/app/views/components/fake_news_feed.html.erb
122
+ - modular-app/app/views/components/foobar.html.erb
123
+ - modular-app/app/views/components/heavy_task.html.erb
124
+ - modular-app/app/views/components/validated.html.erb
125
+ - modular-app/app/views/components/vertical.html.erb
126
+ - modular-app/app/views/example/index.html.erb
127
+ - modular-app/app/views/indirect_render/index.html.erb
128
+ - modular-app/app/views/layout_test/index.html.erb
129
+ - modular-app/app/views/layouts/application.html.erb
130
+ - modular-app/config.ru
131
+ - modular-app/config/application.rb
132
+ - modular-app/config/boot.rb
133
+ - modular-app/config/database.yml
134
+ - modular-app/config/environment.rb
135
+ - modular-app/config/environments/development.rb
136
+ - modular-app/config/environments/production.rb
137
+ - modular-app/config/environments/test.rb
138
+ - modular-app/config/initializers/backtrace_silencers.rb
139
+ - modular-app/config/initializers/inflections.rb
140
+ - modular-app/config/initializers/mime_types.rb
141
+ - modular-app/config/initializers/modular.rb
142
+ - modular-app/config/initializers/secret_token.rb
143
+ - modular-app/config/initializers/session_store.rb
144
+ - modular-app/config/locales/en.yml
145
+ - modular-app/config/routes.rb
146
+ - modular-app/db/migrate/20110721090602_create_simple_models.rb
147
+ - modular-app/db/schema.rb
148
+ - modular-app/db/seeds.rb
149
+ - modular-app/script/rails
150
+ - modular-app/spec/components/base.rb
151
+ - modular-app/spec/components/container.rb
152
+ - modular-app/spec/components/validated.rb
153
+ - modular-app/spec/controllers/cached_for_time_controller_spec.rb
154
+ - modular-app/spec/controllers/cached_forever_controller_spec.rb
155
+ - modular-app/spec/controllers/callback_layout_controller_spec.rb
156
+ - modular-app/spec/controllers/example_controller_spec.rb
157
+ - modular-app/spec/controllers/indirect_render_controller_spec.rb
158
+ - modular-app/spec/controllers/layout_test_controller_spec.rb
159
+ - modular-app/spec/helpers/indirect_render_helper_spec.rb
160
+ - modular-app/spec/spec_helper.rb
161
+ - modular-app/spec/views/indirect_render/index.html.erb_spec.rb
162
+ - modular.gemspec
163
+ - spec/base.rb
164
+ - spec/configuration.rb
165
+ - spec/spec_helper.rb
166
+ - templates/layout.erb
167
+ has_rdoc: true
168
+ homepage: http://zn.ua
169
+ licenses: []
170
+
171
+ post_install_message:
172
+ rdoc_options: []
173
+
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ requirements: []
195
+
196
+ rubyforge_project: modular
197
+ rubygems_version: 1.5.2
198
+ signing_key:
199
+ specification_version: 3
200
+ summary: This gem provides functionality for modular frontend layout
201
+ test_files: []
202
+