From ab35f2bf3d83d245fa2833e5654afaeb1a33d293 Mon Sep 17 00:00:00 2001 From: Dennis Collinson <dennis.collective@gmail.com> Date: Tue, 6 Mar 2012 13:55:24 -0800 Subject: [PATCH] MS DC posts/new page init --- app/controllers/posts_controller.rb | 8 +++++++- app/views/layouts/post.html.haml | 1 + app/views/posts/show.html.haml | 2 -- config/routes.rb | 2 +- features/step_definitions/trumpeter_steps.rb | 7 +++++++ features/trumpeter.feature | 12 ++++++++++++ public/javascripts/app/pages/post-new.js | 12 ++++++++++++ public/javascripts/app/router.js | 6 ++++++ .../javascripts/app/templates/post-form.handlebars | 4 ++++ public/javascripts/app/templates/post-new.handlebars | 1 + public/javascripts/app/views/post_form_view.js | 12 ++++++++++++ spec/javascripts/app/pages/post_new_spec.js | 9 +++++++++ spec/javascripts/app/views/post_form_spec.js | 10 ++++++++++ spec/javascripts/support/jasmine.yml | 1 + 14 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 features/step_definitions/trumpeter_steps.rb create mode 100644 features/trumpeter.feature create mode 100644 public/javascripts/app/pages/post-new.js create mode 100644 public/javascripts/app/templates/post-form.handlebars create mode 100644 public/javascripts/app/templates/post-new.handlebars create mode 100644 public/javascripts/app/views/post_form_view.js create mode 100644 spec/javascripts/app/pages/post_new_spec.js create mode 100644 spec/javascripts/app/views/post_form_spec.js diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 667eb51a49..7fff7c82ed 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -8,11 +8,17 @@ class PostsController < ApplicationController before_filter :authenticate_user!, :except => :show before_filter :set_format_if_malformed_from_status_net, :only => :show + layout 'post' + respond_to :html, :mobile, :json, :xml + def new + render :text => "", :layout => true + end + def show key = params[:id].to_s.length <= 8 ? :id : :guid @@ -34,7 +40,7 @@ class PostsController < ApplicationController format.xml{ render :xml => @post.to_diaspora_xml } format.mobile{render 'posts/show.mobile.haml'} format.json{ render :json => PostPresenter.new(@post, current_user).to_json } - format.any{render 'posts/show.html.haml', :layout => 'layouts/post'} + format.any{render 'posts/show.html.haml'} end else diff --git a/app/views/layouts/post.html.haml b/app/views/layouts/post.html.haml index bc10e192a3..b2a2e4d0a0 100644 --- a/app/views/layouts/post.html.haml +++ b/app/views/layouts/post.html.haml @@ -50,5 +50,6 @@ %body = flash_messages + #container = yield diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index ad90ddc2ee..5720b3364c 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -4,5 +4,3 @@ - content_for :page_title do = post_page_title @post - -#container diff --git a/config/routes.rb b/config/routes.rb index 59fe1a0273..f6e8771eb3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ Diaspora::Application.routes.draw do resources :status_messages, :only => [:new, :create] - resources :posts, :only => [:show, :destroy] do + resources :posts, :only => [:show, :new, :destroy] do resources :likes, :only => [:create, :destroy, :index] resources :participations, :only => [:create, :destroy, :index] resources :comments, :only => [:new, :create, :destroy, :index] diff --git a/features/step_definitions/trumpeter_steps.rb b/features/step_definitions/trumpeter_steps.rb new file mode 100644 index 0000000000..a3b32a59f7 --- /dev/null +++ b/features/step_definitions/trumpeter_steps.rb @@ -0,0 +1,7 @@ +When /^I trumpet$/ do + visit new_post_path +end + +When /^I write "([^"]*)"$/ do |text| + fill_in :text, :with => text +end diff --git a/features/trumpeter.feature b/features/trumpeter.feature new file mode 100644 index 0000000000..28a8b02880 --- /dev/null +++ b/features/trumpeter.feature @@ -0,0 +1,12 @@ +@javascript +Feature: Creating a new post + Background: + Given a user with username "bob" + And I sign in as "bob@bob.bob" + + Scenario: Posting a public message + When I trumpet + And I write "Rectangles are awesome" + And I press "Share" +# When I go to the stream page +# Then I should see "Rectangles are awesome" as the first post in my stream diff --git a/public/javascripts/app/pages/post-new.js b/public/javascripts/app/pages/post-new.js new file mode 100644 index 0000000000..339f194243 --- /dev/null +++ b/public/javascripts/app/pages/post-new.js @@ -0,0 +1,12 @@ +app.pages.PostNew = app.views.Base.extend({ + templateName : "post-new", + + subviews : { "#new-post" : "postForm"}, + + initialize : function(){ + console.log("In the page") + + this.model = new app.models.Post() + this.postForm = new app.views.PostForm({model : this.model}) + } +}) diff --git a/public/javascripts/app/router.js b/public/javascripts/app/router.js index 30d12cc7db..d56ece7c7b 100644 --- a/public/javascripts/app/router.js +++ b/public/javascripts/app/router.js @@ -16,6 +16,7 @@ app.Router = Backbone.Router.extend({ "followed_tags": "stream", "tags/:name": "stream", + "posts/new" : "newPost", "posts/:id": "singlePost", "p/:id": "singlePost" }, @@ -38,6 +39,11 @@ app.Router = Backbone.Router.extend({ $("#main_stream").html(app.page.el); }, + newPost : function(){ + var page = new app.pages.PostNew(); + $("#container").html(page.render().el) + }, + singlePost : function(id) { var page = new app.pages.PostViewer({ id: id }); $("#container").html(page.el); diff --git a/public/javascripts/app/templates/post-form.handlebars b/public/javascripts/app/templates/post-form.handlebars new file mode 100644 index 0000000000..4d5253c6ac --- /dev/null +++ b/public/javascripts/app/templates/post-form.handlebars @@ -0,0 +1,4 @@ +<form class="new-post"> + <label>text<textarea class="text"/></label> + <input type="submit" value="Share" class="btn-primary"></input> +</form> diff --git a/public/javascripts/app/templates/post-new.handlebars b/public/javascripts/app/templates/post-new.handlebars new file mode 100644 index 0000000000..444b344222 --- /dev/null +++ b/public/javascripts/app/templates/post-new.handlebars @@ -0,0 +1 @@ +<div id="new-post"></div> \ No newline at end of file diff --git a/public/javascripts/app/views/post_form_view.js b/public/javascripts/app/views/post_form_view.js new file mode 100644 index 0000000000..b451ae48b0 --- /dev/null +++ b/public/javascripts/app/views/post_form_view.js @@ -0,0 +1,12 @@ +app.views.PostForm = app.views.Base.extend({ + templateName : "post-form", + + initialize : function(){ + console.log("In the form") + }, + + postRenderTemplate: function(){ + console.log("I'm getting rendered") + } + +}); \ No newline at end of file diff --git a/spec/javascripts/app/pages/post_new_spec.js b/spec/javascripts/app/pages/post_new_spec.js new file mode 100644 index 0000000000..e0e13b39aa --- /dev/null +++ b/spec/javascripts/app/pages/post_new_spec.js @@ -0,0 +1,9 @@ +describe("app.pages.PostNew", function(){ + beforeEach(function(){ + this.page = new app.pages.PostNew() + }) + + it("renders", function(){ + this.page.render(); + }) +}); \ No newline at end of file diff --git a/spec/javascripts/app/views/post_form_spec.js b/spec/javascripts/app/views/post_form_spec.js new file mode 100644 index 0000000000..03bcbe2337 --- /dev/null +++ b/spec/javascripts/app/views/post_form_spec.js @@ -0,0 +1,10 @@ +describe("app.views.PostForm", function(){ + beforeEach(function(){ + this.post = new app.models.Post(); + this.view = new app.views.PostForm({model : this.post}) + }) + + it("renders", function(){ + this.view.render() + }) +}) \ No newline at end of file diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index 83fbd18746..9c29ffafdc 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -53,6 +53,7 @@ src_files: - public/javascripts/app/views/content_view.js - public/javascripts/app/views/*.js - public/javascripts/app/views/**/*.js + - public/javascripts/app/pages/**/*.js - public/javascripts/mobile.js - public/javascripts/contact-list.js -- GitLab