jim 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +28 -0
- data/README.rdoc +1 -1
- data/Rakefile +2 -1
- data/jim.gemspec +67 -9
- data/lib/jim/bundler.rb +14 -11
- data/lib/jim/cli.rb +51 -9
- data/lib/jim/index.rb +3 -7
- data/lib/jim/installer.rb +140 -22
- data/lib/jim/templates/commands +21 -6
- data/lib/jim/version_parser.rb +2 -3
- data/lib/jim.rb +19 -2
- data/test/fixtures/jimfile +3 -3
- data/test/fixtures/sammy-0.5.0/HISTORY.md +135 -0
- data/test/fixtures/sammy-0.5.0/LICENSE +22 -0
- data/test/fixtures/sammy-0.5.0/README.md +81 -0
- data/test/fixtures/sammy-0.5.0/Rakefile +174 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/README.md +23 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/Rakefile +15 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/app.rb +17 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/app.ru +3 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/app.js +106 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/jquery.cloudkit.js +840 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/jquery.js +19 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/sammy.js +1013 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/index.html.erb +11 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/task.html.erb +4 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/task_details.html.erb +4 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/views/app.sass +63 -0
- data/test/fixtures/sammy-0.5.0/examples/backend/views/index.haml +18 -0
- data/test/fixtures/sammy-0.5.0/examples/form_handling/files/form.html +12 -0
- data/test/fixtures/sammy-0.5.0/examples/form_handling/index.html +65 -0
- data/test/fixtures/sammy-0.5.0/examples/hello_world/index.html +50 -0
- data/test/fixtures/sammy-0.5.0/examples/location_override/README.md +15 -0
- data/test/fixtures/sammy-0.5.0/examples/location_override/data.html +110 -0
- data/test/fixtures/sammy-0.5.0/examples/location_override/index.html +79 -0
- data/test/fixtures/sammy-0.5.0/examples/location_override/test.html +121 -0
- data/test/fixtures/sammy-0.5.0/lib/min/sammy-0.5.0.min.js +5 -0
- data/test/fixtures/sammy-0.5.0/lib/min/sammy-lastest.min.js +5 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.cache.js +117 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.haml.js +539 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.json.js +362 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.mustache.js +415 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.nested_params.js +118 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.storage.js +515 -0
- data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.template.js +117 -0
- data/test/fixtures/sammy-0.5.0/lib/sammy.js +1367 -0
- data/test/fixtures/sammy-0.5.0/test/fixtures/partial +1 -0
- data/test/fixtures/sammy-0.5.0/test/fixtures/partial.html +1 -0
- data/test/fixtures/sammy-0.5.0/test/fixtures/partial.noengine +1 -0
- data/test/fixtures/sammy-0.5.0/test/fixtures/partial.template +1 -0
- data/test/fixtures/sammy-0.5.0/test/index.html +84 -0
- data/test/fixtures/sammy-0.5.0/test/test_sammy_application.js +953 -0
- data/test/fixtures/sammy-0.5.0/test/test_sammy_event_context.js +252 -0
- data/test/fixtures/sammy-0.5.0/test/test_sammy_location_proxy.js +91 -0
- data/test/fixtures/sammy-0.5.0/test/test_sammy_plugins.js +296 -0
- data/test/fixtures/sammy-0.5.0/test/test_sammy_storage.js +175 -0
- data/test/fixtures/sammy-0.5.0/test/test_server +27 -0
- data/test/fixtures/sammy-0.5.0/vendor/jquery-1.4.1.js +6078 -0
- data/test/fixtures/sammy-0.5.0/vendor/jquery-1.4.1.min.js +152 -0
- data/test/fixtures/sammy-0.5.0/vendor/jsdoc/doc.haml +58 -0
- data/test/fixtures/sammy-0.5.0/vendor/jsdoc/jsdoc.rb +143 -0
- data/test/fixtures/sammy-0.5.0/vendor/jslitmus.js +670 -0
- data/test/fixtures/sammy-0.5.0/vendor/qunit/qunit.css +119 -0
- data/test/fixtures/sammy-0.5.0/vendor/qunit/qunit.js +1043 -0
- data/test/fixtures/sammy-0.5.0/vendor/qunit-spec.js +127 -0
- data/test/helper.rb +23 -3
- data/test/test_jim_bundler.rb +9 -8
- data/test/test_jim_cli.rb +21 -12
- data/test/test_jim_installer.rb +152 -35
- data/test/test_jim_version_parser.rb +4 -0
- metadata +117 -27
- data/.document +0 -5
data/lib/jim/templates/commands
CHANGED
@@ -1,22 +1,32 @@
|
|
1
1
|
init [path]
|
2
|
-
|
2
|
+
Create an example Jimfile at path or the current directory if path is
|
3
3
|
omitted
|
4
4
|
|
5
|
-
install [
|
6
|
-
|
5
|
+
install <url> [name] [version]
|
6
|
+
Install the file(s) at url into the JIMHOME directory. URL can be any path
|
7
7
|
or url that Downlow understands. This means:
|
8
8
|
|
9
9
|
jim install http://code.jquery.com/jquery-1.4.1.js
|
10
10
|
jim install ../sammy/
|
11
11
|
jim install gh://quirkey/sammy
|
12
12
|
jim install git://github.com/jquery/jquery.git
|
13
|
-
|
13
|
+
|
14
|
+
remove <name> [version]
|
15
|
+
uninstall <name> [version]
|
16
|
+
Iterate through the install files and prompt for the removal of those matching
|
17
|
+
the supplied name and version
|
18
|
+
|
14
19
|
list
|
15
|
-
|
20
|
+
installed
|
21
|
+
List all the installed packages and their versions
|
22
|
+
|
23
|
+
available
|
24
|
+
List all available projects and versions including those in the local path, or
|
25
|
+
paths specified in a Jimfile
|
16
26
|
|
17
27
|
resolve
|
18
28
|
Resolve all the paths listed in a Jimfile and print them to STDOUT.
|
19
|
-
If no Jimfile is set in the options, assumes ./Jimfile.
|
29
|
+
If no Jimfile is set in the options, assumes ./Jimfile.
|
20
30
|
|
21
31
|
bundle [bundled_path]
|
22
32
|
Bundle all the files listed in a Jimfile and save them to [bundled_path].
|
@@ -36,6 +46,11 @@ compress [compressed_path]
|
|
36
46
|
vendor [vendor_dir]
|
37
47
|
Copy all the files listed in Jimfile to the vendor_dir
|
38
48
|
|
49
|
+
pack [vendor_dir]
|
50
|
+
Runs in order, vendor, bundle, compress. This command simplifies the common
|
51
|
+
workflow of vendoring and re-bundling before commiting or deploying changes
|
52
|
+
to a project
|
53
|
+
|
39
54
|
commands
|
40
55
|
Print this help file
|
41
56
|
|
data/lib/jim/version_parser.rb
CHANGED
@@ -12,9 +12,8 @@ module Jim
|
|
12
12
|
f.gsub!(/#{extension}$/, '')
|
13
13
|
end
|
14
14
|
|
15
|
-
name, after_name, delimiter, version = f.scan(/^([a-z
|
16
|
-
|
17
|
-
[name, version || "0"]
|
15
|
+
name, after_name, delimiter, version = f.scan(/^([a-z\.\-\_]+)(([\.\-\_\s])v?(([\w\d]{6,7})|(\d[\d\w\.]*)))?$/i)[0]
|
16
|
+
[name || f, version || "0"]
|
18
17
|
end
|
19
18
|
|
20
19
|
def self.parse_package_json(package)
|
data/lib/jim.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'downlow'
|
2
2
|
require 'logger'
|
3
3
|
require 'yajl'
|
4
|
-
|
4
|
+
require 'version_sorter'
|
5
|
+
require 'digest/md5'
|
5
6
|
|
6
7
|
module Jim
|
7
|
-
VERSION = '0.
|
8
|
+
VERSION = '0.2.0'
|
8
9
|
|
9
10
|
class Error < RuntimeError; end
|
11
|
+
class InstallError < Error; end
|
10
12
|
class FileExists < Error; end
|
11
13
|
|
12
14
|
def self.logger=(logger)
|
@@ -24,6 +26,21 @@ module Jim
|
|
24
26
|
@logger
|
25
27
|
end
|
26
28
|
|
29
|
+
def self.each_path_in_directories(directories, ext, ignore_directories = [], &block)
|
30
|
+
ignore_regexp = ignore_directories.empty? ? false : /(\/|^)(#{ignore_directories.join('|')})\//
|
31
|
+
directories.each do |dir|
|
32
|
+
dir = Pathname.new(dir).expand_path
|
33
|
+
Dir.glob(Pathname.new(dir) + '**' + "*#{ext}") do |filename|
|
34
|
+
next if File.directory?(filename)
|
35
|
+
if ignore_regexp
|
36
|
+
basepath = filename.to_s.gsub(dir.to_s, '/')
|
37
|
+
next if basepath =~ ignore_regexp
|
38
|
+
end
|
39
|
+
yield Pathname.new(filename)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
27
44
|
autoload :Installer, 'jim/installer'
|
28
45
|
autoload :Index, 'jim/index'
|
29
46
|
autoload :Bundler, 'jim/bundler'
|
data/test/fixtures/jimfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
// bundled_path: tmp/public/javascripts/bundled.js
|
2
|
-
// compressed_path: tmp/public/javascripts/compressed.js
|
3
|
-
// vendor_dir: tmp/public/javascripts/vendor
|
1
|
+
// bundled_path: test/tmp/public/javascripts/bundled.js
|
2
|
+
// compressed_path: test/tmp/public/javascripts/compressed.js
|
3
|
+
// vendor_dir: test/tmp/public/javascripts/vendor
|
4
4
|
|
5
5
|
jquery 1.4.1
|
6
6
|
myproject
|
@@ -0,0 +1,135 @@
|
|
1
|
+
== 0.5.0 [02/15/10]
|
2
|
+
|
3
|
+
New:
|
4
|
+
|
5
|
+
- Sammy.Haml is a plugin wrapper around haml-js that provides client side rendering of Haml templates (Thanks Tim Caswell!)
|
6
|
+
- Sammy.Mustache can now accept Mustache partials as a third argument or passed as {partials:} in data. (thanks dpree!)
|
7
|
+
- around filters with Sammy.Application#around(). Wraps an entire route execution path in a function()
|
8
|
+
- Sammy.Application#contextMatchesOptions() as a method for filtering which before() filters to process when running a route.
|
9
|
+
- test_server is a simple Sinatra/vegas app for running the tests on a local ruby server (allows for testing functionality that requires the http:// protocol)
|
10
|
+
- Sammy.Store#load(key, path) loads file at path into key
|
11
|
+
- partial() will now iterate over an array of data, calling the callback for each element, or appending the collected result.
|
12
|
+
- route() takes the psuedo-verb 'any' which appends the path/callback to all the verbs. Also, added the shortcut method any(). If only a path and callback are supplied to route(), the verb is assumed to be 'any'.
|
13
|
+
- Passing a string as the callback argument to route() looks up that method on the application.
|
14
|
+
- Sammy.Application#mapRoutes() takes an array of routes (as arrays of arguments) and adds them to the app.
|
15
|
+
- Sammy() is a function itself which provides an easy hook for looking up/creating/and extending applications with the element_selector as the unique identifier.
|
16
|
+
- The application level setting 'template_engine' lets you define a default template engine to fall back on for partial() rendering regardless of extension.
|
17
|
+
- All application modifying methods return the application instance allowing for jQuery-esque chaining for app creation.
|
18
|
+
|
19
|
+
Changed:
|
20
|
+
|
21
|
+
- the separate Sammy.Cache plugin is now deprecated in favor of one included/built-upon Sammy.Storage. It is still in the repository, but will be removed completely in 1.0
|
22
|
+
- Tests are now on top of qunit (http://github.com/jquery/qunit). jQunit has been unmaintained for a while. Also, removed dependency on external jqunit-spec repo.
|
23
|
+
- Updated to latest mustache.js (0.2.2) in Sammy.Mustache
|
24
|
+
- Removed .extend() and .clone() from Sammy.Object (unused)
|
25
|
+
- Sammy now requires jQuery >= 1.4.1
|
26
|
+
- Forms bound to post/put/delete routes no longer have to be manually re-bound with triggering('changed'). The application listens for 'submit' events on forms within the context of the element_selector instead. (Relies on the submit bubbling in jQuery 1.4.1)
|
27
|
+
- $.sammy is an alias for Sammy() instead of new Sammy.Application
|
28
|
+
|
29
|
+
Fixed:
|
30
|
+
|
31
|
+
- Only fire KVO once when setting a Sammy.Store key
|
32
|
+
- Ensure all keys are strings in Sammy.Store.
|
33
|
+
- refesh() with new location proxies (Thanks ZhangJinzhu!)
|
34
|
+
|
35
|
+
|
36
|
+
== 0.4.1 [01/11/10]
|
37
|
+
|
38
|
+
New:
|
39
|
+
|
40
|
+
- Add rake generate task that builds a simple (server-less) sammy app structure
|
41
|
+
|
42
|
+
Fixed:
|
43
|
+
|
44
|
+
- decode all parsed params (thanks jdknezek)
|
45
|
+
- Fix Sammy.JSON fails in IE6
|
46
|
+
- Fixed test suite in IE8
|
47
|
+
- Fixed console.log is not a real function in IE8
|
48
|
+
|
49
|
+
== 0.4.0 [01/04/10]
|
50
|
+
|
51
|
+
New:
|
52
|
+
|
53
|
+
- Sammy.Storage and Sammy.Session are wrappers around a new prototype Sammy.Store, which is an class that abstracts access to the various types of in browser storage, including HTML5 DOM Storage and Cookies. This allows for a unified way of accessing and storing data locally for a Sammy app.
|
54
|
+
- Sammy.Mustache is a plugin that adds support for the Mustache template framework through @janl's Mustache.js.
|
55
|
+
- Sammy.JSON is simple plugin that includes the json2.js source and also provides a simple helper for doing JSON to/from conversion
|
56
|
+
- Sammy.Application#helper() is a shortcut for adding a single helper by name. This allows for more easily defined dynamically named helpers.
|
57
|
+
|
58
|
+
Changed:
|
59
|
+
|
60
|
+
- Sammy no longer depends exclusively on polling to determine changes in its location. The work of determining location change was pulled out of Sammy.Application entirely and into LocationProxy prototypes. The new default Sammy.HashLocationProxy will use the native 'onhashchange' event where available, and resort to a single global poller when not. The LocationProxy object can be set for each Sammy.Application. Location proxies can be defined added, and will work as long as they conform to the simple prototype laid out by the HashLocationProxy.
|
61
|
+
|
62
|
+
Fixed:
|
63
|
+
|
64
|
+
- URL query params are properly URL decoded. [Thanks Lee Semel]
|
65
|
+
|
66
|
+
== 0.3.1 [12/09/09]
|
67
|
+
|
68
|
+
New:
|
69
|
+
|
70
|
+
- Sammy.NestedParams is a new plugin that handles form fields like Rails/Rack's nested params. See the docs for more info [thanks endor!]
|
71
|
+
|
72
|
+
Changed:
|
73
|
+
|
74
|
+
- Sammy.Application#_parseFormParams is now a single point of entry that takes a form and should return a set of params. NestedParams hooks into this.
|
75
|
+
- The Sammy.Application constructor no longer requires an app function. This allows you to create multiple apps quickly and assign routes/etc. later.
|
76
|
+
- Sammy.Template takes a second option which is the proxy/extension you want to associate it with.
|
77
|
+
|
78
|
+
Fixed:
|
79
|
+
|
80
|
+
- Fixed a bug in IE only where with two consecutive routes that contain params, the second set of params will not be filtered properly [thanks Scott McMillin!]
|
81
|
+
|
82
|
+
|
83
|
+
== 0.3.0 [09/28/09]
|
84
|
+
|
85
|
+
New:
|
86
|
+
|
87
|
+
- Sammy.Application#use() takes an app function and applies it to the current app. This is the entry point for Sammy Plugins. See docs at: http://code.quirkey.com/sammy/docs/plugins.html
|
88
|
+
- New system for repository structure, minified files are placed in lib/min/ version numbers are appended to minified files
|
89
|
+
- Sammy.EventContext#partial() is template engine agnostic and calls the template engine method based on the extension of the file you're trying to render.
|
90
|
+
- New official Sammy.Cache plugin provides simple client side caching
|
91
|
+
- Sammy.EventContext#redirect() can take any number of arguments that are all joined by '/'
|
92
|
+
- Sammy.Application#refresh() will re-run the current route
|
93
|
+
|
94
|
+
Changes:
|
95
|
+
|
96
|
+
- Removed John Resig's Class() inheritance code/style in favor of doing prototypical inheritance and using $.extend()
|
97
|
+
- Sammy.Application bind() and trigger() now use jQuery's built in namespacing. This means that a Sammy application can now catch events like clicks and other events that bubble up or are triggered on the Sammy.Application#element()
|
98
|
+
- Sammy.log and Sammy.addLogger are top level access to logging and adding additional logging paths. Sammy.Application#bindToAllEvents() replaces the functionality for the former addLogger() method
|
99
|
+
- the app functions and route callbacks both take _this_ as the first argument
|
100
|
+
- $.srender and template() are no longer part of the sammy.js and are instead included in the Sammy.Template plugin lib/plugins/sammy.template.js
|
101
|
+
- Routes are saved and looked up in order of definition instead of shortest first (May break existing applications that use RegExp based routing)
|
102
|
+
- Made the parse query more uniform with the rest of the code base
|
103
|
+
- Sammy.Object#toString() wont include functions unless you explicitly want them
|
104
|
+
|
105
|
+
Fixes:
|
106
|
+
- Fixed redirect() handling in post routes
|
107
|
+
- Fixed param parsing for form submission where there were multiple params with the same name
|
108
|
+
|
109
|
+
== 0.2.1 [08/28/09]
|
110
|
+
|
111
|
+
New:
|
112
|
+
|
113
|
+
- Query string parameters: You can now pass extra parameters to a route using the traditional Query string params scheme. e.g #/my/route?var1=blah will give you params['var1'] #=> 'blah' inside an Event context. (Thanks to Jesse Hallet [halletj]) See the commit (cb309b91c0ab80d4e8d6ef9bc97314607cc0da76) for more info.
|
114
|
+
|
115
|
+
Fixed:
|
116
|
+
|
117
|
+
- Redirection in POST routes wasnt working properly. (Thanks Russel Jones [CodeOfficer])
|
118
|
+
- Dont cache partial templates in debug mode. (Thanks Jonathan Vaught [gravelpup])
|
119
|
+
- Spelling and grammar fixes to README/Docs (Thanks Jason Davies [jasondavies])
|
120
|
+
|
121
|
+
|
122
|
+
== 0.2.0 [06/01/09]
|
123
|
+
|
124
|
+
New:
|
125
|
+
|
126
|
+
- Location Overrides: All location methods refer to two Sammy.Application methods: getLocation() and setLocation() which return and take a string, respectively. The default behavior is to pull the location from window.location.hash, but these methods can be overridden to provide alternate location strategies. Theres an example in examples/location_override. (thanks to britg, CodeOfficer)
|
127
|
+
- Sammy.Object#toHash() returns a JS object with any functions stripped. Useful for using with params.
|
128
|
+
- Sammy.Application#swap() is the method called within partial() for changing the content of $element(). The default behavior is just to use $.fn.html(), but can be overridden to provide some fancy animations.
|
129
|
+
|
130
|
+
Fixed:
|
131
|
+
|
132
|
+
- The 'changed' event is only fired at run() and after a partial's callback. This is the event to bind to, to check the DOM after a partial() call. (thanks to hpoydar).
|
133
|
+
- template() (aka $.srender) handles single quoted attributes now (aka generated HAML)
|
134
|
+
- When the app booted up, run() would redirect to the start_url even if another location was present.
|
135
|
+
- the _checkLocation() method now sets last_location properly (which fixes continual checking if route isnt found)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008 Aaron Quint, Quirkey NYC, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Sammy
|
2
|
+
|
3
|
+
[http://code.quirkey.com/sammy](http://code.quirkey.com/sammy)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Sammy is a tiny javascript framework built on top of jQuery inspired by Ruby's [Sinatra](http://sinatrarb.com).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Download sammy.js and install it in your public javascripts directory.
|
12
|
+
Include it in your document AFTER jquery.
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Like Sinatra, a Sammy application revolves around 'routes'. Routes in Sammy are a little different, though. Not only can you define 'get' and 'post' routes, but you can also bind routes to custom events triggered by your application.
|
17
|
+
|
18
|
+
You set up a Sammy Application by passing a Function to the `$.sammy` (which is a shortcut for the Sammy.Application constructor).
|
19
|
+
|
20
|
+
$.sammy(function() {
|
21
|
+
|
22
|
+
this.get('#/', function() {
|
23
|
+
$('#main').text('Welcome!');
|
24
|
+
});
|
25
|
+
|
26
|
+
});
|
27
|
+
|
28
|
+
Inside the 'app' function() `this` is the Application. This is where you can configure the application and add routes.
|
29
|
+
|
30
|
+
Above, we defined a `get()` route. When the browser is pointed to `#/` the function passed to that route will be run. Inside the route function, `this` is a Sammy.EventContext. EventContext has a bunch of special methods and properties including a params hash, the ability to redirect, render partials, and more.
|
31
|
+
|
32
|
+
Once you've defined an application the only thing left to do is run it. The best-practice behavior is to encapulate `run()` in a document.ready block:
|
33
|
+
|
34
|
+
var app = $.sammy(...)
|
35
|
+
|
36
|
+
$(function() {
|
37
|
+
app.run();
|
38
|
+
});
|
39
|
+
|
40
|
+
This will guarantee that the DOM is loaded before we try to apply functionality to it.
|
41
|
+
|
42
|
+
## Dependencies
|
43
|
+
|
44
|
+
Sammy requires jQuery >= 1.3.2
|
45
|
+
Get it from: [http://jquery.com](http://jquery.com)
|
46
|
+
|
47
|
+
## More!
|
48
|
+
|
49
|
+
### Learn!
|
50
|
+
|
51
|
+
* [Intro](http://code.quirkey.com/sammy)
|
52
|
+
* [Docs](http://code.quirkey.com/sammy/docs/)
|
53
|
+
* [Examples](http://github.com/quirkey/sammy/tree/master/examples/)
|
54
|
+
* [More Resources](http://code.quirkey.com/sammy/resources.html)
|
55
|
+
|
56
|
+
### Keep informed!
|
57
|
+
|
58
|
+
* [Follow @sammy_js](http://twitter.com/sammy_js)
|
59
|
+
* [Join the mailing list](http://groups.google.com/group/sammyjs)
|
60
|
+
* [Chat with us in #sammy](irc://irc.freenode.net/#sammy)
|
61
|
+
|
62
|
+
## Authors
|
63
|
+
|
64
|
+
Sammy.js was created and is maintained by Aaron Quint <aaron at quirkey.com> with additional features and fixes contributed by these talented individuals:
|
65
|
+
|
66
|
+
* Frank Prößdorf / endor
|
67
|
+
* Alexander Lang / langalex
|
68
|
+
* Scott McMillin / scottymac
|
69
|
+
* ZhangJinzhu / jinzhu
|
70
|
+
* Jesse Hallett / hallettj
|
71
|
+
* Jonathan Vaught / gravelpup
|
72
|
+
* Jason Davies / jasondavies
|
73
|
+
* Russell Jones / CodeOfficer
|
74
|
+
* Geoff Longman
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
Sammy is covered by the MIT License. See LICENSE for more information.
|
79
|
+
|
80
|
+
Sammy includes code originally created by John Resig ([Class implementation](http://ejohn.org/blog/simple-javascript-inheritance/)) and Greg Borenstien ([srender](http://github.com/atduskgreg/srender/tree/master)).
|
81
|
+
|
@@ -0,0 +1,174 @@
|
|
1
|
+
desc 'Pulls the current version from lib/sammy.js'
|
2
|
+
task :version do
|
3
|
+
f = File.read('lib/sammy.js')
|
4
|
+
@version = f.match(/Sammy.VERSION \= \'([\d\w\.]+)\'/)[1]
|
5
|
+
puts "VERSION: " + @version
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Uses the yui-compressor to minify lib/sammy.js'
|
9
|
+
task :minify => :version do
|
10
|
+
yui_path = ENV['YUI_PATH'] || '~/Sites/yui/yuicompressor-2.4.2.jar'
|
11
|
+
java_path = ENV['JAVA_PATH'] || '/usr/bin/java'
|
12
|
+
puts "Minify-ing"
|
13
|
+
|
14
|
+
# compress each file
|
15
|
+
Dir['lib/**/*.js'].each do |path|
|
16
|
+
if path =~ /\.min\.js$/
|
17
|
+
File.unlink(path)
|
18
|
+
next
|
19
|
+
end
|
20
|
+
path.gsub!('lib','')
|
21
|
+
|
22
|
+
dir = 'lib/min'
|
23
|
+
min_path = File.join(dir, path.gsub(/\.js$/, "-#{@version}.min.js"))
|
24
|
+
latest_min_path = File.join(dir, path.gsub(/\.js$/, "-lastest.min.js"))
|
25
|
+
|
26
|
+
sh "#{java_path} -jar #{yui_path} -o #{min_path} lib/#{path}"
|
27
|
+
minified = File.read(min_path)
|
28
|
+
prefix = []
|
29
|
+
prefix << "// -- Sammy -- #{path}"
|
30
|
+
prefix << "// http://code.quirkey.com/sammy"
|
31
|
+
prefix << "// Version: #{@version}"
|
32
|
+
prefix << "// Built: #{Time.now}"
|
33
|
+
File.open(min_path, 'w') do |f|
|
34
|
+
f << prefix.join("\n") << "\n"
|
35
|
+
f << minified
|
36
|
+
end
|
37
|
+
FileUtils.copy(min_path, latest_min_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Modified from peterc: http://gist.github.com/113226
|
42
|
+
desc "Automatically run something when code is changed"
|
43
|
+
task :autotest do
|
44
|
+
require 'find'
|
45
|
+
files = {}
|
46
|
+
test_path = ENV['TEST'] || File.join(File.dirname(__FILE__), 'test', 'index.html')
|
47
|
+
loop do
|
48
|
+
changed = false
|
49
|
+
Find.find(File.dirname(__FILE__)) do |file|
|
50
|
+
next unless file =~ /\.js$/
|
51
|
+
ctime = File.ctime(file).to_i
|
52
|
+
|
53
|
+
if ctime != files[file]
|
54
|
+
files[file] = ctime
|
55
|
+
changed = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if changed
|
60
|
+
puts "Running #{test_path} at #{Time.now}"
|
61
|
+
system "open #{test_path}"
|
62
|
+
puts "\nWaiting for a *.js change"
|
63
|
+
end
|
64
|
+
|
65
|
+
sleep 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc 'launch the test file in the browser'
|
70
|
+
task :test do
|
71
|
+
system "open #{File.join(File.dirname(__FILE__), 'test', 'index.html')}"
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'generate the API documentation'
|
75
|
+
task :api do
|
76
|
+
tmp_doc_path = '/tmp/sammy.api.html'
|
77
|
+
api_template_path = 'site/docs/api_template.html'
|
78
|
+
final_path = 'site/docs/api.html'
|
79
|
+
File.unlink(tmp_doc_path) if File.readable?(tmp_doc_path)
|
80
|
+
sh "ruby vendor/jsdoc/jsdoc.rb lib/sammy.js lib/plugins/ > #{tmp_doc_path}"
|
81
|
+
sh "cat #{api_template_path} #{tmp_doc_path} > #{final_path}"
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'copy files into the site branch'
|
85
|
+
task :copy_test_and_examples do
|
86
|
+
sh "cp -r examples site/examples"
|
87
|
+
sh "cp -r test site/test"
|
88
|
+
sh "cp -r lib site/lib"
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
desc 'update the current version # in the pages'
|
93
|
+
task :update_version => :version do
|
94
|
+
Dir['site/**/*.*'].each do |file|
|
95
|
+
File.open(file, 'r+') do |f|
|
96
|
+
contents = f.read
|
97
|
+
contents.gsub!(/current_version\: ([\w\d\.]+)/, "current_version: #{@version}")
|
98
|
+
f.truncate(0)
|
99
|
+
f.rewind
|
100
|
+
f << contents
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
task :push_site do
|
106
|
+
sh "cd site && git add ."
|
107
|
+
sh "cd site && git commit -am 'Updated Site via Rake'"
|
108
|
+
sh "cd site && git push upstream gh-pages"
|
109
|
+
end
|
110
|
+
|
111
|
+
desc 'Build the site'
|
112
|
+
task :build_site => [:api, :copy_test_and_examples, :update_version]
|
113
|
+
|
114
|
+
desc 'Build the site, then push it to github'
|
115
|
+
task :site => [:build_site, :push_site]
|
116
|
+
|
117
|
+
desc "generate a simple sammy app structure at DIR"
|
118
|
+
task :generate do
|
119
|
+
dir = ENV['DIR']
|
120
|
+
name = File.basename(dir)
|
121
|
+
puts "Generating an app #{name} at #{dir}"
|
122
|
+
sammy_root = File.expand_path(File.dirname(__FILE__))
|
123
|
+
include FileUtils
|
124
|
+
path = File.expand_path(dir)
|
125
|
+
mkdir_p(path)
|
126
|
+
mkdir_p(File.join(path, 'javascripts'))
|
127
|
+
mkdir_p(File.join(path, 'stylesheets'))
|
128
|
+
mkdir_p(File.join(path, 'images'))
|
129
|
+
cp_r(File.join(sammy_root, 'lib'), File.join(path, 'javascripts', 'sammy'))
|
130
|
+
cp_r(File.join(sammy_root, 'vendor', 'jquery-1.3.2.js'), File.join(path, 'javascripts', 'jquery-1.3.2.js'))
|
131
|
+
index = <<-EOT
|
132
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
133
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
134
|
+
|
135
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
136
|
+
<head>
|
137
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
138
|
+
|
139
|
+
<title>#{name}</title>
|
140
|
+
|
141
|
+
<link rel="stylesheet" href="/stylesheets/styles.css" type="text/css" media="screen" charset="utf-8"/>
|
142
|
+
|
143
|
+
<script src="javascripts/jquery-1.3.2.js" type="text/javascript" charset="utf-8"></script>
|
144
|
+
<script src="javascripts/sammy/sammy.js" type="text/javascript" charset="utf-8"></script>
|
145
|
+
<script src="javascripts/#{name}.js" type="text/javascript" charset="utf-8"></script>
|
146
|
+
</head>
|
147
|
+
|
148
|
+
<body>
|
149
|
+
|
150
|
+
|
151
|
+
</body>
|
152
|
+
</html>
|
153
|
+
EOT
|
154
|
+
|
155
|
+
js = <<-EOT
|
156
|
+
(function($) {
|
157
|
+
|
158
|
+
var app = $.sammy(function() {
|
159
|
+
|
160
|
+
|
161
|
+
});
|
162
|
+
|
163
|
+
$(function() {
|
164
|
+
app.run();
|
165
|
+
});
|
166
|
+
|
167
|
+
|
168
|
+
})(jQuery);
|
169
|
+
EOT
|
170
|
+
touch(File.join(path, 'stylesheets', 'style.css'))
|
171
|
+
File.open(File.join(path, 'javascripts', "#{name}.js"), 'w') {|f| f << js }
|
172
|
+
File.open(File.join(path, "index.html"), 'w') {|f| f << index }
|
173
|
+
puts "Done."
|
174
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Sammy
|
2
|
+
|
3
|
+
## Backend Example
|
4
|
+
|
5
|
+
This is a simple To-do list type application built with a simple ruby backend and a sammy front-end.
|
6
|
+
|
7
|
+
The backend is built using sinatra (+rack), and [cloudkit](http://getcloudkit.com).
|
8
|
+
|
9
|
+
### Setup
|
10
|
+
|
11
|
+
Besides Ruby you also need some gems.
|
12
|
+
Currently, there are some issues with Rack 1.0 and Sinatra so you need to install the pre-release sinatra from github.
|
13
|
+
|
14
|
+
sudo gem install cloudkit haml
|
15
|
+
sudo gem install sinatra-sinatra -s http://gems.github.com
|
16
|
+
|
17
|
+
Once you have everything installed from this directory (examples/backend) run:
|
18
|
+
|
19
|
+
rake start
|
20
|
+
|
21
|
+
### Notes
|
22
|
+
|
23
|
+
!!! Todo's are stored in memory! AKA if you restart the rack application you will loose you're todos. This is really just a demonstration. If you really want to use this, check the [cloudkit](http://getcloudkit.com) docs to see how to set cloudkit up to store info in Tokyo Cabinent.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
task :start => :copy_files do
|
2
|
+
system 'open http://localhost:9292/'
|
3
|
+
system 'rackup app.ru'
|
4
|
+
end
|
5
|
+
|
6
|
+
desc 'copy latest sammy and jquery from lib and vendor'
|
7
|
+
task :copy_files do
|
8
|
+
root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
9
|
+
{
|
10
|
+
['lib', 'sammy.js'] => 'sammy.js',
|
11
|
+
['vendor', 'jquery-1.3.2.min.js'] => 'jquery.js'
|
12
|
+
}.each do |from, to|
|
13
|
+
FileUtils.cp(File.join(root, *from), File.join('public', 'javascripts', to))
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'haml'
|
3
|
+
require 'sass'
|
4
|
+
require 'cloudkit'
|
5
|
+
|
6
|
+
class Tasks < Sinatra::Default
|
7
|
+
|
8
|
+
use CloudKit::Service, :collections => [:tasks]
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
haml :index
|
12
|
+
end
|
13
|
+
|
14
|
+
get '/stylesheets/:sheet.css' do
|
15
|
+
sass :"#{params['sheet']}"
|
16
|
+
end
|
17
|
+
end
|