Skip to content

Instantly share code, notes, and snippets.

View bazzel's full-sized avatar

Patrick Baselier bazzel

  • Oisterwijk, The Netherlands
View GitHub Profile
@bazzel
bazzel / ember-infinite-scroll.js.coffee
Created February 9, 2014 21:06
Infinite scroll with Ember.js and Ruby on Rails - These Ember Mixins are used by my Rails template for setting up infinite scrolling with Ember.js and Ruby on Rails. The template is located here https://github.com/bazzel/rails-templates/blob/master/ember-infinite-scroll.rb
InfiniteScroll =
ControllerMixin: Ember.Mixin.create(
hasMore: (->
@meta('page') < @meta('total_pages')
).property('@each')
meta: (key) ->
@store.metadataFor(@_type())[key]
loadMore: ->
@bazzel
bazzel / ember-list-view.js.coffee
Last active August 29, 2015 13:56
Ember.ListView mixins - for changing height and width of Ember.ListView during runtime
# This mixin can be used to extend a ListView class to adjust its width and height when resizing
# the browser. The dimensions of the ListView are synchronized with the width and height
# of the parent element that contains the ListView.
#
# Although this mixin sets the width and height you still have to define these properties when
# defining the ListView class.
#
# example:
# App.ListView = Ember.ListView.extend ListView.ListViewMixin,
# width: 100
<header class='landing'>
<img src='images/logo.png'>
</header>
<section class='landing-wrapper'>
<div class='landing-content'>
<h1 class='section-heading'>Ember <em>work</em>Shop</h1>
<p class='lead'>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid, suscipit, rerum quos facilis repellat architecto commodi officia atque nemo facere eum non illo voluptatem quae delectus odit vel itaque amet.</p>
</div>
<div class="jumbotron">
<h1>Ember <em>work</em>Shop</h1>
<p>Select a product to view the details.</p>
</div>
<form role='form' class='well'>
<div class='form-group'>
{{input value=title class='form-control' placeholder='Enter a title'}}
</div>
<div class='form-group'>
{{textarea value=description class='form-control' placeholder='Enter a description'}}
</div>
<div class='form-group'>
{{input value=price class='form-control' type='number' placeholder='Enter a price'}}
</div>
<div class='form-group'>
{{#if image}}
<img {{bind-attr src=image}}/>
<button type='button' class='remove pull-right'>Remove</button>
{{else}}
<img src='http://placehold.it/320x150&text=No image'>
{{/if}}
<div class='file'>
Browse...<input type='file' accept='image/*'>
</div>
import Ember from 'ember';
export default Ember.ObjectController.extend({
isEditing: false,
actions: {
toggleEditing: function() {
this.toggleProperty('isEditing');
this.resetModel();
},
submit: function() {
{{#each starred}}
<span class="glyphicon glyphicon-star"></span>
{{/each}}
{{#each unstarred}}
<span class="glyphicon glyphicon-star-empty"></span>
{{/each}}
import DS from 'ember-data';
export default DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
category: {embedded: 'always'}
}
});
@bazzel
bazzel / related1.rb
Last active September 8, 2015 19:25
Related posts, before and after
def similar_posts(post)
related_posts(post).tap do |posts|
(posts << @posts.first(2)).flatten!
end.first(2)
end
def related_posts(post)
categories_ids = post.categories.map(&:id)
@posts.select do |p|