modular 0.1.2 → 0.2.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/.gitignore +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +2 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +155 -0
- data/LICENSE +7 -0
- data/README.rdoc +21 -0
- data/Rakefile +14 -2
- data/TODO +3 -2
- data/config.ru +7 -0
- data/lib/modular.rb +15 -35
- data/lib/modular/action_controller_extension.rb +20 -0
- data/lib/modular/components.rb +6 -0
- data/lib/modular/components/base.rb +9 -7
- data/lib/modular/components/container.rb +1 -10
- data/lib/modular/components/main_content.rb +1 -3
- data/lib/modular/configuration.rb +10 -10
- data/lib/modular/creation.rb +29 -0
- data/lib/modular/{abstract_model.rb → helpers.rb} +0 -0
- data/lib/modular/layout_generator.rb +8 -7
- data/lib/modular/railtie.rb +11 -0
- data/lib/modular/rendering.rb +68 -73
- data/lib/modular/version.rb +1 -1
- data/modular.gemspec +0 -1
- data/{modular-app/spec → spec}/components/base.rb +0 -0
- data/{modular-app/spec → spec}/components/container.rb +3 -3
- data/{modular-app/spec → spec}/components/hello_world.rb +0 -0
- data/{modular-app/spec → spec}/components/helpers_example.rb +0 -0
- data/{modular-app/spec → spec}/components/validated.rb +0 -0
- data/{modular-app/spec → spec}/controllers/cached_for_time_controller_spec.rb +0 -0
- data/{modular-app/spec → spec}/controllers/cached_forever_controller_spec.rb +0 -0
- data/{modular-app/spec → spec}/controllers/callback_layout_controller_spec.rb +0 -0
- data/{modular-app/spec → spec}/controllers/example_controller_spec.rb +0 -0
- data/{modular-app/spec → spec}/controllers/indirect_render_controller_spec.rb +0 -0
- data/{modular-app/spec → spec}/controllers/layout_test_controller_spec.rb +1 -1
- data/{modular-app → spec/internal}/app/components/cached_for_time.rb +2 -4
- data/spec/internal/app/components/cached_forever.rb +8 -0
- data/spec/internal/app/components/fake_news_feed.rb +3 -0
- data/{modular-app → spec/internal}/app/components/foobar.rb +0 -0
- data/spec/internal/app/components/heavy_task.rb +8 -0
- data/{modular-app → spec/internal}/app/components/hello_world.rb +0 -0
- data/{modular-app → spec/internal}/app/components/helpers_example.rb +0 -0
- data/{modular-app → spec/internal}/app/components/validated.rb +0 -0
- data/{modular-app → spec/internal}/app/components/vertical.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/application_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/cached_for_time_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/cached_forever_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/callback_layout_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/example_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/indirect_render_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/controllers/layout_test_controller.rb +0 -0
- data/{modular-app → spec/internal}/app/models/simple_model.rb +0 -0
- data/{modular-app → spec/internal}/app/views/cached_for_time/index.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/cached_forever/index.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/callback_layout/index.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/cached_for_time.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/cached_forever.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/container.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/fake_news_feed.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/foobar.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/heavy_task.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/hello_world.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/helpers_example.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/validated.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/components/vertical.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/example/index.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/indirect_render/index.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/layout_test/index.html.erb +0 -0
- data/{modular-app → spec/internal}/app/views/layouts/application.html.erb +0 -0
- data/spec/internal/config/database.yml +3 -0
- data/{modular-app → spec/internal}/config/initializers/modular.rb +1 -1
- data/spec/internal/config/routes.rb +7 -0
- data/spec/internal/db/schema.rb +6 -0
- data/spec/internal/log/.gitignore +1 -0
- data/{README → spec/internal/public/favicon.ico} +0 -0
- data/spec/internal/tmp/.gitkeep +0 -0
- data/spec/internal/tmp/modular/cached_for_time.html.erb +14 -0
- data/spec/internal/tmp/modular/cached_forever.html.erb +12 -0
- data/spec/internal/tmp/modular/heavy.html.erb +19 -0
- data/spec/internal/tmp/modular/nested.html.erb +28 -0
- data/spec/modular/configuration_spec.rb +46 -0
- data/spec/{base.rb → modular/creation_spec.rb} +11 -16
- data/spec/spec_helper.rb +11 -3
- data/spec/views/indirect_render/index.html.erb_spec.rb +4 -0
- data/templates/layout.erb +5 -10
- metadata +119 -133
- data/autotest/discover.rb +0 -12
- data/lib/modular/rails.rb +0 -16
- data/modular-app/app/components/cached_forever.rb +0 -10
- data/modular-app/app/components/fake_news_feed.rb +0 -9
- data/modular-app/app/components/heavy_task.rb +0 -5
- data/modular-app/app/helpers/application_helper.rb +0 -2
- data/modular-app/app/helpers/callback_layout_helper.rb +0 -2
- data/modular-app/app/helpers/example_helper.rb +0 -2
- data/modular-app/app/helpers/indirect_render_helper.rb +0 -2
- data/modular-app/spec/helpers/indirect_render_helper_spec.rb +0 -14
- data/modular-app/spec/views/indirect_render/index.html.erb_spec.rb +0 -4
- data/spec/configuration.rb +0 -74
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Modular
|
|
2
|
+
module Creation
|
|
3
|
+
def create(typ, params = {})
|
|
4
|
+
return typ if typ.is_a? Modular::Components::Base
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
begin
|
|
8
|
+
component = typ.to_s.camelize.constantize.new params
|
|
9
|
+
rescue NameError
|
|
10
|
+
component = (Components.name + '::' + typ.to_s.camelize).constantize.new params
|
|
11
|
+
end
|
|
12
|
+
rescue Exception => e
|
|
13
|
+
raise "Unable to create element " + typ.to_s
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
raise "Component has errors: " + component.errors.to_s if component.invalid?
|
|
17
|
+
|
|
18
|
+
component
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def from_json(text)
|
|
22
|
+
obj = ActiveSupport::JSON.decode text
|
|
23
|
+
raise "Type expected in json string" unless obj['type']
|
|
24
|
+
create(obj['type'], obj.except('type'))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
extend self
|
|
28
|
+
end
|
|
29
|
+
end
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ require 'erb'
|
|
|
3
3
|
module Modular
|
|
4
4
|
class LayoutGenerator
|
|
5
5
|
class ERBContext
|
|
6
|
-
def initialize(hash)
|
|
6
|
+
def initialize(hash = {})
|
|
7
7
|
hash.each_pair do |key, value|
|
|
8
8
|
instance_variable_set('@' + key.to_s, value)
|
|
9
9
|
end
|
|
@@ -23,7 +23,7 @@ module Modular
|
|
|
23
23
|
filename.to_s
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def initialize(id, params)
|
|
26
|
+
def initialize(id, params= {})
|
|
27
27
|
@id = id
|
|
28
28
|
@params = params
|
|
29
29
|
end
|
|
@@ -38,7 +38,7 @@ module Modular
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def layout_exists?
|
|
41
|
-
if
|
|
41
|
+
if Rails.configuration.action_controller.perform_caching
|
|
42
42
|
File.exists?(filename)
|
|
43
43
|
else
|
|
44
44
|
false
|
|
@@ -48,19 +48,20 @@ module Modular
|
|
|
48
48
|
def write_layout
|
|
49
49
|
folder = self.foldername
|
|
50
50
|
filename = self.filename
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
path = "#{Rails.root}/#{folder}"
|
|
52
|
+
|
|
53
|
+
Dir.mkdir(path) unless File.exists? path
|
|
53
54
|
|
|
54
55
|
template = ERB.new File.new(Gem.loaded_specs['modular'].full_gem_path + '/templates/layout.erb').read
|
|
55
56
|
output = template.result(ERBContext.new(template_variables).get_binding)
|
|
56
57
|
|
|
57
|
-
File.open(filename, 'w') do |f|
|
|
58
|
+
File.open("#{Rails.root}/#{filename}", 'w') do |f|
|
|
58
59
|
f.write(output)
|
|
59
60
|
end
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
def template_variables
|
|
63
|
-
@params.merge
|
|
64
|
+
{ :original_layout => 'application' }.merge(@params.merge(:layout_id => @id))
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'modular/action_controller_extension'
|
|
2
|
+
|
|
3
|
+
module TaggableCache
|
|
4
|
+
class Railtie < ::Rails::Railtie
|
|
5
|
+
initializer "modular" do |app|
|
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
|
7
|
+
::ActionController::Base.__send__ :include, Modular::ActionControllerExtension
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/modular/rendering.rb
CHANGED
|
@@ -1,82 +1,77 @@
|
|
|
1
|
-
module Modular
|
|
2
|
-
|
|
3
|
-
module DirectRender
|
|
4
|
-
extend ActiveSupport::Concern
|
|
5
|
-
|
|
6
|
-
module InstanceMethods
|
|
1
|
+
module Modular::Rendering
|
|
2
|
+
extend ActiveSupport::Concern
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def config
|
|
17
|
-
ActionController::Base.config
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def execute
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def render
|
|
25
|
-
execute
|
|
26
|
-
modular_render :render_type => :direct
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def initialize(attributes = {})
|
|
30
|
-
append_view_path File.join('app', 'views')
|
|
31
|
-
super
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
protected
|
|
35
|
-
def modular_render(args = {})
|
|
36
|
-
render_to_string :file => 'components/' + action_name, :locals => args
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
module ClassMethods
|
|
42
|
-
def view_context_class
|
|
43
|
-
context = super
|
|
44
|
-
|
|
45
|
-
context.send :define_method, :render_component do |component|
|
|
46
|
-
if component.is_a?(Modular::Components::IndirectRender)
|
|
47
|
-
component.indirect_render
|
|
48
|
-
else
|
|
49
|
-
a = "<%= Modular.from_json('"+ component.to_json + "').render %>"
|
|
50
|
-
a.html_safe
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context.send :include, Rails.application.routes.url_helpers if defined? Rails
|
|
55
|
-
|
|
56
|
-
context.send :include, ApplicationHelper if defined? ApplicationHelper
|
|
57
|
-
|
|
58
|
-
context
|
|
59
|
-
end
|
|
60
|
-
end
|
|
4
|
+
def controller_path
|
|
5
|
+
'components'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def action_name
|
|
9
|
+
type.underscore
|
|
10
|
+
end
|
|
61
11
|
|
|
62
|
-
|
|
12
|
+
# def config
|
|
13
|
+
# ActionController::Base.config
|
|
14
|
+
# end
|
|
15
|
+
|
|
16
|
+
def execute
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def render
|
|
20
|
+
execute
|
|
21
|
+
modular_render :render_type => :indirect
|
|
22
|
+
end
|
|
63
23
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
24
|
+
# configure the different paths correctly
|
|
25
|
+
def initialize(*args)
|
|
26
|
+
super()
|
|
27
|
+
lookup_context.view_paths = Rails.root.join('app', 'views')
|
|
28
|
+
config.javascripts_dir = Rails.root.join('public', 'javascripts')
|
|
29
|
+
config.stylesheets_dir = Rails.root.join('public', 'stylesheets')
|
|
30
|
+
config.assets_dir = Rails.root.join('public')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# we are not in a browser, no need for this
|
|
34
|
+
def protect_against_forgery?
|
|
35
|
+
false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# so that your flash calls still work
|
|
39
|
+
def flash
|
|
40
|
+
{}
|
|
41
|
+
end
|
|
72
42
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
43
|
+
def params
|
|
44
|
+
{}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# # same asset host as the controllers
|
|
48
|
+
# self.asset_host = ActionController::Base.asset_host
|
|
49
|
+
|
|
50
|
+
def initialize(attributes = {})
|
|
51
|
+
append_view_path(Rails.root.join('app', 'views'))
|
|
52
|
+
append_view_path(Gem.loaded_specs['modular'].full_gem_path + '/templates')
|
|
53
|
+
|
|
54
|
+
super
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
protected
|
|
58
|
+
def modular_render(args = {})
|
|
59
|
+
render_to_string :file => 'components/' + action_name, :locals => args
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
module ClassMethods
|
|
63
|
+
def view_context_class
|
|
64
|
+
context = super
|
|
76
65
|
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
context.send :define_method, :render_component do |component|
|
|
67
|
+
component.render
|
|
79
68
|
end
|
|
69
|
+
|
|
70
|
+
context.send :include, Rails.application.routes.url_helpers if defined? Rails
|
|
71
|
+
|
|
72
|
+
context.send :include, ApplicationHelper if defined? ApplicationHelper
|
|
73
|
+
|
|
74
|
+
context
|
|
80
75
|
end
|
|
81
76
|
end
|
|
82
77
|
end
|
data/lib/modular/version.rb
CHANGED
data/modular.gemspec
CHANGED
|
File without changes
|
|
@@ -13,7 +13,7 @@ describe Modular::Components::Container, ' vertical container class ' do
|
|
|
13
13
|
@cmp.components.push Modular.create(:FakeNewsFeed, { :news_count => 50, :title => 'Best news feed' }).to_json
|
|
14
14
|
json = @cmp.to_json
|
|
15
15
|
container = Modular.from_json(json)
|
|
16
|
-
container.components[0].should be_a_kind_of
|
|
16
|
+
container.components[0].should be_a_kind_of FakeNewsFeed
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "should have add_container and add_child methods" do
|
|
@@ -26,9 +26,9 @@ describe Modular::Components::Container, ' vertical container class ' do
|
|
|
26
26
|
@cmp.components[0].title.should == 'Test container title'
|
|
27
27
|
|
|
28
28
|
feed = @cmp.components[0].components[0]
|
|
29
|
-
feed.should be_a_kind_of
|
|
29
|
+
feed.should be_a_kind_of FakeNewsFeed
|
|
30
30
|
feed.title.should == 'Worst news feed'
|
|
31
31
|
|
|
32
|
-
@cmp.components[0].components[1].should be_a_kind_of
|
|
32
|
+
@cmp.components[0].components[1].should be_a_kind_of Vertical
|
|
33
33
|
end
|
|
34
34
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
class
|
|
1
|
+
class CachedForTime < Modular::Components::Base
|
|
2
2
|
include Modular::Components::Caching
|
|
3
3
|
cache :expires_in => 2.seconds
|
|
4
4
|
|
|
5
5
|
def execute
|
|
6
6
|
SimpleModel.called_by_cached_for_time
|
|
7
7
|
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
CachedForTime = Modular::Components::CachedForTime
|
|
8
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|