modular 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.gitignore +2 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +2 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +155 -0
  6. data/LICENSE +7 -0
  7. data/README.rdoc +21 -0
  8. data/Rakefile +14 -2
  9. data/TODO +3 -2
  10. data/config.ru +7 -0
  11. data/lib/modular.rb +15 -35
  12. data/lib/modular/action_controller_extension.rb +20 -0
  13. data/lib/modular/components.rb +6 -0
  14. data/lib/modular/components/base.rb +9 -7
  15. data/lib/modular/components/container.rb +1 -10
  16. data/lib/modular/components/main_content.rb +1 -3
  17. data/lib/modular/configuration.rb +10 -10
  18. data/lib/modular/creation.rb +29 -0
  19. data/lib/modular/{abstract_model.rb → helpers.rb} +0 -0
  20. data/lib/modular/layout_generator.rb +8 -7
  21. data/lib/modular/railtie.rb +11 -0
  22. data/lib/modular/rendering.rb +68 -73
  23. data/lib/modular/version.rb +1 -1
  24. data/modular.gemspec +0 -1
  25. data/{modular-app/spec → spec}/components/base.rb +0 -0
  26. data/{modular-app/spec → spec}/components/container.rb +3 -3
  27. data/{modular-app/spec → spec}/components/hello_world.rb +0 -0
  28. data/{modular-app/spec → spec}/components/helpers_example.rb +0 -0
  29. data/{modular-app/spec → spec}/components/validated.rb +0 -0
  30. data/{modular-app/spec → spec}/controllers/cached_for_time_controller_spec.rb +0 -0
  31. data/{modular-app/spec → spec}/controllers/cached_forever_controller_spec.rb +0 -0
  32. data/{modular-app/spec → spec}/controllers/callback_layout_controller_spec.rb +0 -0
  33. data/{modular-app/spec → spec}/controllers/example_controller_spec.rb +0 -0
  34. data/{modular-app/spec → spec}/controllers/indirect_render_controller_spec.rb +0 -0
  35. data/{modular-app/spec → spec}/controllers/layout_test_controller_spec.rb +1 -1
  36. data/{modular-app → spec/internal}/app/components/cached_for_time.rb +2 -4
  37. data/spec/internal/app/components/cached_forever.rb +8 -0
  38. data/spec/internal/app/components/fake_news_feed.rb +3 -0
  39. data/{modular-app → spec/internal}/app/components/foobar.rb +0 -0
  40. data/spec/internal/app/components/heavy_task.rb +8 -0
  41. data/{modular-app → spec/internal}/app/components/hello_world.rb +0 -0
  42. data/{modular-app → spec/internal}/app/components/helpers_example.rb +0 -0
  43. data/{modular-app → spec/internal}/app/components/validated.rb +0 -0
  44. data/{modular-app → spec/internal}/app/components/vertical.rb +0 -0
  45. data/{modular-app → spec/internal}/app/controllers/application_controller.rb +0 -0
  46. data/{modular-app → spec/internal}/app/controllers/cached_for_time_controller.rb +0 -0
  47. data/{modular-app → spec/internal}/app/controllers/cached_forever_controller.rb +0 -0
  48. data/{modular-app → spec/internal}/app/controllers/callback_layout_controller.rb +0 -0
  49. data/{modular-app → spec/internal}/app/controllers/example_controller.rb +0 -0
  50. data/{modular-app → spec/internal}/app/controllers/indirect_render_controller.rb +0 -0
  51. data/{modular-app → spec/internal}/app/controllers/layout_test_controller.rb +0 -0
  52. data/{modular-app → spec/internal}/app/models/simple_model.rb +0 -0
  53. data/{modular-app → spec/internal}/app/views/cached_for_time/index.html.erb +0 -0
  54. data/{modular-app → spec/internal}/app/views/cached_forever/index.html.erb +0 -0
  55. data/{modular-app → spec/internal}/app/views/callback_layout/index.html.erb +0 -0
  56. data/{modular-app → spec/internal}/app/views/components/cached_for_time.html.erb +0 -0
  57. data/{modular-app → spec/internal}/app/views/components/cached_forever.html.erb +0 -0
  58. data/{modular-app → spec/internal}/app/views/components/container.html.erb +0 -0
  59. data/{modular-app → spec/internal}/app/views/components/fake_news_feed.html.erb +0 -0
  60. data/{modular-app → spec/internal}/app/views/components/foobar.html.erb +0 -0
  61. data/{modular-app → spec/internal}/app/views/components/heavy_task.html.erb +0 -0
  62. data/{modular-app → spec/internal}/app/views/components/hello_world.html.erb +0 -0
  63. data/{modular-app → spec/internal}/app/views/components/helpers_example.html.erb +0 -0
  64. data/{modular-app → spec/internal}/app/views/components/validated.html.erb +0 -0
  65. data/{modular-app → spec/internal}/app/views/components/vertical.html.erb +0 -0
  66. data/{modular-app → spec/internal}/app/views/example/index.html.erb +0 -0
  67. data/{modular-app → spec/internal}/app/views/indirect_render/index.html.erb +0 -0
  68. data/{modular-app → spec/internal}/app/views/layout_test/index.html.erb +0 -0
  69. data/{modular-app → spec/internal}/app/views/layouts/application.html.erb +0 -0
  70. data/spec/internal/config/database.yml +3 -0
  71. data/{modular-app → spec/internal}/config/initializers/modular.rb +1 -1
  72. data/spec/internal/config/routes.rb +7 -0
  73. data/spec/internal/db/schema.rb +6 -0
  74. data/spec/internal/log/.gitignore +1 -0
  75. data/{README → spec/internal/public/favicon.ico} +0 -0
  76. data/spec/internal/tmp/.gitkeep +0 -0
  77. data/spec/internal/tmp/modular/cached_for_time.html.erb +14 -0
  78. data/spec/internal/tmp/modular/cached_forever.html.erb +12 -0
  79. data/spec/internal/tmp/modular/heavy.html.erb +19 -0
  80. data/spec/internal/tmp/modular/nested.html.erb +28 -0
  81. data/spec/modular/configuration_spec.rb +46 -0
  82. data/spec/{base.rb → modular/creation_spec.rb} +11 -16
  83. data/spec/spec_helper.rb +11 -3
  84. data/spec/views/indirect_render/index.html.erb_spec.rb +4 -0
  85. data/templates/layout.erb +5 -10
  86. metadata +119 -133
  87. data/autotest/discover.rb +0 -12
  88. data/lib/modular/rails.rb +0 -16
  89. data/modular-app/app/components/cached_forever.rb +0 -10
  90. data/modular-app/app/components/fake_news_feed.rb +0 -9
  91. data/modular-app/app/components/heavy_task.rb +0 -5
  92. data/modular-app/app/helpers/application_helper.rb +0 -2
  93. data/modular-app/app/helpers/callback_layout_helper.rb +0 -2
  94. data/modular-app/app/helpers/example_helper.rb +0 -2
  95. data/modular-app/app/helpers/indirect_render_helper.rb +0 -2
  96. data/modular-app/spec/helpers/indirect_render_helper_spec.rb +0 -14
  97. data/modular-app/spec/views/indirect_render/index.html.erb_spec.rb +0 -4
  98. data/spec/configuration.rb +0 -74
data/autotest/discover.rb DELETED
@@ -1,12 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }
2
-
3
- Autotest.add_hook :initialize do |at|
4
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
5
-
6
- filename
7
- }
8
-
9
- %w{.git .svn .hg .DS_Store ._* spec/helpers spec/testdata}.each do |exception|
10
- at.add_exception(exception)
11
- end
12
- end
data/lib/modular/rails.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'action_controller'
2
-
3
- class ActionController::Base
4
- def render_modular_layout(name)
5
- layout = Modular.layout name
6
- render :text => layout.render
7
- end
8
-
9
- def self.modular_layout(name, params = {})
10
- proc = Proc.new do |controller|
11
- '../../../' + Modular.generate_rails_layout(name.is_a?(Symbol) ? controller.__send__(name) : name, params)
12
- end
13
-
14
- layout proc
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- class Modular::Components::CachedForever < Modular::Components::Base
2
- include Modular::Components::Caching
3
- cache
4
-
5
- def execute
6
- SimpleModel.called_by_cached_forever
7
- end
8
- end
9
-
10
- CachedForever = Modular::Components::CachedForever
@@ -1,9 +0,0 @@
1
- module Modular
2
- module Components
3
- class FakeNewsFeed < Modular::Components::Base
4
- attr_reader :news_count
5
- end
6
- end
7
- end
8
-
9
- FakeNewsFeed = Modular::Components::FakeNewsFeed
@@ -1,5 +0,0 @@
1
- class Modular::Components::HeavyTask < Modular::Components::Base
2
- include Modular::Components::IndirectRender
3
- end
4
-
5
- HeavyTask = Modular::Components::HeavyTask
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,2 +0,0 @@
1
- module CallbackLayoutHelper
2
- end
@@ -1,2 +0,0 @@
1
- module ExampleHelper
2
- end
@@ -1,2 +0,0 @@
1
- module IndirectRenderHelper
2
- end
@@ -1,14 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "indirect_render/index.html.erb" do
4
- end
@@ -1,74 +0,0 @@
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