Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds preview action to wiki/pages

  • Loading branch information...
commit ac0eede54700e794d6474e9042d99a86c6550762 1 parent bf821b0
adam authored
View
10 lib/3scale/wiki/pages_controller.rb
@@ -54,6 +54,16 @@ def destroy
redirect_to(wiki_pages_url)
end
+ def preview
+ @wiki_page = wiki_pages.new(params[:wiki_page])
+ @wiki_page.readonly!
+
+ respond_to do |format|
+ format.js { render :layout => false }
+ format.all
+ end
+ end
+
private
# Override this to supply your own wiki page class. Default is WikiPage.
View
5 lib/app/views/3scale/wiki/pages/_form.html.erb
@@ -1,10 +1,11 @@
-<div class="field">
+<div class="field wiki_title">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
-<div class="field">
+<div class="field wiki_content">
<%= form.label :content %>
+ <%= link_to 'Preview', preview_new_wiki_page_path, :class => 'wiki_preview_trigger' %>
<%= form.text_area :content, :rows => 40 %>
<div class="help">
View
7 lib/app/views/3scale/wiki/pages/preview.html.erb
@@ -0,0 +1,7 @@
+<h2><%= h @wiki_page.title %></h2>
+
+<span class="popup_close" title="Close">Close</span>
+
+<div class="usercontent">
+ <%= wiki_text @wiki_page.content %>
+</div>
View
2  test/test_helper.rb
@@ -54,5 +54,5 @@ def wiki_page_model
# Routes
ActionController::Routing::Routes.draw do |map|
- map.resources :wiki_pages
+ map.resources :wiki_pages, :new => {:preview => :post}
end
View
10 test/wiki_pages_controller_test.rb
@@ -112,6 +112,16 @@ def setup
assert_redirected_to wiki_pages_url
end
+ test 'on POST to :preview with javascript' do
+ xhr :post, :preview, :wiki_page => {:title => 'Hello world',
+ :content => 'foo *bar*'}
+ assert_response :success
+ assert_template '3scale/wiki/pages/preview'
+
+ assert_not_nil assigns(:wiki_page)
+ assert_equal 'Hello world', assigns(:wiki_page).title
+ end
+
private
def setup_page
Please sign in to comment.
Something went wrong with that request. Please try again.