From 1249a774ea66c036230dd14e7e91c06b6f0340d8 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 22 Dec 2007 02:49:30 +0000 Subject: [PATCH] ActionItem24: checkpoint --- app/controllers/my_profile/cms/README | 46 ---------------------------------------------- app/controllers/my_profile/cms/text_html.rb | 5 ----- app/controllers/my_profile/cms_controller.rb | 4 +--- app/models/tiny_mce_article.rb | 2 ++ app/views/cms/_article.rhtml | 1 + app/views/cms/_tiny_mce_article.rhtml | 9 +++++++++ app/views/cms/edit.rhtml | 15 +++++++++++++++ app/views/cms/new.rhtml | 9 --------- app/views/cms/select_article_type.rhtml | 9 +++++++++ app/views/cms/text_html_edit.rhtml | 1 - app/views/cms/text_html_new.rhtml | 20 -------------------- test/functional/cms_controller_test.rb | 16 ++++++++-------- test/test_helper.rb | 4 ++++ test/unit/tiny_mce_article_test.rb | 9 +++++++++ 14 files changed, 58 insertions(+), 92 deletions(-) delete mode 100644 app/controllers/my_profile/cms/README delete mode 100644 app/controllers/my_profile/cms/text_html.rb create mode 100644 app/models/tiny_mce_article.rb create mode 120000 app/views/cms/_article.rhtml create mode 100644 app/views/cms/_tiny_mce_article.rhtml create mode 100644 app/views/cms/edit.rhtml delete mode 100644 app/views/cms/new.rhtml create mode 100644 app/views/cms/select_article_type.rhtml delete mode 120000 app/views/cms/text_html_edit.rhtml delete mode 100644 app/views/cms/text_html_new.rhtml create mode 100644 test/unit/tiny_mce_article_test.rb diff --git a/app/controllers/my_profile/cms/README b/app/controllers/my_profile/cms/README deleted file mode 100644 index 6bd4cf2..0000000 --- a/app/controllers/my_profile/cms/README +++ /dev/null @@ -1,46 +0,0 @@ -CMS editors for Noosfero -======================== - -This directory contains code for custom content editors in Noosfero. - -Creating a new editor -===================== - -:: File structure - -Let's say that you are implementingn and editor for type, say, "foo/bar". Then -you have to create: - - * app/controllers/my_profile/cms/foo_bar.html - * app/views/cms/foo_bar_*.rhtml (one view for each action you define in the - controller class, if applicable). - -:: Coding conventions - -You file must add methods to CmsController class. They are going to be loaded -after the cms_controller.rb file itself, to you don't need to care about -declaring the superclass: - - class CmsController - def foo_bar_edit - # code for preparing the "edit" view - end - - def foo_bar_new - # code for preparing the "new" view - end - - # etc ... - end - -Note that *all* of your actions must be prefixed with the content type (e.g. -"foor_bar_" for "foo/bar"), in order to avoid conflicts. - -The views for those actions can be thrown in app/views/cms/, just like other -views for this controller. - -Limitations -=========== - - - diff --git a/app/controllers/my_profile/cms/text_html.rb b/app/controllers/my_profile/cms/text_html.rb deleted file mode 100644 index 03c460a..0000000 --- a/app/controllers/my_profile/cms/text_html.rb +++ /dev/null @@ -1,5 +0,0 @@ -class CmsController - - # add eventual helper methods you need for editing your type of article. - -end diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 4539e81..ec7f5fc 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -26,8 +26,6 @@ class CmsController < MyProfileController return end end - - render :action => "#{mime_type_to_action_name(@article.mime_type)}_edit" end def new @@ -47,7 +45,7 @@ class CmsController < MyProfileController end end - render :action => "#{mime_type_to_action_name(type)}_new" + render :action => 'edit' end post_only :set_home_page diff --git a/app/models/tiny_mce_article.rb b/app/models/tiny_mce_article.rb new file mode 100644 index 0000000..46168f6 --- /dev/null +++ b/app/models/tiny_mce_article.rb @@ -0,0 +1,2 @@ +class TinyMceArticle < Article +end diff --git a/app/views/cms/_article.rhtml b/app/views/cms/_article.rhtml new file mode 120000 index 0000000..8f01891 --- /dev/null +++ b/app/views/cms/_article.rhtml @@ -0,0 +1 @@ +_tiny_mce_article.rhtml \ No newline at end of file diff --git a/app/views/cms/_tiny_mce_article.rhtml b/app/views/cms/_tiny_mce_article.rhtml new file mode 100644 index 0000000..2a2f9d6 --- /dev/null +++ b/app/views/cms/_tiny_mce_article.rhtml @@ -0,0 +1,9 @@ + +<%= f.text_field('name', :size => '64') %> + +<%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %> + +<%= f.text_area('abstract', :cols => 64, :rows => 5) %> + +<%= f.text_area('body', :cols => 64) %> + diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml new file mode 100644 index 0000000..4dccdb8 --- /dev/null +++ b/app/views/cms/edit.rhtml @@ -0,0 +1,15 @@ + + +<%= render :file => 'shared/tiny_mce' %> + +<%= error_messages_for 'article' %> + +<% labelled_form_for 'article', @article do |f| %> + + <%= hidden_field_tag('parent_id', params[:parent_id]) if params[:parent_id] %> + + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> + + <%= design_display_button_submit('save', _('Save')) %> + <%= design_display_button('cancel', _('Cancel'), :action => (@article.parent ? 'view' : 'index'), :id => @article.parent) %> +<% end %> diff --git a/app/views/cms/new.rhtml b/app/views/cms/new.rhtml deleted file mode 100644 index 7d7445f..0000000 --- a/app/views/cms/new.rhtml +++ /dev/null @@ -1,9 +0,0 @@ -

- <%= _('Choose the type of article:') %> -

- - diff --git a/app/views/cms/select_article_type.rhtml b/app/views/cms/select_article_type.rhtml new file mode 100644 index 0000000..7d7445f --- /dev/null +++ b/app/views/cms/select_article_type.rhtml @@ -0,0 +1,9 @@ +

+ <%= _('Choose the type of article:') %> +

+ + diff --git a/app/views/cms/text_html_edit.rhtml b/app/views/cms/text_html_edit.rhtml deleted file mode 120000 index ee9726e..0000000 --- a/app/views/cms/text_html_edit.rhtml +++ /dev/null @@ -1 +0,0 @@ -text_html_new.rhtml \ No newline at end of file diff --git a/app/views/cms/text_html_new.rhtml b/app/views/cms/text_html_new.rhtml deleted file mode 100644 index 4d874b1..0000000 --- a/app/views/cms/text_html_new.rhtml +++ /dev/null @@ -1,20 +0,0 @@ -<%= render :file => 'shared/tiny_mce' %> - -<%= error_messages_for 'article' %> - -<% labelled_form_for 'article', @article do |f| %> - - <%= hidden_field_tag('parent_id', params[:parent_id]) if params[:parent_id] %> - - <%= f.text_field('name', :size => '64') %> - - <%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %> - - <%= f.text_area('abstract', :cols => 64, :rows => 5) %> - - <%= f.text_area('body', :cols => 64) %> - - <%= design_display_button_submit('save', _('Save')) %> - <%= design_display_button('cancel', _('Cancel'), :action => (@article.parent ? 'view' : 'index'), :id => @article.parent) %> - -<% end %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index a0db8ac..0c479b3 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -47,20 +47,20 @@ class CmsControllerTest < Test::Unit::TestCase a.save! get :edit, :profile => profile.identifier, :id => a.id - assert_template 'text_html_edit' - end - - should 'be able to type a new document' do - get :new, :profile => profile.identifier - assert_template 'text_html_new' + assert_template 'edit' end should 'be able to create a new document' do get :new, :profile => profile.identifier - assert_template 'text_html_new' + assert_template 'select_article_type' assert_tag :tag => 'form', :attributes => { :action => "/myprofile/#{profile.identifier}/cms/new", :method => /post/i } end + should 'present edit screen after choosing article type' do + get :new, :profile => profile.identifier, :article_type => 'Article' + assert_template 'edit' + end + should 'be able to save a save a document' do assert_difference Article, :count do post :new, :profile => profile.identifier, :article => { :name => 'a test article', :body => 'the text of the article ...' } @@ -125,7 +125,7 @@ class CmsControllerTest < Test::Unit::TestCase get :edit, :profile => profile.identifier, :id => a.id assert_response :success - assert_template 'text_html_edit' + assert_template 'edit' end should 'convert mime-types to action names' do diff --git a/test/test_helper.rb b/test/test_helper.rb index 08329e2..7b09edd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -103,6 +103,10 @@ class Test::Unit::TestCase object.valid? assert !object.errors.invalid?(attribute) end + + def assert_subclass(parent, child) + assert_equal parent, child.superclass, "Class #{child} expected to be a subclass of #{parent}" + end private diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb new file mode 100644 index 0000000..f159405 --- /dev/null +++ b/test/unit/tiny_mce_article_test.rb @@ -0,0 +1,9 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TinyMceArticleTest < Test::Unit::TestCase + + should 'be an article' do + assert_subclass Article, TinyMceArticle + end + +end -- libgit2 0.21.2