adding simple hooks system
Oleg
committed Oct 26, 2010
commit 3aee275656c66d2e4b019d410848240281e8307b
Showing 7
changed files with
81 additions
and 6 deletions
app/views/layouts/cms_admin.html.erb
+1
-1
| @@ | @@ -16,7 +16,7 @@ |
| <%= active_link_to 'Layouts', cms_admin_layouts_path %> | |
| <%= active_link_to 'Pages', cms_admin_pages_path %> | |
| <%= active_link_to 'Snippets', cms_admin_snippets_path %> | |
| - | <%= yield :left_column %> |
| + | <%= hook :navigation %> |
| </div> | |
| </div> | |
| <div class='right_column'> | |
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb
+1
-0
| @@ | @@ -7,6 +7,7 @@ end |
| 'comfortable_mexican_sofa/http_auth', | |
| 'comfortable_mexican_sofa/rails_extensions', | |
| 'comfortable_mexican_sofa/controller_methods', | |
| + | 'comfortable_mexican_sofa/view_hooks', |
| 'comfortable_mexican_sofa/view_methods', | |
| 'comfortable_mexican_sofa/form_builder', | |
| 'comfortable_mexican_sofa/acts_as_tree', | |
comfortable_mexican_sofa/view_hooks.rb b/lib/comfortable_mexican_sofa/view_hooks.rb
+25
-0
| @@ | @@ -0,0 +1,25 @@ |
| + | module ComfortableMexicanSofa::ViewHooks |
| + | |
| + | # Array of declared hooks |
| + | def self.hooks |
| + | @@hooks ||= { } |
| + | end |
| + | |
| + | # Renders hook content |
| + | def self.render(name, template) |
| + | template.render :partial => self.hooks[name.to_sym] if self.hooks[name.to_sym] |
| + | end |
| + | |
| + | # Will declare a partial that will be rendered for this hook |
| + | # Example: |
| + | # ComfortableMexicanSofa::ViewHooks.add(:navigation, 'shared/navigation') |
| + | def self.add(name, partial_path) |
| + | self.hooks[name.to_sym] = partial_path |
| + | end |
| + | |
| + | # Removing previously declared hook |
| + | def self.remove(name) |
| + | self.hooks.delete(name) |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/view_methods.rb b/lib/comfortable_mexican_sofa/view_methods.rb
+5
-0
| @@ | @@ -14,6 +14,11 @@ module ComfortableMexicanSofa::ViewMethods |
| def datetime_field_tag(name, value = nil, options = {}) | |
| text_field_tag(name, value, options.stringify_keys.update('type' => 'datetime')) | |
| end | |
| + | |
| + | # Injects some content somewhere inside cms admin area |
| + | def hook(name) |
| + | ComfortableMexicanSofa::ViewHooks.render(name, self) |
| + | end |
| end | |
| ActionView::Base.send :include, ComfortableMexicanSofa::ViewMethods | |
public/stylesheets/comfortable_mexican_sofa/structure.css
+26
-5
| @@ | @@ -160,9 +160,12 @@ ul.list li .action_links { |
| float: right; | |
| opacity: 0.1; | |
| } | |
| - | ul.list .action_links a { |
| + | table.formatted td.action_links a { |
| + | opacity: 0.1; |
| + | } |
| + | ul.list .action_links a, |
| + | table.formatted td.action_links a { |
| margin-left: 3px; | |
| - | float: left; |
| background-color: #272A2D; | |
| color: #fff; | |
| padding: 3px 5px; | |
| @@ | @@ -171,11 +174,15 @@ ul.list .action_links a { |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| } | |
| - | ul.list li .label { |
| + | ul.list li .label, |
| + | table.formatted td .label { |
| margin-left: 35px; | |
| font: 16px/18px Georgia, serif; | |
| color: #1C1F22; | |
| } | |
| + | table.formatted td .label { |
| + | margin-left: 0px; |
| + | } |
| ul.list li .label .sublabel { | |
| margin-left: 15px; | |
| font: 11px/14px Arial, sans-serif; | |
| @@ | @@ -184,9 +191,23 @@ ul.list li .label .sublabel { |
| ul.list li ul { | |
| margin-left: 30px; | |
| } | |
| - | ul.list li .item:hover { |
| + | ul.list li .item:hover, |
| + | table.formatted tr:hover td { |
| background-color: #fff; | |
| } | |
| - | ul.list li .item:hover .action_links { |
| + | ul.list li .item:hover .action_links, |
| + | table.formatted tr:hover td.action_links a { |
| opacity: 1; | |
| + | } |
| + | table.formatted th, |
| + | table.formatted td { |
| + | white-space: nowrap; |
| + | vertical-align: top; |
| + | padding: 5px; |
| + | border-bottom: 1px solid #fff; |
| + | } |
| + | table.formatted th.main, |
| + | table.formatted td.main { |
| + | width: 100%; |
| + | white-space: normal; |
| } | |
| \ No newline at end of file | |
test/fixtures/views/_nav_hook.html.erb
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | hook_content |
| \ No newline at end of file | |
test/integration/view_hooks_test.rb
+22
-0
| @@ | @@ -0,0 +1,22 @@ |
| + | require File.dirname(__FILE__) + '/../test_helper' |
| + | |
| + | class ViewHooksTest < ActionDispatch::IntegrationTest |
| + | |
| + | def test_hooks_rendering |
| + | CmsAdmin::SitesController.append_view_path(File.expand_path('../fixtures/views', File.dirname(__FILE__))) |
| + | ComfortableMexicanSofa::ViewHooks.add(:navigation, '/nav_hook') |
| + | |
| + | http_auth :get, cms_admin_sites_path |
| + | assert_response :success |
| + | assert_match /hook_content/, response.body |
| + | end |
| + | |
| + | def test_hooks_rendering_with_no_hook |
| + | ComfortableMexicanSofa::ViewHooks.remove(:navigation) |
| + | |
| + | http_auth :get, cms_admin_sites_path |
| + | assert_response :success |
| + | assert_no_match /hook_content/, response.body |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |