js-get 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom Wilson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ = js-get
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Tom Wilson. See LICENSE for details.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "js-get"
8
+ gem.summary = %Q{cli javascript library install}
9
+ gem.description = %Q{command line interface to install js libraries}
10
+ gem.email = "tom@jackhq.com"
11
+ gem.homepage = "http://github.com/twilson63/js-get"
12
+ gem.authors = ["Tom Wilson"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "js-get #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # == Synopsis
4
+ # This is a command line application that helps install javascript in your app.
5
+ #
6
+ #
7
+ # == Examples
8
+ # This command does install jquery in your public/javascripts folder.
9
+ # js-get install jquery
10
+ #
11
+ # Other examples:
12
+ # js-get list
13
+ # js-get uninstall jquery
14
+ #
15
+ # == Usage
16
+ # js-get [options] list|install|uninstall javascript_name
17
+ #
18
+ # For help use: js-get --help
19
+ #
20
+ # == Options
21
+ # -h, --help Displays help message
22
+ # -v, --version Displays version
23
+ # -q, --quiet Output as little as possible, overrides verbose
24
+ # -V, --verbose Verbose output
25
+ # TO DO - add additional options
26
+ #
27
+ # == Author
28
+ # Tom Wilson
29
+ #
30
+ # == Copyright
31
+ # Copyright (c) 2008 Jack Russell Software Company. Licensed under the MIT License:
32
+ # http://www.opensource.org/licenses/mit-license.php
33
+
34
+
35
+ require 'optparse'
36
+ require 'rdoc/usage'
37
+ require 'ostruct'
38
+ require 'date'
39
+ require 'rest_client'
40
+ require 'crack'
41
+ require 'fileutils'
42
+
43
+ class App
44
+ VERSION = '0.1.3'
45
+ JSDIR = ENV['JSDIR'] || "public/javascripts"
46
+ HOST = ENV['JSGET_HOST'] || "http://js-get.jackhq.com"
47
+
48
+ attr_reader :options
49
+
50
+ def initialize(arguments, stdin)
51
+ @arguments = arguments
52
+ @stdin = stdin
53
+
54
+ # Set defaults
55
+ @options = OpenStruct.new
56
+ @options.verbose = false
57
+ @options.quiet = false
58
+ # TO DO - add additional defaults
59
+ end
60
+
61
+ # Parse options, check arguments, then process the command
62
+ def run
63
+
64
+ if parsed_options? && arguments_valid?
65
+
66
+ puts "Start at #{DateTime.now}\n\n" if @options.verbose
67
+
68
+ output_options if @options.verbose # [Optional]
69
+
70
+ process_arguments
71
+ process_command
72
+
73
+ puts "\nFinished at #{DateTime.now}" if @options.verbose
74
+
75
+ else
76
+ output_usage
77
+ end
78
+
79
+ end
80
+
81
+ protected
82
+
83
+ def parsed_options?
84
+
85
+ # Specify options
86
+ opts = OptionParser.new
87
+ opts.on('-v', '--version') { output_version ; exit 0 }
88
+ opts.on('-h', '--help') { output_help }
89
+ opts.on('-V', '--verbose') { @options.verbose = true }
90
+ opts.on('-q', '--quiet') { @options.quiet = true }
91
+ # TO DO - add additional options
92
+
93
+ opts.parse!(@arguments) rescue return false
94
+
95
+ process_options
96
+ true
97
+ end
98
+
99
+ # Performs post-parse processing on options
100
+ def process_options
101
+ @options.verbose = false if @options.quiet
102
+ end
103
+
104
+ def output_options
105
+ puts "Options:\n"
106
+
107
+ @options.marshal_dump.each do |name, val|
108
+ puts " #{name} = #{val}"
109
+ end
110
+ end
111
+
112
+ # True if required arguments were provided
113
+ def arguments_valid?
114
+ true if ['install','list','uninstall'].include?(@arguments[0])
115
+ end
116
+
117
+ # Setup the arguments
118
+ def process_arguments
119
+ # TO DO - place in local vars, etc
120
+ end
121
+
122
+ def output_help
123
+ output_version
124
+ RDoc::usage() #exits app
125
+ end
126
+
127
+ def output_usage
128
+ RDoc::usage('usage') # gets usage from comments above
129
+ end
130
+
131
+ def output_version
132
+ puts "#{File.basename(__FILE__)} version #{VERSION}"
133
+ end
134
+
135
+ def process_command
136
+ send(@arguments[0].to_sym)
137
+
138
+ #process_standard_input # [Optional]
139
+ end
140
+
141
+ def install
142
+ # Install Javascript
143
+ js_name = @arguments[1]
144
+ puts "Installing Javascript - #{js_name}" if @options.verbose
145
+ jlib = Crack::JSON.parse(RestClient.get("#{HOST}/scripts/#{js_name}"))
146
+ FileUtils.mkpath(JSDIR)
147
+ File.open([JSDIR, "#{js_name}.js"].join('/'), 'w') do |f|
148
+ f.write(RestClient.get(jlib["src_url"]))
149
+ end
150
+ puts "Successfully Installed - #{js_name}" if @options.verbose
151
+ rescue
152
+ puts "Could not locate javascript library on #{HOST}"
153
+ end
154
+
155
+ def list
156
+ # List Libraries
157
+ libraries = Crack::JSON.parse(RestClient.get("#{HOST}/scripts.json"))
158
+ libraries.each do |lib|
159
+ puts lib["name"]
160
+ end
161
+ end
162
+
163
+ def uninstall
164
+ js_name = @argument[1]
165
+ puts "Removing Javascript - #{js_name}" if @options.verbose
166
+ FileUtils.rm %w{ [JSDIR,"#{js_name}.js"].join('/') }
167
+ puts "Successfully removed javascript library - #{js_name}" if @options.verbose
168
+ rescue
169
+ puts "Could not remove javascript library"
170
+ end
171
+
172
+ def process_standard_input
173
+ input = @stdin.read
174
+ # TO DO - process input
175
+
176
+ # [Optional]
177
+ #@stdin.each do |line|
178
+ # # TO DO - process each line
179
+ #end
180
+ end
181
+ end
182
+
183
+
184
+ # TO DO - Add your Modules, Classes, etc
185
+
186
+
187
+ # Create and run the application
188
+ app = App.new(ARGV, STDIN)
189
+ app.run
@@ -0,0 +1,399 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: App</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">App</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/bin/js-get.html">
59
+ bin/js-get
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000006">arguments_valid?</a>&nbsp;&nbsp;
90
+ <a href="#M000012">install</a>&nbsp;&nbsp;
91
+ <a href="#M000013">list</a>&nbsp;&nbsp;
92
+ <a href="#M000001">new</a>&nbsp;&nbsp;
93
+ <a href="#M000008">output_help</a>&nbsp;&nbsp;
94
+ <a href="#M000005">output_options</a>&nbsp;&nbsp;
95
+ <a href="#M000009">output_usage</a>&nbsp;&nbsp;
96
+ <a href="#M000010">output_version</a>&nbsp;&nbsp;
97
+ <a href="#M000003">parsed_options?</a>&nbsp;&nbsp;
98
+ <a href="#M000007">process_arguments</a>&nbsp;&nbsp;
99
+ <a href="#M000011">process_command</a>&nbsp;&nbsp;
100
+ <a href="#M000004">process_options</a>&nbsp;&nbsp;
101
+ <a href="#M000015">process_standard_input</a>&nbsp;&nbsp;
102
+ <a href="#M000002">run</a>&nbsp;&nbsp;
103
+ <a href="#M000014">uninstall</a>&nbsp;&nbsp;
104
+ </div>
105
+ </div>
106
+
107
+ </div>
108
+
109
+
110
+ <!-- if includes -->
111
+
112
+ <div id="section">
113
+
114
+
115
+ <div id="constants-list">
116
+ <h3 class="section-bar">Constants</h3>
117
+
118
+ <div class="name-list">
119
+ <table summary="Constants">
120
+ <tr class="top-aligned-row context-row">
121
+ <td class="context-item-name">VERSION</td>
122
+ <td>=</td>
123
+ <td class="context-item-value">'0.0.1'</td>
124
+ </tr>
125
+ <tr class="top-aligned-row context-row">
126
+ <td class="context-item-name">JSDIR</td>
127
+ <td>=</td>
128
+ <td class="context-item-value">ENV['JSDIR'] || &quot;public/javascripts&quot;</td>
129
+ </tr>
130
+ <tr class="top-aligned-row context-row">
131
+ <td class="context-item-name">HOST</td>
132
+ <td>=</td>
133
+ <td class="context-item-value">ENV['JSGET_HOST'] || &quot;http://js-get.jackhq.com&quot;</td>
134
+ </tr>
135
+ </table>
136
+ </div>
137
+ </div>
138
+
139
+
140
+
141
+ <div id="attribute-list">
142
+ <h3 class="section-bar">Attributes</h3>
143
+
144
+ <div class="name-list">
145
+ <table>
146
+ <tr class="top-aligned-row context-row">
147
+ <td class="context-item-name">options</td>
148
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
149
+ <td class="context-item-desc"></td>
150
+ </tr>
151
+ </table>
152
+ </div>
153
+ </div>
154
+
155
+
156
+
157
+ <!-- if method_list -->
158
+ <div id="methods">
159
+ <h3 class="section-bar">Public Class methods</h3>
160
+
161
+ <div id="method-M000001" class="method-detail">
162
+ <a name="M000001"></a>
163
+
164
+ <div class="method-heading">
165
+ <a href="App.src/M000001.html" target="Code" class="method-signature"
166
+ onclick="popupCode('App.src/M000001.html');return false;">
167
+ <span class="method-name">new</span><span class="method-args">(arguments, stdin)</span>
168
+ </a>
169
+ </div>
170
+
171
+ <div class="method-description">
172
+ </div>
173
+ </div>
174
+
175
+ <h3 class="section-bar">Public Instance methods</h3>
176
+
177
+ <div id="method-M000002" class="method-detail">
178
+ <a name="M000002"></a>
179
+
180
+ <div class="method-heading">
181
+ <a href="App.src/M000002.html" target="Code" class="method-signature"
182
+ onclick="popupCode('App.src/M000002.html');return false;">
183
+ <span class="method-name">run</span><span class="method-args">()</span>
184
+ </a>
185
+ </div>
186
+
187
+ <div class="method-description">
188
+ <p>
189
+ Parse options, check arguments, then process the command
190
+ </p>
191
+ </div>
192
+ </div>
193
+
194
+ <h3 class="section-bar">Protected Instance methods</h3>
195
+
196
+ <div id="method-M000006" class="method-detail">
197
+ <a name="M000006"></a>
198
+
199
+ <div class="method-heading">
200
+ <a href="App.src/M000006.html" target="Code" class="method-signature"
201
+ onclick="popupCode('App.src/M000006.html');return false;">
202
+ <span class="method-name">arguments_valid?</span><span class="method-args">()</span>
203
+ </a>
204
+ </div>
205
+
206
+ <div class="method-description">
207
+ <p>
208
+ True if required arguments were provided
209
+ </p>
210
+ </div>
211
+ </div>
212
+
213
+ <div id="method-M000012" class="method-detail">
214
+ <a name="M000012"></a>
215
+
216
+ <div class="method-heading">
217
+ <a href="App.src/M000012.html" target="Code" class="method-signature"
218
+ onclick="popupCode('App.src/M000012.html');return false;">
219
+ <span class="method-name">install</span><span class="method-args">()</span>
220
+ </a>
221
+ </div>
222
+
223
+ <div class="method-description">
224
+ </div>
225
+ </div>
226
+
227
+ <div id="method-M000013" class="method-detail">
228
+ <a name="M000013"></a>
229
+
230
+ <div class="method-heading">
231
+ <a href="App.src/M000013.html" target="Code" class="method-signature"
232
+ onclick="popupCode('App.src/M000013.html');return false;">
233
+ <span class="method-name">list</span><span class="method-args">()</span>
234
+ </a>
235
+ </div>
236
+
237
+ <div class="method-description">
238
+ </div>
239
+ </div>
240
+
241
+ <div id="method-M000008" class="method-detail">
242
+ <a name="M000008"></a>
243
+
244
+ <div class="method-heading">
245
+ <a href="App.src/M000008.html" target="Code" class="method-signature"
246
+ onclick="popupCode('App.src/M000008.html');return false;">
247
+ <span class="method-name">output_help</span><span class="method-args">()</span>
248
+ </a>
249
+ </div>
250
+
251
+ <div class="method-description">
252
+ </div>
253
+ </div>
254
+
255
+ <div id="method-M000005" class="method-detail">
256
+ <a name="M000005"></a>
257
+
258
+ <div class="method-heading">
259
+ <a href="App.src/M000005.html" target="Code" class="method-signature"
260
+ onclick="popupCode('App.src/M000005.html');return false;">
261
+ <span class="method-name">output_options</span><span class="method-args">()</span>
262
+ </a>
263
+ </div>
264
+
265
+ <div class="method-description">
266
+ </div>
267
+ </div>
268
+
269
+ <div id="method-M000009" class="method-detail">
270
+ <a name="M000009"></a>
271
+
272
+ <div class="method-heading">
273
+ <a href="App.src/M000009.html" target="Code" class="method-signature"
274
+ onclick="popupCode('App.src/M000009.html');return false;">
275
+ <span class="method-name">output_usage</span><span class="method-args">()</span>
276
+ </a>
277
+ </div>
278
+
279
+ <div class="method-description">
280
+ </div>
281
+ </div>
282
+
283
+ <div id="method-M000010" class="method-detail">
284
+ <a name="M000010"></a>
285
+
286
+ <div class="method-heading">
287
+ <a href="App.src/M000010.html" target="Code" class="method-signature"
288
+ onclick="popupCode('App.src/M000010.html');return false;">
289
+ <span class="method-name">output_version</span><span class="method-args">()</span>
290
+ </a>
291
+ </div>
292
+
293
+ <div class="method-description">
294
+ </div>
295
+ </div>
296
+
297
+ <div id="method-M000003" class="method-detail">
298
+ <a name="M000003"></a>
299
+
300
+ <div class="method-heading">
301
+ <a href="App.src/M000003.html" target="Code" class="method-signature"
302
+ onclick="popupCode('App.src/M000003.html');return false;">
303
+ <span class="method-name">parsed_options?</span><span class="method-args">()</span>
304
+ </a>
305
+ </div>
306
+
307
+ <div class="method-description">
308
+ </div>
309
+ </div>
310
+
311
+ <div id="method-M000007" class="method-detail">
312
+ <a name="M000007"></a>
313
+
314
+ <div class="method-heading">
315
+ <a href="App.src/M000007.html" target="Code" class="method-signature"
316
+ onclick="popupCode('App.src/M000007.html');return false;">
317
+ <span class="method-name">process_arguments</span><span class="method-args">()</span>
318
+ </a>
319
+ </div>
320
+
321
+ <div class="method-description">
322
+ <p>
323
+ Setup the arguments
324
+ </p>
325
+ </div>
326
+ </div>
327
+
328
+ <div id="method-M000011" class="method-detail">
329
+ <a name="M000011"></a>
330
+
331
+ <div class="method-heading">
332
+ <a href="App.src/M000011.html" target="Code" class="method-signature"
333
+ onclick="popupCode('App.src/M000011.html');return false;">
334
+ <span class="method-name">process_command</span><span class="method-args">()</span>
335
+ </a>
336
+ </div>
337
+
338
+ <div class="method-description">
339
+ </div>
340
+ </div>
341
+
342
+ <div id="method-M000004" class="method-detail">
343
+ <a name="M000004"></a>
344
+
345
+ <div class="method-heading">
346
+ <a href="App.src/M000004.html" target="Code" class="method-signature"
347
+ onclick="popupCode('App.src/M000004.html');return false;">
348
+ <span class="method-name">process_options</span><span class="method-args">()</span>
349
+ </a>
350
+ </div>
351
+
352
+ <div class="method-description">
353
+ <p>
354
+ Performs post-parse processing on options
355
+ </p>
356
+ </div>
357
+ </div>
358
+
359
+ <div id="method-M000015" class="method-detail">
360
+ <a name="M000015"></a>
361
+
362
+ <div class="method-heading">
363
+ <a href="App.src/M000015.html" target="Code" class="method-signature"
364
+ onclick="popupCode('App.src/M000015.html');return false;">
365
+ <span class="method-name">process_standard_input</span><span class="method-args">()</span>
366
+ </a>
367
+ </div>
368
+
369
+ <div class="method-description">
370
+ </div>
371
+ </div>
372
+
373
+ <div id="method-M000014" class="method-detail">
374
+ <a name="M000014"></a>
375
+
376
+ <div class="method-heading">
377
+ <a href="App.src/M000014.html" target="Code" class="method-signature"
378
+ onclick="popupCode('App.src/M000014.html');return false;">
379
+ <span class="method-name">uninstall</span><span class="method-args">()</span>
380
+ </a>
381
+ </div>
382
+
383
+ <div class="method-description">
384
+ </div>
385
+ </div>
386
+
387
+
388
+ </div>
389
+
390
+
391
+ </div>
392
+
393
+
394
+ <div id="validator-badges">
395
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
396
+ </div>
397
+
398
+ </body>
399
+ </html>