Skip to content

Instantly share code, notes, and snippets.

@trabus
trabus / gist:0a3d100aedc21e9b338f
Last active August 29, 2015 14:17
Resolver ideas to work with pods and structures

Resolver Idea for Structures

Resolver rules don't belong in structures

Structures don't need to have the lookup pattern defined in them, they should instead conform to available patterns provided by the resolver. The issue is that the resolver deals with compiled modules, and structures are for pre-compilation. The resolver does have a role in how structures should work, but it shouldn't be coupled to the way the structure is defined. The difficulty of getting the resolver rules out of the structure and into the resolver also shows that it's not the right path.

The resolver could use a hash to resolve different types, defining the prefix to use for each, as well as the structures supported (implied by the prefix). For this example let's assume there is no 'pods' folder, but rather the prefix describes the structure used in the folder. We should also assume that modules of a specific type are only generated in pod or type structure, not both. This config example is a bit contrived, and doesn't take in

@trabus
trabus / gist:6c2ecfbd8e5145e7b328
Last active April 16, 2018 11:01
Pods in ember-cli

Overview

Pods are a type of file organization structure in ember-cli. They allow you to gather related modules and assets together in your file structure. Currently pod structured modules can live side by side with your basic modules because the resolver that ships with ember-cli will look up your path in pod structure, and then fall back to basic structure if no paths are resolved.

Soon there will be a point where some blueprints will only generate in pod structure, and others will only generate in basic structure. This will allow us to collect a list of types that support each lookup structure and only need to lookup modules once. This will also cause less ambiguity around what a project structure looks like.

TLDR

My opinion on pods is that they should not live in the same namespace as type based modules. We should re-appropriate 'components',' models', and 'routes' (or 'resources') as pod prefixes to house the concerns of global ui, data, and route specific ui, respectively. Everything else stays th

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
var get = Ember.get, set = Ember.set, doc = document;
var FastSelectComponent = Ember.Component.extend({
items: null,
valuePath: 'value',
labelPath: 'label',
value: null,
selected: null,
tagName: 'select',
@trabus
trabus / gist:f8bfa2cdd2d7c45701d0
Created July 8, 2014 18:21
Brocfile change output directory
/*
Simply modify the output after calling app.toTree(). The final destination is completely up to you.
Something like the following in your Brocfile:
*/
var pickFiles = require('broccoli-static-compiler');
// default app = new EmberApp stuff here
var appTree = app.toTree();
define(
['ember', 'app'],
function(Em, App){
/*
Mobile template resolver (borrowed from Discourse)
If the app is in mobile mode, it will look for a mobile template instead
*/
App.Resolver = Em.DefaultResolver.extend({
resolveTemplate: function(parsedName){
var t = this._super();
@trabus
trabus / gist:9516907
Last active December 16, 2015 21:40
Detect IE version
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@trabus
trabus / embed.js
Created January 5, 2014 06:40
Discourse embed code
/* global discourseUrl */
/* global discourseEmbedUrl */
(function() {
var comments = document.getElementById('discourse-comments'),
iframe = document.createElement('iframe');
iframe.src = discourseUrl + "embed/comments?embed_url=" + encodeURIComponent(discourseEmbedUrl);
iframe.id = 'discourse-embed-frame';
iframe.width = "100%";
iframe.frameBorder = "0";
@trabus
trabus / gist:8001480
Created December 17, 2013 07:49
Using Isotope.js with Ember.js
// Controller
App.SomeController = Ember.ArrayController.extend({
items: []
});
// View
App.SomeView = Ember.View.extend({
// this will be run once the didInsertElement event occurs, and any time an item is added
initIsotope: function(){
// use the run loop to execute after rendering is complete
@trabus
trabus / grunt-contrib-copy config
Last active December 15, 2015 14:49
Matches all files and folders in path 'foo' but excludes folders and subfolders starting with an underscore
copy: {
main: {
files: [
{src: ['foo/**', '!**/_*/**'], dest:'temp/'}
]
}
}