remove template picker
This commit is contained in:
parent
6c8c4fc99e
commit
ea58324aa8
6 changed files with 1 additions and 242 deletions
|
|
@ -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() {
|
interactedAt : function() {
|
||||||
return this.timeOf("interacted_at");
|
return this.timeOf("interacted_at");
|
||||||
},
|
},
|
||||||
|
|
@ -67,13 +59,4 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
|
||||||
hasText : function(){
|
hasText : function(){
|
||||||
return $.trim(this.get("text")) !== ""
|
return $.trim(this.get("text")) !== ""
|
||||||
}
|
}
|
||||||
}), {
|
}));
|
||||||
headlineLimit : 118,
|
|
||||||
|
|
||||||
frameMoods : [
|
|
||||||
"Wallpaper",
|
|
||||||
"Vanilla",
|
|
||||||
"Typist",
|
|
||||||
"Fridge"
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -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"
|
|
||||||
})
|
|
||||||
|
|
@ -14,38 +14,4 @@ app.views.Post = app.views.Base.extend({
|
||||||
showPost : function() {
|
showPost : function() {
|
||||||
return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw")
|
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
|
|
@ -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()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Loading…
Reference in a new issue