Permalink
Browse files

added basic example, seems to be working decently

  • Loading branch information...
1 parent bca04d3 commit 5131486b99b800a915ff069c4ac07ec9ba446ef4 @datapimp committed Apr 6, 2013
View
@@ -2,4 +2,6 @@
# the following line to use "https"
source 'http://rubygems.org'
-gem "middleman", "~>3.0.13"
+gem "middleman", "~>3.0.13"
+gem "haml"
+gem "sass"
View
@@ -97,4 +97,6 @@ PLATFORMS
ruby
DEPENDENCIES
+ haml
middleman (~> 3.0.13)
+ sass
View
@@ -1,3 +1,4 @@
+require 'haml'
###
# Compass
###
View
@@ -1,10 +0,0 @@
----
-title: Welcome to Middleman
----
-
-<div class="welcome">
- <h1>Middleman is Watching</h1>
- <p class="doc">
- <%= link_to "Read Online Documentation", "http://middlemanapp.com/" %>
- </p><!-- .doc -->
-</div><!-- .welcome -->
View
No changes.
@@ -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"
+]
@@ -6,12 +6,13 @@
KeyLauncher.VERSION = "0.0.1"
-KeyLauncher.on = (keycommand, launchFn=->, options={})->
+KeyLauncher.on = (keycommand, launchFn, options={})->
throw "Must specify a valid key command" unless keycommand?
launcher = new KeyLauncher.Launcher
command: keycommand
fn: launchFn || ->
requires: options.requires || []
- key(keycommand, launcher.run)
+ key keycommand, ->
+ launcher.run.call(launcher)
@@ -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
_dependencies: {}
constructor: (@options={})->
@fn = options.fn
@command = options.command
-
+
for dependency in @options.requires
@_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)->
@_dependencies[dependency] =
loaded: false
+ #### Private Methods
+
isReady: ()->
ready = true
@@ -8,7 +8,7 @@ KeyLauncher.util.loadScript = (url, options={}, callback) ->
loaded = loadedScripts
timers = scriptTimers
- if _.isFunction(options) and !callback?
+ if typeof(options) is "function" and !callback?
callback = options
options = {}
View
@@ -1,19 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <meta charset="utf-8">
-
- <!-- Always force latest IE rendering engine or request Chrome Frame -->
- <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
-
- <!-- Use title if it's in the page YAML frontmatter -->
- <title><%= data.page.title || "The Middleman" %></title>
-
- <%= stylesheet_link_tag "normalize", "all" %>
- <%= javascript_include_tag "all" %>
- </head>
-
- <body class="<%= page_classes %>">
- <%= yield %>
- </body>
-</html>
@@ -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.