Skip to content

Commit

Permalink
added basic example, seems to be working decently
Browse files Browse the repository at this point in the history
  • Loading branch information
datapimp committed Apr 6, 2013
1 parent bca04d3 commit 5131486
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 34 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -2,4 +2,6 @@
# the following line to use "https" # the following line to use "https"
source 'http://rubygems.org' source 'http://rubygems.org'


gem "middleman", "~>3.0.13" gem "middleman", "~>3.0.13"
gem "haml"
gem "sass"
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -97,4 +97,6 @@ PLATFORMS
ruby ruby


DEPENDENCIES DEPENDENCIES
haml
middleman (~> 3.0.13) middleman (~> 3.0.13)
sass
1 change: 1 addition & 0 deletions config.rb
@@ -1,3 +1,4 @@
require 'haml'
### ###
# Compass # Compass
### ###
Expand Down
10 changes: 0 additions & 10 deletions source/index.html.erb

This file was deleted.

Empty file added source/index.html.haml
Empty file.
5 changes: 5 additions & 0 deletions source/javascripts/example.coffee
@@ -0,0 +1,5 @@
launcher = KeyLauncher.on 'command+j', ()->
alert "is jquery loaded? #{ typeof(jQuery) is undefined }"
, requires:[
"http://code.jquery.com/jquery-1.9.1.min.js"
]
5 changes: 3 additions & 2 deletions source/javascripts/keylauncher.coffee
Expand Up @@ -6,12 +6,13 @@


KeyLauncher.VERSION = "0.0.1" KeyLauncher.VERSION = "0.0.1"


KeyLauncher.on = (keycommand, launchFn=->, options={})-> KeyLauncher.on = (keycommand, launchFn, options={})->
throw "Must specify a valid key command" unless keycommand? throw "Must specify a valid key command" unless keycommand?


launcher = new KeyLauncher.Launcher launcher = new KeyLauncher.Launcher
command: keycommand command: keycommand
fn: launchFn || -> fn: launchFn || ->
requires: options.requires || [] requires: options.requires || []


key(keycommand, launcher.run) key keycommand, ->
launcher.run.call(launcher)
18 changes: 17 additions & 1 deletion source/javascripts/keylauncher/launcher.coffee
@@ -1,17 +1,33 @@
# KeyLauncher.Launcher is an internal class that sets up the dependencies
# and then runs the specified function if they are all loaded
class window.KeyLauncher.Launcher class window.KeyLauncher.Launcher
_dependencies: {} _dependencies: {}


constructor: (@options={})-> constructor: (@options={})->
@fn = options.fn @fn = options.fn
@command = options.command @command = options.command

for dependency in @options.requires for dependency in @options.requires
@_dependencies[dependency] = loaded: false @_dependencies[dependency] = loaded: false


# The run method gets triggered when the keycommand
# is detected, it will ensure all of the dependencies
# are loaded and once it is comfortable they are, then
# it will run the user specified method and launch the
# application.
run: ()->
return @onReady() if @isReady()

for dependency, status of @_dependencies when status.loaded isnt true
KeyLauncher.util.loadScript dependency, =>
@_dependencies[dependency].loaded = true

requires: (dependency)-> requires: (dependency)->
@_dependencies[dependency] = @_dependencies[dependency] =
loaded: false loaded: false


#### Private Methods

isReady: ()-> isReady: ()->
ready = true ready = true


Expand Down
2 changes: 1 addition & 1 deletion source/javascripts/keylauncher/loader.coffee
Expand Up @@ -8,7 +8,7 @@ KeyLauncher.util.loadScript = (url, options={}, callback) ->
loaded = loadedScripts loaded = loadedScripts
timers = scriptTimers timers = scriptTimers


if _.isFunction(options) and !callback? if typeof(options) is "function" and !callback?
callback = options callback = options
options = {} options = {}


Expand Down
19 changes: 0 additions & 19 deletions source/layouts/layout.erb

This file was deleted.

6 changes: 6 additions & 0 deletions source/layouts/layout.html.haml
@@ -0,0 +1,6 @@
!!!
%html
%head
%title Keylauncher.js
%body
= javascript_include_tag 'keylauncher', 'example'

0 comments on commit 5131486

Please sign in to comment.