adding view helpers, fixing js
Oleg
committed Nov 16, 2010
commit 4a47d7ea5947e90c87a0e5ad2ebaabf3f968fea6
Showing 3
changed files with
46 additions
and 9 deletions
comfortable_mexican_sofa/view_methods.rb b/lib/comfortable_mexican_sofa/view_methods.rb
+18
-0
| @@ | @@ -19,6 +19,24 @@ module ComfortableMexicanSofa::ViewMethods |
| def cms_hook(name) | |
| ComfortableMexicanSofa::ViewHooks.render(name, self) | |
| end | |
| + | |
| + | # Content of a snippet. Example: |
| + | # cms_snippet_content(:my_snippet) |
| + | def cms_snippet_content(snippet_slug) |
| + | return '' unless snippet = CmsSnippet.find_by_slug(snippet_slug) |
| + | snippet.content.to_s.html_safe |
| + | end |
| + | |
| + | # Content of a page block. This is how you get content from page:field |
| + | # Example: |
| + | # cms_page_content(:left_column, CmsPage.first) |
| + | # cms_page_content(:left_column) # if @cms_page is present |
| + | def cms_page_content(block_label, page = nil) |
| + | return '' unless page ||= @cms_page |
| + | return '' unless block = page.cms_blocks.find_by_label(block_label) |
| + | block.content.to_s.html_safe |
| + | end |
| + | |
| end | |
| ActionView::Base.send :include, ComfortableMexicanSofa::ViewMethods | |
public/javascripts/comfortable_mexican_sofa/cms.js
+7
-9
| @@ | @@ -6,7 +6,7 @@ $.CMS = function(){ |
| $('input#slugify').bind('keyup.cms', function() { | |
| $('input#slug').val( $.CMS.slugify( $(this).val() ) ); | |
| }); | |
| - | |
| + | |
| // Expand/Collapse tree function | |
| $('a.tree_toggle').bind('click.cms', function() { | |
| $(this).siblings('ul').toggle(); | |
| @@ | @@ -14,12 +14,12 @@ $.CMS = function(){ |
| // object_id are set in the helper (check cms_helper.rb) | |
| $.ajax({url: [current_path, object_id, 'toggle'].join('/')}); | |
| }); | |
| - | |
| + | |
| // Show/hide details | |
| $('a.details_toggle').bind('click.cms', function() { | |
| $(this).parent().siblings('table.details').toggle(); | |
| }); | |
| - | |
| + | |
| // Sortable trees | |
| $('ul.sortable').each(function(){ | |
| $(this).sortable({ handle: 'div.dragger', | |
| @@ | @@ -31,13 +31,11 @@ $.CMS = function(){ |
| // Load Page Blocks on layout change | |
| $('select#cms_page_cms_layout_id').bind('change.cms', function() { | |
| - | $.ajax({url: [$(this).attr('data-path-prefix'), 'pages', $(this).attr('data-page-id'), 'form_blocks'].join('/'), data: ({ layout_id: $(this).val()})}) |
| + | $.ajax({url: ['/' + $(this).attr('data-path-prefix'), 'pages', $(this).attr('data-page-id'), 'form_blocks'].join('/'), data: ({ layout_id: $(this).val()})}) |
| }) | |
| - | |
| + | |
| }); // End $(document).ready() | |
| - | |
| - | |
| - | |
| + | |
| return { | |
| slugify: function(str){ | |
| str = str.replace(/^\s+|\s+$/g, ''); | |
| @@ | @@ -50,4 +48,4 @@ $.CMS = function(){ |
| return str; | |
| } | |
| } | |
| - | }(); |
| + | }(); |
| \ No newline at end of file | |
test/unit/view_methods_test.rb
+21
-0
| @@ | @@ -0,0 +1,21 @@ |
| + | require File.expand_path('../test_helper', File.dirname(__FILE__)) |
| + | |
| + | class ViewMethodsTest < ActiveSupport::TestCase |
| + | |
| + | include ComfortableMexicanSofa::ViewMethods |
| + | |
| + | def test_cms_snippet_content |
| + | assert_equal 'default_snippet_content', cms_snippet_content('default') |
| + | assert_equal '', cms_snippet_content('not_found') |
| + | end |
| + | |
| + | def test_cms_page_content |
| + | assert_equal 'default_field_text_content', cms_page_content('default_field_text', cms_pages(:default)) |
| + | assert_equal '', cms_page_content('default_field_text') |
| + | @cms_page = cms_pages(:default) |
| + | assert_equal 'default_field_text_content', cms_page_content('default_field_text') |
| + | assert_equal '', cms_page_content('not_found') |
| + | @cms_page = nil |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |