<% # TODO mover para helper base_path = Rails.root.join('app', 'assets', 'javascripts', 'resources') models_list = Dir.glob(Rails.root.join(base_path, '**', '*.js*')) models_list.map! do |file| file.sub! base_path.to_s + '/', '' # Ignore Emacs temporary files next nil if file =~ /~/ entries = file.split /\// || [] entries.unshift 'resources' entries.push File.basename entries.pop, '.js.coffee' File.join *entries end.compact! models_list.each do |model_file| require_asset model_file end %> 'use strict' define 'aura/extensions/resources', <%= models_list.to_json %>, (resources...) -> # TODO better require api for indemma indemma = require 'indefinido~indemma@master' require 'indefinido~indemma@master/lib/extensions/rivets.js' require 'indefinido~indemma@master/lib/record/rest.js' require 'indefinido~indemma@master/lib/record/associable.js' require 'indefinido~indemma@master/lib/record/storable.js' require 'indefinido~indemma@master/lib/record/persistable.js' require 'indefinido~indemma@master/lib/record/queryable.js' require 'indefinido~indemma@master/lib/record/scopable.js' require 'indefinido~indemma@master/lib/record/restfulable.js' require 'indefinido~indemma@master/lib/record/resource.js' require 'indefinido~indemma@master/lib/record/maid.js' require 'indefinido~indemma@master/lib/record/validatable.js' # TODO create an plurazation interface on indemma, or move # inflector outside it require 'indefinido~indemma@master/vendor/owl/pluralize.js' name: 'resources' version: '0.2.0' # Extension definition initialize: (application) -> {core, sandbox} = application core.util.inflector = cssify: (sentence) -> sentence.replace /\//, '-' pluralize: indemma.model.pluralize singularize: indemma.model.singularize # TODO create an plurazation interface on indemma, or move # inflector outside it define: owl.pluralize.define # TODO rename core.models, core.domain and core.resources to core.resourceable completely core.resourceable = core.resources = core.domain = core.models = sandbox.models = indemma.model core.resource = core.model = sandbox.resource = sandbox.model = (name) -> # TODO use a Map internally in indemma model = indemma.model[name] throw new TypeError "Resource not found with name: #{name}\nCheck for the definition on assets/javascripts/resources/#{name}.js.coffee" unless model? model # TODO rename core.models and core.domain, to core.resources, completely # TODO deprecate record usage core.domain.record = core.models.record = sandbox.models.record = indemma.record # TODO allow user to create custom definitions before resources # (models) get defined # new Aura(inflections: {measures: measures}) core.util.inflector.define 'measures', 'measures' # Build all model definitions indemma.model.every = [] # TODO implement this on indemma core.util._.map resources, (definition) -> resource = indemma.model.call definition indemma.model.every.push resource