Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kossnocorp/pipegems
base: 9ec59fcd6f
...
head fork: kossnocorp/pipegems
compare: dc41964e10
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
1  Gemfile
@@ -15,7 +15,6 @@ gem 'inherited_resources', '~> 1.3.0'
gem 'cancan', git: 'git://github.com/ryanb/cancan.git', branch: '2.0'
gem 'jquery-rails', '~> 2.0.2'
-gem 'ember-rails', '~> 0.2.4'
gem 'strip_attributes', git: 'git://github.com/mkaschenko/strip_attributes.git', branch: 'shoulda_matchers_support'
View
4 Gemfile.lock
@@ -82,9 +82,6 @@ GEM
diff-lcs (1.1.3)
draper (0.11.1)
activesupport (>= 2.3.10)
- ember-rails (0.2.4)
- execjs (>= 1.2)
- railties (>= 3.0)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
@@ -241,7 +238,6 @@ DEPENDENCIES
database_cleaner (~> 0.7.1)
devise (~> 2.0.0)
draper (~> 0.11.1)
- ember-rails (~> 0.2.4)
fabrication (~> 1.2.0)
guard-bundler (~> 0.1.3)
guard-rspec (~> 0.6.0)
View
39 app/assets/javascripts/framework/component.coffee
@@ -0,0 +1,39 @@
+class Framework.Component extends Framework.Module
+
+ @setComponentName: (@componentName) -> @prototype.componentName = @componentName
+
+ controller: (controllerName, options...) ->
+ throw "Controller name should be a string, #{typeof(controllerName)} given." unless typeof(controllerName) == 'string'
+
+ # bring controllerName to 'SomeNameController' like
+ controllerName += '_controller' unless !!/controller$/i.exec(controllerName)
+ controllerName = _(controllerName).classify()
+
+ # get controller object
+ controllerObj = eval("App.#{@componentName}.#{controllerName}")
+
+ controllerObj.setComponent(@)
+ controllerObj.setControllerName(controllerName)
+
+ # create, initialize and return controller
+ new controllerObj(options...)
+
+ view: (viewName, options...) ->
+ throw "View name should be a string, #{typeof(viewName)} given." unless typeof(viewName) == 'string'
+ viewName += '_view' unless !!/view$/i.exec(viewName)
+ viewName = _(viewName).classify()
+ viewObj = eval("App.#{@componentName}.#{viewName}")
+ viewObj.setComponent(@)
+ viewObj.setViewName(@viewName)
+ new viewObj(options...)
+
+ pub: ->
+ pub.apply(null, arguments)
+
+
+ sub: (message, fn, priority = 10) ->
+ sub(message, @, fn, priority)
+
+
+ unsub: (message, fn) ->
+ unsub(message, fn)
View
87 app/assets/javascripts/framework/controller.coffee
@@ -0,0 +1,87 @@
+class Framework.Controller extends Framework.Module
+
+ @setControllerName: (@controllerName) -> @prototype.controllerName = @controllerName
+ @setComponent: (@component) -> @prototype.component = @component
+
+ @modules: (args...) ->
+ @::attachedModules = if _(args[0]).isArray()
+ args[0]
+ else if /\s/.test(args[0])
+ args[0].split(/\s/)
+ else if /\n/.test(args[0])
+ args[0].split(/\n/)
+ else
+ args
+
+
+ constructor: ->
+ @initializeModules()
+
+ super
+
+
+ destructor: ->
+ module.destroy?() for own module of @modules
+
+ destroy?()
+
+
+ initializeModules: ->
+ return unless @attachedModules?
+
+ @modules ?= {}
+
+ componentClass = _(@componentName).classify() + 'Component'
+
+ for module in @attachedModules
+ do (module) =>
+
+ options = {}
+ moduleStr = _(module).classify()
+ moduleName = moduleStr + 'Module'
+
+ if (initializeFn = @['initialize' + moduleStr])?
+ canceled = false
+ returned = initializeFn(cancel: -> canceled = true)
+
+ options = returned if typeof returned == 'object'
+
+ return if canceled
+
+ if not (moduleClass = window[componentClass][moduleName])? and
+ not (moduleClass = Shared[moduleName])?
+
+ for key, namespace of Shared
+ moduleClass = namespace[moduleName] if namespace[moduleName]?
+
+ unless moduleClass?
+ throw "Module \"#{moduleName}\" is not found"
+
+ moduleAPI = @modules[_(module).camelize()] = moduleClass(options)
+
+ @bindModuleEvents(moduleAPI, moduleStr)
+
+ moduleAPI.afterBinds?()
+
+
+ bindModuleEvents: (moduleAPI, moduleStr) ->
+ re = new RegExp("on#{moduleStr}(.+)")
+
+ for fnName, callback of @constructor.prototype
+
+ continue if not _(callback).isFunction() or not re.test(fnName)
+
+ event = _(fnName.match(re)[0]).underscored()
+ moduleAPI.bind(event, _(callback).bind(@))
+
+
+ pub: ->
+ pub.apply(null, arguments)
+
+
+ sub: (message, fn, priority = 10) ->
+ sub(message, @, fn, priority)
+
+
+ unsub: (message, fn) ->
+ unsub(message, fn)
View
9 app/assets/javascripts/framework/controller_module.coffee
@@ -0,0 +1,9 @@
+Framework.ControllerModule = (moduleFn) ->
+
+ # Return controller module constructor
+ (options = {}) =>
+ api = new Framework.Module()
+ moduleApi = moduleFn(api, options)
+
+ # Return module public API extended with Framework.Module
+ _.extend({}, api, moduleApi)
View
17 app/assets/javascripts/framework/events.coffee
@@ -0,0 +1,17 @@
+Framework.Events = ->
+
+ events = []
+
+
+ bind: (event, callback) ->
+ events[event] ?= []
+ events[event].push(callback)
+
+
+ trigger: (event, args...) ->
+ callback.apply(null, args) for callback in events[event]
+
+
+ unbind: (event, callback) ->
+ # TODO: Find better way to do this (coz _.without returns copy)
+ events[event] = _(events[event]).without(callback)
View
24 app/assets/javascripts/framework/index.coffee
@@ -0,0 +1,24 @@
+#= require_self
+#= require ./module
+#= require_tree ./
+
+@Framework = {}
+
+@Framework.component = (componentName, options...) ->
+ @components = {} unless @components?
+
+ throw "Component name should be a string, #{typeof(componentName)} given." unless typeof(componentName) == 'string'
+
+ componentName += '_component' unless !!/component$/i.exec(componentName)
+ componentName = _(componentName).classify()
+
+ # if we already create this component, just return it
+ return @components[componentName] if @components[componentName]?
+
+ # get component object
+ componentObj = eval("App.#{componentName}")
+
+ componentObj.setComponentName(componentName)
+
+ # create, initialize and return component
+ @components[componentName] = new componentObj(options...)
View
14 app/assets/javascripts/framework/model.coffee
@@ -0,0 +1,14 @@
+class Framework.Model extends Framework.Module
+
+ @create: (data) ->
+ @ensureCollectionExist()
+
+ new @(data)
+
+
+ @ensureCollectionExist: ->
+ @collection ?= {}
+
+
+ constructor: (data) ->
+ _.extend(@, data)
View
22 app/assets/javascripts/framework/module.coffee
@@ -0,0 +1,22 @@
+class Framework.Module
+
+ ## Class functions
+
+ @delegate: (args..., options) ->
+ for fnName in args
+ do (fnName) =>
+ @::[fnName] = -> @[options.to][fnName].apply(@[options.to], arguments)
+
+
+ @delegate('bind', 'unbind', 'trigger', to: 'events')
+
+ ## Instance functions
+
+ constructor: ->
+ @uid = _.uniqueId('.')
+
+ # TODO: Move creation of Events to @delegate:
+ # @delegate(..., to: -> Framework.Events())
+ @events = Framework.Events()
+
+ @initialize?.apply(@, arguments)
View
118 app/assets/javascripts/framework/view.coffee
@@ -0,0 +1,118 @@
+JQUERY_EVENTS = '''
+ blur
+ change
+ click
+ dblclick
+ focus
+ focusin
+ focusout
+ keydown
+ keypress
+ keyup
+ load
+ mousedown
+ mouseenter
+ mouseleave
+ mousemove
+ mouseout
+ mouseover
+ mouseup
+ ready
+ resize
+ scroll
+ select
+ submit
+ unload
+'''.split("\n")
+
+CALLBACK_REGEXP = /([a-z]+)(?:On|Of|To|From|In)([A-Z].*)/
+
+class Framework.View extends Framework.Module
+
+ @delegate('appendTo', 'append', 'prepend', 'prependTo', to: 'el')
+
+ @setViewName: (@viewName) -> @prototype.viewName = @viewName
+ @setComponent: (@component) -> @prototype.component = @component
+
+ constructor: ->
+ if not @componentName? and @component?
+ @componentName = _(
+ @component.componentName.replace('Component', '')
+ ).underscored()
+
+ @templatesPaths = @getTemplatesPaths()
+ @buildHelpersObject()
+ super
+
+
+ # Returns paths to templates
+ getTemplatesPaths: ->
+ sharedPaths = _(JST)
+ .chain()
+ .map((v, k) ->
+ k.match(/(.+\/).+$/)[1] if k.match('app/components/shared')
+ )
+ .uniq()
+ .compact()
+ .value()
+
+ _.union(
+ ["app/components/#{@componentName}/templates/"]
+ sharedPaths
+ )
+
+
+ # Build helpers object
+ buildHelpersObject: ->
+ @helpersObject = {}
+
+ _(@helpersObject).extend(@getPartialsHelper())
+
+ for componentName, componentClass of App
+ for className, klass of componentClass
+ _(@helpersObject).extend(klass) if /^.+Helper$/.test(className)
+
+
+ # Returns object with partials mechanism
+ getPartialsHelper: ->
+ render: (name, object) => @renderHTML('_' + name, object)
+
+
+ # Render template
+ renderHTML: (name, object = {}) ->
+ for templatesPath in @templatesPaths
+ if (jstTemplate = JST[templatesPath + name])?
+ return jstTemplate(
+ _.extend({}, object, @helpersObject)
+ )
+
+ throw "Template \"#{name}\" is not found"
+
+
+ # Render template (returns jQuery object)
+ renderTemplate: ->
+ return $(@renderHTML.apply(@, arguments))
+
+
+ # Delegate events
+ delegateEvents: ->
+ for fnName, callback of @constructor.prototype
+ continue unless _(callback).isFunction()
+
+ callbackMatch = fnName.match(CALLBACK_REGEXP)
+
+ continue unless callbackMatch?
+
+ [event, role] = _(callbackMatch).last(2)
+
+ bindedCallback = _(callback).bind(@)
+
+ if _(JQUERY_EVENTS).include(event)
+ roleString = _(role).underscored()
+ if roleString == 'this'
+ @el.bind(event, bindedCallback)
+ else
+ @el.delegate('@' + roleString, event, bindedCallback)
+
+
+ $: (selector) -> @el.find(selector)

No commit comments for this range

Something went wrong with that request. Please try again.