Permalink
Browse files

added a lot of style related classes

  • Loading branch information...
collin committed Aug 7, 2012
1 parent 9906b82 commit 05c328b397309ad5fff90281d18fa3306212d84a
Showing with 2,201 additions and 595 deletions.
  1. +1 −1 .rvmrc
  2. +3 −1 Gemfile
  3. +3 −0 Gemfile.lock
  4. +1 −0 Procfile.build
  5. +5 −2 alpha_simprini.erb
  6. +64 −0 autobuild.watchr
  7. +1 −1 examples/todo/todo.coffee
  8. +3 −1 src/alpha_simprini.coffee
  9. +5 −3 src/alpha_simprini/client.coffee
  10. +117 −43 src/alpha_simprini/client/application.coffee
  11. +1 −1 src/alpha_simprini/client/binding.coffee
  12. +30 −22 src/alpha_simprini/client/binding/edit_line.coffee
  13. +27 −0 src/alpha_simprini/client/binding/if.coffee
  14. +3 −1 src/alpha_simprini/client/binding/input.coffee
  15. +10 −6 src/alpha_simprini/client/binding/many.coffee
  16. +8 −8 src/alpha_simprini/client/binding/model.coffee
  17. +5 −3 src/alpha_simprini/client/binding_group.coffee
  18. +10 −4 src/alpha_simprini/client/dom.coffee
  19. +56 −0 src/alpha_simprini/client/key_router.coffee
  20. +20 −2 src/alpha_simprini/client/view.coffee
  21. +6 −0 src/alpha_simprini/client/view_model.coffee
  22. +3 −1 src/alpha_simprini/client/views/dialog.coffee
  23. +19 −2 src/alpha_simprini/core.coffee
  24. +27 −19 src/alpha_simprini/core/collection.coffee
  25. +2 −13 src/alpha_simprini/core/filtered_collection.coffee
  26. +8 −0 src/alpha_simprini/core/logging.coffee
  27. +86 −4 src/alpha_simprini/core/model.coffee
  28. +4 −8 src/alpha_simprini/core/model/dendrite.coffee
  29. +86 −0 src/alpha_simprini/core/model/local.coffee
  30. +108 −0 src/alpha_simprini/core/model/post_message.coffee
  31. +245 −64 src/alpha_simprini/core/model/share.coffee
  32. +5 −0 src/alpha_simprini/core/model/synapse.coffee
  33. +1 −1 src/alpha_simprini/core/models/grouping.coffee
  34. +11 −2 src/alpha_simprini/core/models/multiple_selection_model.coffee
  35. +4 −3 src/alpha_simprini/core/models/radio_selection_model.coffee
  36. +9 −1 src/alpha_simprini/core/properties/belongs_to.coffee
  37. +60 −39 src/alpha_simprini/core/properties/field.coffee
  38. +47 −15 src/alpha_simprini/core/properties/has_many.coffee
  39. +10 −2 src/alpha_simprini/core/properties/has_one.coffee
  40. +10 −1 src/alpha_simprini/core/properties/virtual_property.coffee
  41. +15 −0 src/alpha_simprini/css.coffee
  42. +2 −0 src/alpha_simprini/css/models/angle.coffee
  43. +21 −0 src/alpha_simprini/css/models/color.coffee
  44. +2 −0 src/alpha_simprini/css/models/color_stop.coffee
  45. +15 −0 src/alpha_simprini/css/models/color_stops.coffee
  46. +41 −0 src/alpha_simprini/css/models/font_family.coffee
  47. +7 −0 src/alpha_simprini/css/models/font_size.coffee
  48. +18 −0 src/alpha_simprini/css/models/length.coffee
  49. +3 −0 src/alpha_simprini/css/models/margin.coffee
  50. +3 −0 src/alpha_simprini/css/models/padding.coffee
  51. +2 −0 src/alpha_simprini/css/models/percent.coffee
  52. +5 −0 src/alpha_simprini/css/models/siding.coffee
  53. +41 −0 src/alpha_simprini/css/views/angle_picker.coffee
  54. +15 −0 src/alpha_simprini/css/views/color_picker.coffee
  55. +75 −0 src/alpha_simprini/css/views/color_stop_picker.coffee
  56. +67 −0 src/alpha_simprini/css/views/dialogs/color.coffee
  57. +7 −0 src/alpha_simprini/keyboard.coffee
  58. +17 −0 src/alpha_simprini/keyboard/models/zone.coffee
  59. +41 −0 src/alpha_simprini/keyboard/models/zone_controller.coffee
  60. +50 −0 src/alpha_simprini/keyboard/models/zone_group.coffee
  61. +10 −0 src/alpha_simprini/keyboard/views/destructable.coffee
  62. +26 −0 src/alpha_simprini/keyboard/views/keyboard_navigation.coffee
  63. +11 −0 src/alpha_simprini/keyboard/views/selectable.coffee
  64. +6 −0 src/alpha_simprini/keyboard/views/zone.coffee
  65. +1 −0 test/client/application.coffee
  66. +2 −0 test/client/binding/check_box.coffee
  67. +60 −0 test/client/binding/field.coffee
  68. +1 −0 test/client/binding/input.coffee
  69. +10 −2 test/client/binding/many.coffee
  70. +2 −0 test/client/binding/model.coffee
  71. +1 −0 test/client/binding/one.coffee
  72. +2 −2 test/client/binding/select.coffee
  73. +2 −2 test/client/binding_group.coffee
  74. +3 −0 test/client/models/targets.coffee
  75. +8 −4 test/client/view.coffee
  76. +1 −1 test/client/view_events.coffee
  77. +1 −1 test/core.coffee
  78. +19 −7 test/core/collection.coffee
  79. +24 −12 test/core/filtered_collection.coffee
  80. +231 −231 test/core/model/share.coffee
  81. +5 −1 test/core/models/grouping.coffee
  82. +40 −7 test/core/properties/belongs_to.coffee
  83. +31 −15 test/core/properties/field.coffee
  84. +87 −28 test/core/properties/has_many.coffee
  85. +28 −0 test/core/properties/has_one.coffee
  86. +11 −1 test/core/properties/virtual_property.coffee
  87. +7 −7 test/helper.coffee
View
2 .rvmrc
@@ -1 +1 @@
-rvm use 1.9.2-p290
+rvm 1.9.3
View
@@ -8,4 +8,6 @@ gem "uglifier", "~> 1.0.3"
gem "coffee-script"
gem "github_uploader", "~> 0.1.0", require: false
gem "html_package", "~> 0.0.3"
-gem "tilt"
+gem "tilt"
+gem "rake"
+gem "watchr"
View
@@ -56,6 +56,7 @@ GEM
uglifier (1.0.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ watchr (0.7)
PLATFORMS
ruby
@@ -65,7 +66,9 @@ DEPENDENCIES
colored
github_uploader (~> 0.1.0)
html_package (~> 0.0.3)
+ rake
rake-pipeline!
rake-pipeline-web-filters!
tilt
uglifier (~> 1.0.3)
+ watchr
View
@@ -0,0 +1 @@
+watchr: watchr autobuild.watchr
View
@@ -19,10 +19,10 @@
href="http://spader.herokuapp.com/spades/jwerty-0.3.0.js">
<link rel="dependency" type="text/package+html"
- href="http://cloud.github.com/downloads/collin/pathology/pathology-0.3.0.html">
+ href="http://cloud.github.com/downloads/collin/pathology/pathology-0.3.1.html">
<link rel="dependency" type="text/package+html"
- href="http://cloud.github.com/downloads/collin/knead/knead-0.3.1.html">
+ href="http://cloud.github.com/downloads/collin/knead/knead-0.3.3.html">
<link rel="dependency" type="text/package+html"
href="http://cloud.github.com/downloads/collin/taxi/taxi-0.3.1.html">
@@ -42,6 +42,9 @@
<link rel="dependency" type="text/spade+javascript"
href="http://spader.herokuapp.com/spades/rangy-core-1.2.3.js">
+ <link rel="dependency" type="text/spade+javascript"
+ herf="http://spader.herokuapp.com/spades/jPicker-1.1.6.js">
+
<!-- DEVELOPMENT DEPENDENCIES -->
<link rel="development-dependency" type="text/spade+javascript"
View
@@ -0,0 +1,64 @@
+# def run_all_tests
+# print `clear`
+# puts "Tests run #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
+# test_files = `find test |grep coffee | tr "\\n" " "`
+# cleaned = test_files.split(" ").reject{|path| path["helper"]}.join(" ")
+# puts "nodeunit #{cleaned}"
+# puts `nodeunit #{cleaned}`
+# end
+
+# def run_tests(m)
+# return if m.to_s["helper"]
+# print `clear`
+# puts "Tests run @ #{m} an #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
+# puts `nodeunit #{m}`
+# end
+
+# run_all_tests
+# watch("(lib)(/.*)+.coffee") { |m|
+# hit = m.to_s
+# hit.gsub!(/^lib\/alpha_simprini/, "test")
+# run_tests(hit)
+# }
+# watch("(test)(/.*)+.coffee") { |m| run_tests(m) }
+
+require "rake"
+load File.expand_path("./Rakefile")
+
+def build
+ Rake::Task["build"].reenable
+ Rake::Task["build"].invoke
+end
+
+watch "(test)(/.*)+.coffee" do |match|
+ hit = match.to_s
+ puts hit
+ puts hit =~ /tmp/
+ return if hit["tmp"]
+ puts "coffee -co tmp/#{File.dirname hit} #{hit}"
+ system "coffee -co tmp/#{File.dirname hit} #{hit}"
+ build
+end
+
+watch "(src)(/.*)+.coffee" do |match|
+ hit = match.to_s
+ puts "coffee -co #{File.dirname hit.sub('src', 'lib')} #{hit}"
+ system "coffee -co #{File.dirname hit.sub('src', 'lib')} #{hit}"
+ build
+end
+
+@interrupted = false
+
+# Ctrl-C
+Signal.trap "INT" do
+ if @interrupted
+ abort("\n")
+ else
+ puts "Interrupt a second time to quit"
+ @interrupted = true
+ Kernel.sleep 1.5
+
+ # run_all_tests
+ @interrupted = false
+ end
+end
@@ -64,7 +64,7 @@ class Todo.Models.Item extends AS.Model
@field "task", default: "Something to do..."
# #### Field types.
# A field may have a type. This field is a boolean field.
- @field "done", type: Boolean, default: false
+ @field "done", type: AS.Model.Boolean, default: false
# ### Todo.Views.List
class Todo.Views.List extends AS.View
@@ -25,6 +25,8 @@ AS.Map = Pathology.Map
AS.Module = Pathology.Module
AS.Namespace = Pathology.Namespace
AS.Property = Taxi.Property
+AS.Property.Instance.def rawValue: -> @value
+
AS.COLLECTION_DELEGATES = ["first", "rest", "last", "compact", "flatten", "without", "union", "filter", "reverse",
"intersection", "difference", "uniq", "zip", "indexOf", "find", "detect", "sortBy",
@@ -35,7 +37,7 @@ AS.require = (framework="alpha_simprini", libraries) ->
require "alpha_simprini/#{framework}"
else
for library in libraries.split(/\s+/)
- continue if library.blank()
+ continue if library.match(/^\s+$/)
require "alpha_simprini/#{framework}/#{library}"
return
@@ -7,12 +7,14 @@ Client.require """
binding
binding/container
- binding/model binding/field binding/input binding/select binding/file
- binding/check_box binding/edit_line binding/one binding/many
+ binding/model binding/field binding/if binding/input binding/select
+ binding/file binding/check_box binding/edit_line binding/one binding/many
views/panel views/region views/dialog
models/targets
- application
+ application key_router
"""
+
+AS.require("keyboard")
@@ -1,85 +1,159 @@
-{each} = _
domready = jQuery
+{defer} = _
require("jwerty")
AS.Application = AS.Object.extend ({def, include}) ->
include Taxi.Mixin
def initialize: (config={}) ->
_.extend(this, config)
+ @stateObjects = {}
@params = AS.params
- @el ?= $("body")
- @godGivenKeyHandlers()
- domready =>
- @boot()
+
+ @keyRouter = AS.KeyRouter.new(this, document.body)
# @::initialize.doc =
# params: [
# []
# ]
# desc: """
- #
+ # Initializes the Application object. Setting up a ZoneController,
+ # states objects, and view objects.
# """
+ JQUERY_EVENTS = """
+ bind blur change click dblclick focus focusin focusout
+ keydown keypress keyup load mousedown mousenter mouseleave mousemove
+ mouseout mouseover mouseup ready resize scroll select submit load unload
+ """
+ def applyTo: (element) ->
+ @el = $(element)
+
+ _document = window.parent.document
+ for event in JQUERY_EVENTS.split(/\s+/)
+ continue if event.match(/^\s+$/)
+ jQuery(_document).on "#{event}.runloop", ->
+ defer -> Taxi.Governer.exit() if Taxi.Governer.currentLoop
+
+ jQuery(_document).ajaxSend ->
+ Taxi.Governer.exit() if Taxi.Governer.currentLoop
+
+ jQuery(_document).ajaxComplete ->
+ Taxi.Governer.exit() if Taxi.Governer.currentLoop
+
+ # FIXME: don't do this on applyTo
+ # would rather them happen on load, not on application
+ @connect()
+ @buildState()
+ @content()
+
+ AS.unbindGoverner = -> $(_document).unbind(".runloop")
- def boot: ->
- # @::boot.doc =
+ def connect: ->
+
+ # @::connect.doc =
+ # desc: """
+ # Override the connect method to instantiate to storage/connection adapters
+ # """
+
+ def buildState: ->
+ @state 'zoneController', AS.Models.ZoneController.new(application: this)
+ @state 'appZones', @zoneController.defaultZoneGroup.get()
+ # @::buildState.doc =
+ # desc: """
+ # Override this method to build your application state objects.
+ # """
+
+ def content: ->
+ # @::content.doc =
+ # desc: """
+ # Override this method to build your application view objects.
+ # """
+
+ def prepareModel: (id, _model) ->
+ path = _model.constructor.path()
+ constructor = AS.loadPath(path)
+ model = constructor.prepare(id: id, application: this)
+ console.log "[preparedModel] #{model.toString()}, #{model.id}"
+ # @::prepareModel.doc =
# params: [
- # []
+ # ["id", [String], true]
+ # ["model", AS.Model, true]
# ]
# desc: """
- #
+ # Prepare a model with the same id and constructor path
+ # as another model. Used when cutting over applications
+ # to an updated code base.
# """
- def godGivenKeyHandlers: ->
- handlers =
- '': 'escape'
- '⌘+↩': 'accept'
- 'backspace': 'delete'
-
- #TODO: add to test suite
- "": "open"
- "up": "up"
- "down": "down"
- "home": "first"
- "end": "last"
- "left": "left"
- "right": "right"
- "tab": "indent"
- "shift+tab": "dedent"
- "[a-z]/[0-9]/shift+[a-z]": "alphanum"
-
-
- each handlers, (trigger, key) =>
- jwerty.key key, ( (event) => @trigger(trigger, event) ), @el
-
- jwerty.key "backspace", (event) =>
- @trigger("delete", event)
- # @::godGivenKeyHandlers.doc =
+ def takeOverModel: (id, _model) ->
+ path = _model.constructor.path()
+ constructor = AS.loadPath(path)
+ model = constructor.find(id)
+ model.takeOver(_model)
+ # @::takeOverMadel.doc =
# params: [
- # []
+ # ["id", String, true, tag: "The id of the model to take over"]
+ # ["_model", AS.Model, true, tag: "The corresponding model to take over."]
# ]
# desc: """
- #
+ # Take over the properties of another model. Used to cut over applicatons
+ # to an updated code base.
+ # """
+
+ def takeOverState: (application) ->
+ for key, value of application.stateObjects
+ console.log "[takeOverState] #{key} => #{value.toString()}", value.id
+ @stateObjects[key] = @[key] = AS.Model.find(value.id)
+ # @::takeOverState.doc =
+ # params: [
+ # ["application", AS.Application, true, tag:"The application to take over."]
+ # ]
+ # desc: """
+ # Take aver the state objects of another application. Used when cutting over.
+ # """
+
+ def state: (name, constructor, options...) ->
+ return if @[name]?
+
+ stateObject = if constructor.new
+ constructor.new.apply(constructor, options)
+ else
+ constructor
+
+ @[name] = @stateObjects[name] = stateObject
+ # @::state.doc =
+ # desc: """
+ # Creates a state object in the application.
# """
def view: (constructor, options={}) ->
options.application = this
constructor.new options
# @::view.doc =
+ # desc: """
+ # Creates a view in the application.
+ # """
+
+ def zone: (name) ->
+ @appZones.add -> @object.application[name]
+ # @::zone.doc =
# params: [
- # []
+ # ["name", String, true,
+ # tag: """
+ # The name of a view in the application that will act as
+ # a navigation zone
+ # """]
# ]
# desc: """
- #
+ # Add a zone to the main application zone group. Lookup of application
+ # zones is extremely late-bound, so they must be referenced by name only.
+ # this is because zone state
# """
def append: (view) ->
@el.append view.el
# @::append.doc =
- # params: [
- # []
- # ]
# desc: """
- #
+ # Append a view's element to the application element.
# """
@@ -6,7 +6,7 @@ AS.Binding = AS.Object.extend ({def}) ->
if _.isFunction(@options)
[@fn, @options] = [@options, {}]
- @container ?= @context.$ @context.currentNode
+ @container ?= $ @context.currentNode
@bindingGroup = @context.bindingGroup
@content = @makeContent()
Oops, something went wrong.

0 comments on commit 05c328b

Please sign in to comment.