lumbar 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 +3 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/Readme.markdown +5 -0
- data/bin/lumbar +6 -0
- data/lib/lumbar.rb +3 -0
- data/lib/lumbar/runner.rb +17 -0
- data/lib/lumbar/tasks.rb +309 -0
- data/lib/lumbar/version.rb +3 -0
- data/lumbar.gemspec +25 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/Readme.markdown
ADDED
data/bin/lumbar
ADDED
data/lib/lumbar.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'lumbar/tasks'
|
3
|
+
|
4
|
+
module Lumbar
|
5
|
+
|
6
|
+
class Runner < Lumbar::Tasks
|
7
|
+
|
8
|
+
private
|
9
|
+
def self.banner(task, all = false, subcommand = false)
|
10
|
+
"lumbar " + task.formatted_usage(self, all, subcommand)
|
11
|
+
end
|
12
|
+
def self.exit_on_failure?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/lumbar/tasks.rb
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Lumbar
|
4
|
+
|
5
|
+
class Tasks < Thor
|
6
|
+
|
7
|
+
include Thor::Actions
|
8
|
+
require 'fileutils'
|
9
|
+
require 'open-uri'
|
10
|
+
require 'active_support/inflector'
|
11
|
+
|
12
|
+
desc "new [TYPE] [NAME]", "Creates new backbone files or projects, use 'backbone:new help' for more."
|
13
|
+
def new(type=nil, name=nil)
|
14
|
+
type = type.nil? ? 'help' : type.downcase
|
15
|
+
if name.nil? and type != 'help'
|
16
|
+
unless type == 'project' or in_app?
|
17
|
+
say "You need to be in a project directory to run this command."
|
18
|
+
exit 0
|
19
|
+
end
|
20
|
+
name = ask "#{type.capitalize} name:"
|
21
|
+
end
|
22
|
+
case type
|
23
|
+
|
24
|
+
when 'project'
|
25
|
+
say "Creating project #{name}:"
|
26
|
+
create_project name
|
27
|
+
|
28
|
+
when 'controller'
|
29
|
+
say "Creating controller #{name}:"
|
30
|
+
build_controller name
|
31
|
+
|
32
|
+
when 'model'
|
33
|
+
say "Creating model #{name}:"
|
34
|
+
build_model name
|
35
|
+
|
36
|
+
when 'view'
|
37
|
+
say "Creating view #{name}:"
|
38
|
+
build_view name
|
39
|
+
|
40
|
+
else
|
41
|
+
say <<-EOS
|
42
|
+
Usage:
|
43
|
+
lumbar new TYPE NAME
|
44
|
+
|
45
|
+
Types:
|
46
|
+
- project
|
47
|
+
- controller
|
48
|
+
- model (creates a collection too)
|
49
|
+
- view
|
50
|
+
EOS
|
51
|
+
|
52
|
+
end
|
53
|
+
say "Done."
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "update", "Updates app_scripts"
|
57
|
+
def update(type='scripts')
|
58
|
+
#TODO: Support type=libs -- pull latest libraries
|
59
|
+
if in_app?
|
60
|
+
say "Updating app_scripts:"
|
61
|
+
update_scripts
|
62
|
+
|
63
|
+
else
|
64
|
+
say "You need to be in a project directory to run this command."
|
65
|
+
exit 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "serve", "Serves this directory via WebBrick (since some browser don't handle file:// urls well)"
|
70
|
+
method_options :port=>5000
|
71
|
+
def serve
|
72
|
+
require 'webrick'
|
73
|
+
say "Launching server at 127.0.0.1:#{options.port}"
|
74
|
+
server = WEBrick::HTTPServer.new(
|
75
|
+
:Port => options.port,
|
76
|
+
:FancyIndexing => true,
|
77
|
+
:DocumentRoot => '.',
|
78
|
+
:MimeTypes => {
|
79
|
+
'js' => 'text/plain',
|
80
|
+
'coffee' => 'text/plain',
|
81
|
+
'css' => 'text/plain',
|
82
|
+
'less' => 'text/plain',
|
83
|
+
'thor' => 'text/plain',
|
84
|
+
'html' => 'text/html'
|
85
|
+
}
|
86
|
+
)
|
87
|
+
trap('INT') { server.stop }
|
88
|
+
server.start
|
89
|
+
end
|
90
|
+
|
91
|
+
no_tasks do
|
92
|
+
|
93
|
+
def update_scripts(project_name=".")
|
94
|
+
File.open "#{project_name}/app/app_scripts.js", 'w' do |file|
|
95
|
+
template = ERB.new APP_SCRIPTS_TEMPLATE
|
96
|
+
app_scripts = []
|
97
|
+
%w(controllers models views).each do |type|
|
98
|
+
app_scripts << Dir["#{project_name}/app/#{type}/*.js"]
|
99
|
+
end
|
100
|
+
app_scripts.flatten!
|
101
|
+
file.write template.result( binding )
|
102
|
+
say " - #{project_name}/app/app_scripts.js"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def build_controller(name)
|
107
|
+
require 'erb'
|
108
|
+
FileUtils.mkdir_p './app/controllers'
|
109
|
+
File.open "./app/controllers/#{name.underscore}.js", 'w' do |file|
|
110
|
+
template = ERB.new CONTROLLER_TEMPLATE
|
111
|
+
name = name
|
112
|
+
className = name.underscore.classify
|
113
|
+
file.write template.result( binding )
|
114
|
+
say " - ./app/controllers/#{name.underscore}.js"
|
115
|
+
update_scripts
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def build_model(name)
|
120
|
+
require 'erb'
|
121
|
+
FileUtils.mkdir_p './app/models'
|
122
|
+
File.open "./app/models/#{name.underscore}.js", 'w' do |file|
|
123
|
+
template = ERB.new MODEL_TEMPLATE
|
124
|
+
name = name
|
125
|
+
className = name.underscore.classify
|
126
|
+
file.write template.result( binding )
|
127
|
+
say " - ./app/models/#{name.underscore}.js"
|
128
|
+
update_scripts
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def build_view(name)
|
133
|
+
require 'erb'
|
134
|
+
FileUtils.mkdir_p './app/views'
|
135
|
+
File.open "./app/views/#{name.underscore}.js", 'w' do |file|
|
136
|
+
template = ERB.new VIEW_TEMPLATE
|
137
|
+
name = name
|
138
|
+
className = name.underscore.classify
|
139
|
+
file.write template.result( binding )
|
140
|
+
say " - ./app/views/#{name.underscore}.js"
|
141
|
+
update_scripts
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def create_project(app_name="NewProject", libs=%w(head jquery underscore backbone))
|
146
|
+
require 'erb'
|
147
|
+
FileUtils.mkdir_p "./#{app_name}/app/lib"
|
148
|
+
|
149
|
+
libs.each do |lib|
|
150
|
+
File.open "./#{app_name}/app/lib/#{lib}.js", 'w' do |file|
|
151
|
+
file.write get_latest(lib)
|
152
|
+
say " - #{app_name}/app/lib/#{lib}.js"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
File.open "./#{app_name}/app/app_main.js", 'w' do |file|
|
157
|
+
file.write APP_JS_TEMPLATE
|
158
|
+
say " - #{app_name}/app/app_main.js"
|
159
|
+
end
|
160
|
+
|
161
|
+
File.open "./#{app_name}/index.html", 'w' do |file|
|
162
|
+
template = ERB.new INDEX_HTML_TEMPLATE
|
163
|
+
app_name = app_name
|
164
|
+
app_libs = libs.reject {|lib| lib == 'head' }
|
165
|
+
file.write template.result( binding )
|
166
|
+
say " - #{app_name}/index.html"
|
167
|
+
end
|
168
|
+
|
169
|
+
File.open "./#{app_name}/lumbar.thor", 'w' do |file|
|
170
|
+
file.write RAKEFILE_TEMPLATE
|
171
|
+
say " - #{app_name}/Rakefile"
|
172
|
+
end
|
173
|
+
|
174
|
+
update_scripts "./#{app_name}"
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
def get_latest(scriptname)
|
179
|
+
# TODO: Verify scriptname is actually in JS_LIBS
|
180
|
+
open( JS_LIBS[scriptname] ).read
|
181
|
+
end
|
182
|
+
|
183
|
+
def in_app?
|
184
|
+
File.exists?('./app') && File.directory?('./app')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
APP_JS_TEMPLATE =<<-EOS
|
189
|
+
|
190
|
+
// You can push your own app_scripts here, example:
|
191
|
+
// app_scripts.push('app/lib/my_plugin');
|
192
|
+
|
193
|
+
function app_main(DEBUG) {
|
194
|
+
if (app_scripts.length > 0) {
|
195
|
+
head.js.apply(head, app_scripts);
|
196
|
+
}
|
197
|
+
head.ready(function(){
|
198
|
+
// Initialize your application here.
|
199
|
+
// new App();
|
200
|
+
// Then:
|
201
|
+
Backbone.history.start();
|
202
|
+
});
|
203
|
+
};
|
204
|
+
|
205
|
+
EOS
|
206
|
+
|
207
|
+
APP_SCRIPTS_TEMPLATE =<<-EOS
|
208
|
+
// auto-generated... Add your scripts in app_main.js
|
209
|
+
var app_scripts = [];
|
210
|
+
<% app_scripts.each do |script| %>
|
211
|
+
app_scripts.push('<%= script %>');<% end %>
|
212
|
+
EOS
|
213
|
+
|
214
|
+
INDEX_HTML_TEMPLATE =<<-EOS
|
215
|
+
<!DOCTYPE html>
|
216
|
+
<html>
|
217
|
+
<head>
|
218
|
+
<meta charset="utf-8" />
|
219
|
+
<title><%= app_name %></title>
|
220
|
+
<!-- Created by Matt McCray on <%= Time.now %> -->
|
221
|
+
<script src="app/lib/head.js"></script>
|
222
|
+
<script>
|
223
|
+
var DEBUG = (window.location.href.indexOf('file:') == 0), app_main_src = 'app/app_main.js'+ (DEBUG ? '?'+((new Date).getTime()) : '');
|
224
|
+
head.js("app/lib/<%= app_libs.join '.js", "app/lib/' %>.js", "app/app_scripts.js", app_main_src, function(){ app_main(DEBUG); });
|
225
|
+
</script>
|
226
|
+
</head>
|
227
|
+
<body>
|
228
|
+
<header></header>
|
229
|
+
<nav></nav>
|
230
|
+
<article>
|
231
|
+
<section></section>
|
232
|
+
</article>
|
233
|
+
<aside></aside>
|
234
|
+
<footer></footer>
|
235
|
+
</body>
|
236
|
+
</html>
|
237
|
+
EOS
|
238
|
+
|
239
|
+
CONTROLLER_TEMPLATE = <<-EOS
|
240
|
+
|
241
|
+
var <%= className %> = Backbone.Controller.extend({
|
242
|
+
|
243
|
+
routes: {
|
244
|
+
'': 'index'
|
245
|
+
},
|
246
|
+
|
247
|
+
index: function() {
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
});
|
252
|
+
|
253
|
+
EOS
|
254
|
+
|
255
|
+
MODEL_TEMPLATE = <<-EOS
|
256
|
+
|
257
|
+
var <%= className %> = Backbone.Model.extend({
|
258
|
+
|
259
|
+
|
260
|
+
});
|
261
|
+
|
262
|
+
var <%= className %>Collection = Backbone.Collection.extend({
|
263
|
+
model: <%= className %>
|
264
|
+
|
265
|
+
});
|
266
|
+
|
267
|
+
|
268
|
+
EOS
|
269
|
+
|
270
|
+
VIEW_TEMPLATE = <<-EOS
|
271
|
+
|
272
|
+
var <%= className %> = Backbone.View.extend({
|
273
|
+
|
274
|
+
events: {
|
275
|
+
|
276
|
+
},
|
277
|
+
|
278
|
+
initialize: function() {
|
279
|
+
_.bindAll(this, "render");
|
280
|
+
},
|
281
|
+
|
282
|
+
render: function() {
|
283
|
+
|
284
|
+
}
|
285
|
+
|
286
|
+
});
|
287
|
+
|
288
|
+
EOS
|
289
|
+
|
290
|
+
|
291
|
+
RAKEFILE_TEMPLATE = <<-EOS
|
292
|
+
|
293
|
+
# Your thor tasks here...
|
294
|
+
|
295
|
+
require 'lumbar/tasks'
|
296
|
+
|
297
|
+
EOS
|
298
|
+
|
299
|
+
JS_LIBS = {
|
300
|
+
'jquery' => 'http://code.jquery.com/jquery-1.4.4.min.js',
|
301
|
+
'backbone' => 'http://documentcloud.github.com/backbone/backbone-min.js',
|
302
|
+
'underscore' => 'http://documentcloud.github.com/underscore/underscore-min.js',
|
303
|
+
'head' => 'https://github.com/headjs/headjs/raw/master/dist/head.min.js'
|
304
|
+
}
|
305
|
+
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
data/lumbar.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "lumbar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "lumbar"
|
7
|
+
s.version = Lumbar::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Matt McCray"]
|
10
|
+
s.email = ["darthapo@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/darthapo/lumbar"
|
12
|
+
s.summary = %q{"Lumbar supports building Backbone (JS) applications."}
|
13
|
+
s.description = s.summary
|
14
|
+
|
15
|
+
s.rubyforge_project = "lumbar"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'thor'
|
23
|
+
s.add_dependency 'activesupport'
|
24
|
+
#s.add_dependency 'tilt'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lumbar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Matt McCray
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-23 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thor
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: "\"Lumbar supports building Backbone (JS) applications.\""
|
47
|
+
email:
|
48
|
+
- darthapo@gmail.com
|
49
|
+
executables:
|
50
|
+
- lumbar
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- Rakefile
|
59
|
+
- Readme.markdown
|
60
|
+
- bin/lumbar
|
61
|
+
- lib/lumbar.rb
|
62
|
+
- lib/lumbar/runner.rb
|
63
|
+
- lib/lumbar/tasks.rb
|
64
|
+
- lib/lumbar/version.rb
|
65
|
+
- lumbar.gemspec
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: https://github.com/darthapo/lumbar
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: lumbar
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: "\"Lumbar supports building Backbone (JS) applications.\""
|
98
|
+
test_files: []
|
99
|
+
|