catapult 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in catapult.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alex MacCaw
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Catapult
2
+
3
+ Simple gem that gives pure JavaScript/CoffeeScript projects a basic structure, and manages any necessary compilation and concatenation.
4
+
5
+ Catapult is especially useful alongside MVC frameworks like [Spine](http://spinejs.com) and [Backbone](http://backbonejs.org).
6
+
7
+ ## Installation
8
+
9
+ $ gem install catapult
10
+
11
+ ## Usage
12
+
13
+ To generate an app, use:
14
+
15
+ catapult new myapp
16
+ cd myapp
17
+
18
+ Now you can start a catapult server:
19
+
20
+ catapult server
21
+
22
+ Or build the files for deployment:
23
+
24
+ catapult build
25
+
26
+ Or watch the files for changes, and then automatically build:
27
+
28
+ catapult watch
29
+
30
+ ## Concatenation
31
+
32
+ Catapult uses [Sprockets](https://github.com/sstephenson/sprockets) for concatenation. Sprockets uses meta comments to specify dependencies. For example:
33
+
34
+ //= require jquery
35
+ //= require ./other_file
36
+ //= require_tree ./app
37
+
38
+ See the Sprockets documentation for more information.
39
+
40
+ ## Included compilers
41
+
42
+ Sprockets will automatically compile certain file types when the files are first requested. For example, files with `.coffee` extensions will be compiled down to JavaScript before being served up to the end user.
43
+
44
+ The included Sprockets compilers are: [CoffeeScript](http://coffeescript.org), [sprockets-commonjs](http://github.com/maccman/sprockets-commonjs) and [Stylus](http://learnboost.github.com/stylus/). You can include additional ones by simply adding them to your project's `Gemfile`.
45
+
46
+ ## Deploying to Heroku
47
+
48
+ It's a good idea to just serve up static files in production, and disable the asset compilation.
49
+
50
+ If you're using a system like Apache, you can just serve up the static files under the `./public` dir. Otherwise, with a [Rack](http://rack.github.com) based system, like [Heroku](http://heroku.com), you're going to need a few files:
51
+
52
+ Firstly, a `Gemfile`:
53
+
54
+ source 'https://rubygems.org'
55
+ gem 'catapult'
56
+
57
+ Then a `config.ru` file, serving up the static files:
58
+
59
+ require 'catapult'
60
+
61
+ use Catapult::TryStatic,
62
+ :root => Catapult.root.join('public'),
63
+ :urls => %w[/],
64
+ :try => ['.html', 'index.html', '/index.html']
65
+
66
+ run lambda {|env|
67
+ [404, {}, ['Not found']]
68
+ }
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/catapult ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'catapult'
5
+ Bundler.require if File.exists?('Gemfile')
6
+
7
+ begin
8
+ require 'catapult/cli'
9
+ Catapult::CLI.start
10
+ rescue Interrupt => e
11
+ puts "\nQuitting..."
12
+ exit 1
13
+ rescue SystemExit => e
14
+ exit e.status
15
+ end
data/catapult.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/catapult/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alex MacCaw"]
6
+ gem.email = ["maccman@gmail.com"]
7
+ gem.description = %q{A Sprockets/Rack build tool}
8
+ gem.summary = %q{Easily build JavaScript projects}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "catapult"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Catapult::VERSION
17
+
18
+ gem.add_dependency 'rack', '~> 1.4.1'
19
+ gem.add_dependency 'sprockets', '~> 2.4.3'
20
+ gem.add_dependency 'sprockets-commonjs', '= 0.0.6.pre'
21
+ gem.add_dependency 'listen', '~> 0.4.2'
22
+ gem.add_dependency 'stylus', '~> 0.6.2'
23
+ gem.add_dependency 'coffee-script', '~> 2.2.0'
24
+ gem.add_dependency 'thor', '~> 0.15.2'
25
+ gem.add_dependency 'thin', '~> 1.3.1'
26
+ end
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1 @@
1
+ /*= require_tree .*/
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "app",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "jquery": "latest"
6
+ }
7
+ }
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link rel="stylesheet" href="/assets/app.css" type="text/css">
5
+ <script src="/assets/app.js"></script>
6
+ </head>
7
+ <body>
8
+ <p>Hello world!</p>
9
+ </body>
10
+ </html>
@@ -0,0 +1,69 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'listen'
4
+ require 'rack'
5
+ require 'thor'
6
+
7
+ module Catapult
8
+ class CLI < Thor
9
+ include Thor::Actions
10
+
11
+ def self.source_root
12
+ File.expand_path('../../..', __FILE__)
13
+ end
14
+
15
+ desc 'build', 'Build project'
16
+
17
+ def build
18
+ target = Pathname('./public/assets')
19
+
20
+ puts "Building: #{Catapult.root}"
21
+
22
+ Catapult.environment.each_logical_path do |logical_path|
23
+ if asset = Catapult.environment.find_asset(logical_path)
24
+ filename = target.join(logical_path)
25
+ FileUtils.mkpath(filename.dirname)
26
+ puts "Write asset: #{filename}"
27
+ asset.write_to(filename)
28
+ end
29
+ end
30
+ end
31
+
32
+ desc 'server', 'Serve up project'
33
+
34
+ method_option :port, :aliases => '-p', :desc => 'Port'
35
+
36
+ def server
37
+ if File.exists?('config.ru')
38
+ Rack::Server.start(
39
+ :Port => options[:port] || 9292,
40
+ :config => 'config.ru'
41
+ )
42
+ else
43
+ Rack::Server.start(
44
+ :Port => options[:port] || 9292,
45
+ :app => Catapult.app
46
+ )
47
+ end
48
+ end
49
+
50
+ desc 'watch', 'Build project whenever it changes'
51
+
52
+ def watch
53
+ puts "Watching: #{Catapult.root}"
54
+
55
+ build
56
+
57
+ paths = Catapult.environment.paths
58
+ paths = paths.select {|p| File.exists?(p) }
59
+
60
+ Listen.to(*paths) { build }
61
+ end
62
+
63
+ desc 'new', 'Create a new project'
64
+
65
+ def new(name)
66
+ directory('templates/app', name)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,36 @@
1
+ module Catapult
2
+ # The Rack::TryStatic middleware delegates requests to Rack::Static middleware
3
+ # trying to match a static file
4
+ #
5
+ # Examples
6
+ #
7
+ # use Rack::TryStatic,
8
+ # :root => "public", # static files root dir
9
+ # :urls => %w[/], # match all requests
10
+ # :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
11
+ #
12
+ # uses same options as Rack::Static with extra :try option which is an array
13
+ # of postfixes to find desired file
14
+
15
+ class TryStatic
16
+
17
+ def initialize(app, options)
18
+ @app = app
19
+ @try = ['', *options[:try]]
20
+ @static = ::Rack::Static.new(
21
+ lambda { |_| [404, {}, []] },
22
+ options
23
+ )
24
+ end
25
+
26
+ def call(env)
27
+ orig_path = env['PATH_INFO']
28
+ found = nil
29
+ @try.each do |path|
30
+ resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path}))
31
+ break if 404 != resp[0] && found = resp
32
+ end
33
+ found or @app.call(env.merge!('PATH_INFO' => orig_path))
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Catapult
2
+ VERSION = '0.0.1'
3
+ end
data/lib/catapult.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'pathname'
2
+ require 'sprockets'
3
+ require 'sprockets/commonjs'
4
+ require 'stylus/tilt'
5
+ require 'stylus/import_processor'
6
+ require 'coffee_script'
7
+
8
+ module Catapult
9
+ autoload :CLI, 'catapult/cli'
10
+ autoload :TryStatic, 'catapult/try_static'
11
+
12
+ def self.root
13
+ @root ||= Pathname('.').expand_path
14
+ end
15
+
16
+ def self.environment
17
+ @environment ||= begin
18
+ env = Sprockets::Environment.new(root)
19
+
20
+ env.append_path(root.join('assets', 'javascripts'))
21
+ env.append_path(root.join('assets', 'stylesheets'))
22
+ env.append_path(root.join('assets', 'images'))
23
+
24
+ env.append_path(root.join('vendor', 'assets', 'javascripts'))
25
+ env.append_path(root.join('vendor', 'assets', 'stylesheets'))
26
+
27
+ env.append_path(root.join('browser_modules'))
28
+
29
+ env.register_engine '.styl', Tilt::StylusTemplate
30
+ env.register_preprocessor 'text/css', Stylus::ImportProcessor
31
+
32
+ env
33
+ end
34
+ end
35
+
36
+ def self.app
37
+ app = Rack::Builder.new do
38
+ map '/assets' do
39
+ run Catapult.environment
40
+ end
41
+
42
+ use Catapult::TryStatic,
43
+ :root => Catapult.root.join('public'),
44
+ :urls => %w[/],
45
+ :try => ['.html', 'index.html', '/index.html']
46
+
47
+ use Rack::ContentType
48
+
49
+ run lambda {|env|
50
+ [404, {}, ['Not found']]
51
+ }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1 @@
1
+ /*= require_tree .*/
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "app",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "jquery": "latest"
6
+ }
7
+ }
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link rel="stylesheet" href="/assets/app.css" type="text/css">
5
+ <script src="/assets/app.js"></script>
6
+ </head>
7
+ <body>
8
+ <p>Hello world!</p>
9
+ </body>
10
+ </html>
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catapult
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex MacCaw
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &70335295156740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.4.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70335295156740
25
+ - !ruby/object:Gem::Dependency
26
+ name: sprockets
27
+ requirement: &70335295156120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.4.3
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70335295156120
36
+ - !ruby/object:Gem::Dependency
37
+ name: sprockets-commonjs
38
+ requirement: &70335295155560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.6.pre
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70335295155560
47
+ - !ruby/object:Gem::Dependency
48
+ name: listen
49
+ requirement: &70335295155000 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.2
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70335295155000
58
+ - !ruby/object:Gem::Dependency
59
+ name: stylus
60
+ requirement: &70335295154420 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.6.2
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70335295154420
69
+ - !ruby/object:Gem::Dependency
70
+ name: coffee-script
71
+ requirement: &70335295153180 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.2.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70335295153180
80
+ - !ruby/object:Gem::Dependency
81
+ name: thor
82
+ requirement: &70335295151340 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.15.2
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70335295151340
91
+ - !ruby/object:Gem::Dependency
92
+ name: thin
93
+ requirement: &70335295149900 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.3.1
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *70335295149900
102
+ description: A Sprockets/Rack build tool
103
+ email:
104
+ - maccman@gmail.com
105
+ executables:
106
+ - catapult
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - bin/catapult
116
+ - catapult.gemspec
117
+ - example/assets/javascripts/app.js
118
+ - example/assets/stylesheets/app.css
119
+ - example/browser.json
120
+ - example/public/index.html
121
+ - lib/catapult.rb
122
+ - lib/catapult/cli.rb
123
+ - lib/catapult/try_static.rb
124
+ - lib/catapult/version.rb
125
+ - templates/app/assets/javascripts/app.js
126
+ - templates/app/assets/stylesheets/app.css
127
+ - templates/app/browser.json
128
+ - templates/app/public/index.html
129
+ homepage: ''
130
+ licenses: []
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.15
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Easily build JavaScript projects
153
+ test_files: []