Commit 1249a774ea66c036230dd14e7e91c06b6f0340d8
1 parent
331957a6
Exists in
master
and in
29 other branches
ActionItem24: checkpoint
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1124 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
58 additions
and
92 deletions
Show diff stats
app/controllers/my_profile/cms/README
| ... | ... | @@ -1,46 +0,0 @@ |
| 1 | -CMS editors for Noosfero | |
| 2 | -======================== | |
| 3 | - | |
| 4 | -This directory contains code for custom content editors in Noosfero. | |
| 5 | - | |
| 6 | -Creating a new editor | |
| 7 | -===================== | |
| 8 | - | |
| 9 | -:: File structure | |
| 10 | - | |
| 11 | -Let's say that you are implementingn and editor for type, say, "foo/bar". Then | |
| 12 | -you have to create: | |
| 13 | - | |
| 14 | - * app/controllers/my_profile/cms/foo_bar.html | |
| 15 | - * app/views/cms/foo_bar_*.rhtml (one view for each action you define in the | |
| 16 | - controller class, if applicable). | |
| 17 | - | |
| 18 | -:: Coding conventions | |
| 19 | - | |
| 20 | -You file must add methods to CmsController class. They are going to be loaded | |
| 21 | -after the cms_controller.rb file itself, to you don't need to care about | |
| 22 | -declaring the superclass: | |
| 23 | - | |
| 24 | - class CmsController | |
| 25 | - def foo_bar_edit | |
| 26 | - # code for preparing the "edit" view | |
| 27 | - end | |
| 28 | - | |
| 29 | - def foo_bar_new | |
| 30 | - # code for preparing the "new" view | |
| 31 | - end | |
| 32 | - | |
| 33 | - # etc ... | |
| 34 | - end | |
| 35 | - | |
| 36 | -Note that *all* of your actions must be prefixed with the content type (e.g. | |
| 37 | -"foor_bar_" for "foo/bar"), in order to avoid conflicts. | |
| 38 | - | |
| 39 | -The views for those actions can be thrown in app/views/cms/, just like other | |
| 40 | -views for this controller. | |
| 41 | - | |
| 42 | -Limitations | |
| 43 | -=========== | |
| 44 | - | |
| 45 | - | |
| 46 | - |
app/controllers/my_profile/cms/text_html.rb
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -26,8 +26,6 @@ class CmsController < MyProfileController |
| 26 | 26 | return |
| 27 | 27 | end |
| 28 | 28 | end |
| 29 | - | |
| 30 | - render :action => "#{mime_type_to_action_name(@article.mime_type)}_edit" | |
| 31 | 29 | end |
| 32 | 30 | |
| 33 | 31 | def new |
| ... | ... | @@ -47,7 +45,7 @@ class CmsController < MyProfileController |
| 47 | 45 | end |
| 48 | 46 | end |
| 49 | 47 | |
| 50 | - render :action => "#{mime_type_to_action_name(type)}_new" | |
| 48 | + render :action => 'edit' | |
| 51 | 49 | end |
| 52 | 50 | |
| 53 | 51 | post_only :set_home_page | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | + | |
| 2 | + | |
| 3 | +<%= render :file => 'shared/tiny_mce' %> | |
| 4 | + | |
| 5 | +<%= error_messages_for 'article' %> | |
| 6 | + | |
| 7 | +<% labelled_form_for 'article', @article do |f| %> | |
| 8 | + | |
| 9 | + <%= hidden_field_tag('parent_id', params[:parent_id]) if params[:parent_id] %> | |
| 10 | + | |
| 11 | + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> | |
| 12 | + | |
| 13 | + <%= design_display_button_submit('save', _('Save')) %> | |
| 14 | + <%= design_display_button('cancel', _('Cancel'), :action => (@article.parent ? 'view' : 'index'), :id => @article.parent) %> | |
| 15 | +<% end %> | ... | ... |
app/views/cms/new.rhtml
app/views/cms/text_html_edit.rhtml
app/views/cms/text_html_new.rhtml
| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | -<%= render :file => 'shared/tiny_mce' %> | |
| 2 | - | |
| 3 | -<%= error_messages_for 'article' %> | |
| 4 | - | |
| 5 | -<% labelled_form_for 'article', @article do |f| %> | |
| 6 | - | |
| 7 | - <%= hidden_field_tag('parent_id', params[:parent_id]) if params[:parent_id] %> | |
| 8 | - | |
| 9 | - <%= f.text_field('name', :size => '64') %> | |
| 10 | - | |
| 11 | - <%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %> | |
| 12 | - | |
| 13 | - <%= f.text_area('abstract', :cols => 64, :rows => 5) %> | |
| 14 | - | |
| 15 | - <%= f.text_area('body', :cols => 64) %> | |
| 16 | - | |
| 17 | - <%= design_display_button_submit('save', _('Save')) %> | |
| 18 | - <%= design_display_button('cancel', _('Cancel'), :action => (@article.parent ? 'view' : 'index'), :id => @article.parent) %> | |
| 19 | - | |
| 20 | -<% end %> |
test/functional/cms_controller_test.rb
| ... | ... | @@ -47,20 +47,20 @@ class CmsControllerTest < Test::Unit::TestCase |
| 47 | 47 | a.save! |
| 48 | 48 | |
| 49 | 49 | get :edit, :profile => profile.identifier, :id => a.id |
| 50 | - assert_template 'text_html_edit' | |
| 51 | - end | |
| 52 | - | |
| 53 | - should 'be able to type a new document' do | |
| 54 | - get :new, :profile => profile.identifier | |
| 55 | - assert_template 'text_html_new' | |
| 50 | + assert_template 'edit' | |
| 56 | 51 | end |
| 57 | 52 | |
| 58 | 53 | should 'be able to create a new document' do |
| 59 | 54 | get :new, :profile => profile.identifier |
| 60 | - assert_template 'text_html_new' | |
| 55 | + assert_template 'select_article_type' | |
| 61 | 56 | assert_tag :tag => 'form', :attributes => { :action => "/myprofile/#{profile.identifier}/cms/new", :method => /post/i } |
| 62 | 57 | end |
| 63 | 58 | |
| 59 | + should 'present edit screen after choosing article type' do | |
| 60 | + get :new, :profile => profile.identifier, :article_type => 'Article' | |
| 61 | + assert_template 'edit' | |
| 62 | + end | |
| 63 | + | |
| 64 | 64 | should 'be able to save a save a document' do |
| 65 | 65 | assert_difference Article, :count do |
| 66 | 66 | 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 |
| 125 | 125 | |
| 126 | 126 | get :edit, :profile => profile.identifier, :id => a.id |
| 127 | 127 | assert_response :success |
| 128 | - assert_template 'text_html_edit' | |
| 128 | + assert_template 'edit' | |
| 129 | 129 | end |
| 130 | 130 | |
| 131 | 131 | should 'convert mime-types to action names' do | ... | ... |
test/test_helper.rb
| ... | ... | @@ -103,6 +103,10 @@ class Test::Unit::TestCase |
| 103 | 103 | object.valid? |
| 104 | 104 | assert !object.errors.invalid?(attribute) |
| 105 | 105 | end |
| 106 | + | |
| 107 | + def assert_subclass(parent, child) | |
| 108 | + assert_equal parent, child.superclass, "Class #{child} expected to be a subclass of #{parent}" | |
| 109 | + end | |
| 106 | 110 | |
| 107 | 111 | private |
| 108 | 112 | ... | ... |