From ea58324aa8bb00b1d2a25572d22fc7655b3a8664 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Wed, 4 Dec 2013 20:08:54 -0200 Subject: [PATCH] remove template picker --- app/assets/javascripts/app/models/post.js | 19 +----- .../app/models/post/template_picker.js | 35 ---------- .../javascripts/app/views/post/mood_view.js | 66 ------------------- app/assets/javascripts/app/views/post_view.js | 34 ---------- features/support/post_generation_helpers.rb | 33 ---------- .../app/models/post/template_picker_spec.js | 56 ---------------- 6 files changed, 1 insertion(+), 242 deletions(-) delete mode 100644 app/assets/javascripts/app/models/post/template_picker.js delete mode 100644 app/assets/javascripts/app/views/post/mood_view.js delete mode 100644 features/support/post_generation_helpers.rb delete mode 100644 spec/javascripts/app/models/post/template_picker_spec.js diff --git a/app/assets/javascripts/app/models/post.js b/app/assets/javascripts/app/models/post.js index 12ba81cc5..51623c5ae 100644 --- a/app/assets/javascripts/app/models/post.js +++ b/app/assets/javascripts/app/models/post.js @@ -15,14 +15,6 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, } }, - setFrameName : function(){ - this.set({frame_name : new app.models.Post.TemplatePicker(this).getFrameName()}) - }, - - applicableTemplates: function() { - return new app.models.Post.TemplatePicker(this).applicableTemplates() - }, - interactedAt : function() { return this.timeOf("interacted_at"); }, @@ -67,13 +59,4 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, hasText : function(){ return $.trim(this.get("text")) !== "" } -}), { - headlineLimit : 118, - - frameMoods : [ - "Wallpaper", - "Vanilla", - "Typist", - "Fridge" - ] -}); +})); diff --git a/app/assets/javascripts/app/models/post/template_picker.js b/app/assets/javascripts/app/models/post/template_picker.js deleted file mode 100644 index faaa424a5..000000000 --- a/app/assets/javascripts/app/models/post/template_picker.js +++ /dev/null @@ -1,35 +0,0 @@ -//require ../post - -app.models.Post.TemplatePicker = function(model){ - this.model = model -} - -_.extend(app.models.Post.TemplatePicker.prototype, { - getFrameName : function getFrameName() { - var frameName - - if(this.isNewspaper()){ - frameName = "Typist" - } else if(this.isWallpaper()) { - frameName = "Wallpaper" - } else { - frameName = "Vanilla" - } - - return frameName - }, - - isNewspaper : function(){ - return this.model.get("text").length > 300 - }, - - isWallpaper : function(){ - return this.model.get("photos").length == 1 - }, - - applicableTemplates : function(){ - /* don't show the wallpaper option if there is no image */ - var moods = app.models.Post.frameMoods; - return (!this.isWallpaper() ? _.without(moods, "Wallpaper") : moods) - } -}); \ No newline at end of file diff --git a/app/assets/javascripts/app/views/post/mood_view.js b/app/assets/javascripts/app/views/post/mood_view.js deleted file mode 100644 index 14748bc3a..000000000 --- a/app/assets/javascripts/app/views/post/mood_view.js +++ /dev/null @@ -1,66 +0,0 @@ -//= require ../post_view -app.views.Post.Mood = app.views.Post.extend({ - templateName : "mood", - className : "post loaded", - tagName : "article", - subviews : { "section.photo_viewer" : "photoViewer" }, - - initialize : function(){ - $(this.el).addClass(this.mood) - }, - - presenter : function(){ - var model = this.model - return _.extend(this.defaultPresenter(), { - headline : $(app.helpers.textFormatter(model.headline(), model)).html(), - body : app.helpers.textFormatter(model.body(), model) - }) - }, - - photoViewer : function(){ - return new app.views.PhotoViewer({ model : this.model }) - }, - - postRenderTemplate : function(){ - if(this.model.body().length < 200){ - this.$('section.body').addClass('short_body'); - } - } -}); - -app.views.Post.Day = app.views.Post.Mood.extend({ - mood : "day" -}) - -app.views.Post.Night = app.views.Post.Mood.extend({ - mood : "night" -}) - -app.views.Post.Newspaper = app.views.Post.Mood.extend({ - mood : "newspaper" -}) - -app.views.Post.Wallpaper = app.views.Post.Mood.extend({ - mood : "wallpaper", - templateName : "wallpaper-mood", - - - presenter : function(){ - var backgroundPhoto = _.first(this.model.get("photos") || []) - return _.extend(app.views.Post.Mood.prototype.presenter.call(this), { - backgroundUrl : backgroundPhoto && backgroundPhoto.sizes.large - }) - } -}) - -app.views.Post.Typist = app.views.Post.Mood.extend({ - mood : "typist" -}) - -app.views.Post.Vanilla = app.views.Post.Mood.extend({ - mood : "vanilla" -}) - -app.views.Post.Fridge = app.views.Post.Mood.extend({ - mood : "fridge" -}) \ No newline at end of file diff --git a/app/assets/javascripts/app/views/post_view.js b/app/assets/javascripts/app/views/post_view.js index 7d3e25173..7d45e6bdf 100644 --- a/app/assets/javascripts/app/views/post_view.js +++ b/app/assets/javascripts/app/views/post_view.js @@ -14,38 +14,4 @@ app.views.Post = app.views.Base.extend({ showPost : function() { return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw") } -}, { //static methods below - - showFactory : function(model) { - var frameName = model.get("frame_name"); - - //translate obsolete template names to the new Moods, should be removed when template picker comes client side. - var map = { - 'status-with-photo-backdrop' : 'Wallpaper', //equivalent - 'status' : 'Day', //equivalent - 'note' : 'Newspaper', //equivalent - 'photo-backdrop' : 'Day' //that theme was bad - } - - frameName = map[frameName] || frameName - - return new app.views.Post[frameName]({ - model : model - }) - - function legacyShow(model) { - return new app.views.Post.Legacy({ - model : model, - className : frameName + " post loaded", - templateName : "post-viewer/content/" + frameName - }); - } - } }); - -app.views.Post.Legacy = app.views.Post.extend({ - tagName : "article", - initialize : function(options) { - this.templateName = options.templateName || this.templateName - } -}) diff --git a/features/support/post_generation_helpers.rb b/features/support/post_generation_helpers.rb deleted file mode 100644 index 50bdab55e..000000000 --- a/features/support/post_generation_helpers.rb +++ /dev/null @@ -1,33 +0,0 @@ -module PostGenerationHelpers - - def generate_post_of_each_template(user) - time = Time.now - - TemplatePicker::TEMPLATES.each do |template| - Timecop.travel time += 1.minute - FactoryGirl.create(template, :author => user.person) - end - - Timecop.return - end - - def visit_posts_and_collect_template_names(user) - visit(post_path(user.posts.last)) - user.posts.map do |post| - sleep 0.25 - post = find('.post') - template_name = post['data-template'] - click_next_button - template_name - end - end - - def click_next_button - next_arrow = '.nav-arrow.right' - if page.has_selector?(next_arrow) - find(next_arrow).click() - end - end -end - -World(PostGenerationHelpers) diff --git a/spec/javascripts/app/models/post/template_picker_spec.js b/spec/javascripts/app/models/post/template_picker_spec.js deleted file mode 100644 index aca0c74b7..000000000 --- a/spec/javascripts/app/models/post/template_picker_spec.js +++ /dev/null @@ -1,56 +0,0 @@ -describe("app.models.Post.TemplatePicker", function(){ - beforeEach(function(){ - this.post = factory.statusMessage({frame_name: undefined, text : "Lol this is a post"}) - this.templatePicker = new app.models.Post.TemplatePicker(this.post) - }) - - describe("getFrameName", function(){ - context("when the model has hella text", function(){ - beforeEach(function(){ - this.post.set({text : window.hipsterIpsumFourParagraphs }) - }) - - it("returns Typist", function(){ - expect(this.templatePicker.getFrameName()).toBe("Typist") - }) - }) - - context("when the model has photos:", function(){ - context("one photo", function(){ - beforeEach(function(){ - this.post.set({photos : [factory.photoAttrs()]}) - }) - - it("returns Wallpaper", function(){ - expect(this.templatePicker.getFrameName()).toBe("Wallpaper") - }) - }) - - context("two photos", function(){ - beforeEach(function(){ - this.post.set({photos : [factory.photoAttrs(), factory.photoAttrs()]}) - }) - - it("returns Vanilla", function(){ - expect(this.templatePicker.getFrameName()).toBe("Vanilla") - }) - }) - - it("returns 'Vanilla' by default", function(){ - expect(this.templatePicker.getFrameName()).toBe("Vanilla") - }) - }) - }) - - describe("applicableTemplates", function(){ - it("includes wallpaper if isWallpaper is true", function(){ - spyOn(this.templatePicker, "isWallpaper").andReturn(true) - expect(_.include(this.templatePicker.applicableTemplates(), "Wallpaper")).toBeTruthy() - }) - - it("does not include wallpaper if isWallpaper is false", function(){ - spyOn(this.templatePicker, "isWallpaper").andReturn(false) - expect(_.include(this.templatePicker.applicableTemplates(), "Wallpaper")).toBeFalsy() - }) - }) -})