static_fm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Add dependencies required to use your gem here.
4
+ # Example:
5
+ # gem "activesupport", ">= 2.3.5"
6
+ gem "typhoeus"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem 'ruby-debug', :platforms => :ruby_18
12
+ gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :ruby_19
13
+ gem "rspec", "~> 2.3.0"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.6.4"
16
+ gem "rcov", ">= 0"
17
+
18
+ gem "guard"
19
+ gem "guard-rspec"
20
+ gem "rb-fsevent"
21
+ gem "growl_notify"
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ archive-tar-minitar (0.5.2)
5
+ columnize (0.3.4)
6
+ diff-lcs (1.1.3)
7
+ git (1.2.5)
8
+ growl_notify (0.0.1)
9
+ rb-appscript
10
+ guard (0.6.3)
11
+ thor (~> 0.14.6)
12
+ guard-rspec (0.4.4)
13
+ guard (>= 0.4.0)
14
+ jeweler (1.6.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ linecache (0.46)
19
+ rbx-require-relative (> 0.0.4)
20
+ linecache19 (0.5.12)
21
+ ruby_core_source (>= 0.1.4)
22
+ mime-types (1.16)
23
+ rake (0.9.2)
24
+ rb-appscript (0.6.1)
25
+ rb-fsevent (0.4.3.1)
26
+ rbx-require-relative (0.0.5)
27
+ rcov (0.9.10)
28
+ rspec (2.3.0)
29
+ rspec-core (~> 2.3.0)
30
+ rspec-expectations (~> 2.3.0)
31
+ rspec-mocks (~> 2.3.0)
32
+ rspec-core (2.3.1)
33
+ rspec-expectations (2.3.0)
34
+ diff-lcs (~> 1.1.2)
35
+ rspec-mocks (2.3.0)
36
+ ruby-debug (0.10.4)
37
+ columnize (>= 0.1)
38
+ ruby-debug-base (~> 0.10.4.0)
39
+ ruby-debug-base (0.10.4)
40
+ linecache (>= 0.3)
41
+ ruby-debug-base19 (0.11.25)
42
+ columnize (>= 0.3.1)
43
+ linecache19 (>= 0.5.11)
44
+ ruby_core_source (>= 0.1.4)
45
+ ruby-debug19 (0.11.6)
46
+ columnize (>= 0.3.1)
47
+ linecache19 (>= 0.5.11)
48
+ ruby-debug-base19 (>= 0.11.19)
49
+ ruby_core_source (0.1.5)
50
+ archive-tar-minitar (>= 0.5.2)
51
+ thor (0.14.6)
52
+ typhoeus (0.2.4)
53
+ mime-types
54
+ mime-types
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ bundler (~> 1.0.0)
61
+ growl_notify
62
+ guard
63
+ guard-rspec
64
+ jeweler (~> 1.6.4)
65
+ rb-fsevent
66
+ rcov
67
+ rspec (~> 2.3.0)
68
+ ruby-debug
69
+ ruby-debug19
70
+ typhoeus
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ross Kaffenberger
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.
data/README.markdown ADDED
@@ -0,0 +1,23 @@
1
+ # static_fm
2
+
3
+ A static file manager: install and upgrade vendor assets (Javascript|CSS).
4
+
5
+ ##
6
+
7
+ This project is still under heavy development
8
+
9
+ ## Contributing to static_fm
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
13
+ * Fork the project
14
+ * Start a feature/bugfix branch
15
+ * Commit and push until you are happy with your contribution
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2011 Ross Kaffenberger. See LICENSE.txt for
22
+ further details.
23
+
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "static_fm"
18
+ gem.homepage = "http://github.com/rossta/static_fm"
19
+ gem.license = "MIT"
20
+ gem.summary = "A static file manager: install and upgrade vendor assets (Javascript|CSS)"
21
+ gem.description = <<-DESCRIPTION
22
+ It's time consuming to look up the URLs to your favorite javascript libraries and css
23
+ frameworks every time you start a new project or need to upgrade to a new version. Static
24
+ FM provides recipes and tasks to speed up the process so you can start using the latest now.
25
+ DESCRIPTION
26
+ gem.email = "rosskaff@gmail.com"
27
+ gem.authors = ["Ross Kaffenberger"]
28
+ gem.executables << 'static'
29
+ # dependencies defined in Gemfile
30
+ end
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+ require 'rspec/core'
34
+ require 'rspec/core/rake_task'
35
+ RSpec::Core::RakeTask.new(:spec) do |spec|
36
+ spec.pattern = FileList['spec/**/*_spec.rb']
37
+ end
38
+
39
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
40
+ spec.pattern = 'spec/**/*_spec.rb'
41
+ spec.rcov = true
42
+ end
43
+
44
+ task :default => :spec
45
+
46
+ # require 'rake/task'
47
+ # Rake::RDocTask.new do |rdoc|
48
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+ #
50
+ # rdoc.rdoc_dir = 'rdoc'
51
+ # rdoc.title = "static_fm #{version}"
52
+ # rdoc.rdoc_files.include('README*')
53
+ # rdoc.rdoc_files.include('lib/**/*.rb')
54
+ # end
55
+
56
+ require 'static_fm/tasks'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/static ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'rubygems'
6
+
7
+ require 'static_fm/command_line'
8
+
9
+ puts StaticFM::CommandLine.new(ARGV).execute
data/config/static.yml ADDED
@@ -0,0 +1,168 @@
1
+ "underscore":
2
+ url: "https://github.com/documentcloud/underscore/raw/{version}/underscore.js"
3
+ description: "javascript's utility belt"
4
+ compressed: "underscore-min.js"
5
+ version: "1.1.7"
6
+
7
+ "raphael":
8
+ url: "https://github.com/DmitryBaranovskiy/raphael/raw/v{version}/raphael.js"
9
+ description: "raphael vector library"
10
+ compressed: "raphael-min.js"
11
+ version: "1.4.7"
12
+
13
+ "g.raphael":
14
+ url: "https://github.com/DmitryBaranovskiy/g.raphael/raw/v{version}/g.raphael.js"
15
+ description: "charting for raphael"
16
+ compressed: "g.raphael-min.js"
17
+ version: "0.4.1"
18
+ dependencies:
19
+ "raphael": "1.4.7"
20
+
21
+ "g.bar":
22
+ url: "https://github.com/DmitryBaranovskiy/g.raphael/raw/v{version}/g.bar.js"
23
+ description: "bar charting for raphael"
24
+ compressed: "g.bar-min.js"
25
+ version: "0.4.1"
26
+ dependencies:
27
+ "g.raphael": "0.4.1"
28
+
29
+ "g.dot":
30
+ url: "https://github.com/DmitryBaranovskiy/g.raphael/raw/v{version}/g.dot.js"
31
+ description: "dot charting for raphael"
32
+ compressed: "g.dot-min.js"
33
+ version: "0.4.1"
34
+ dependencies:
35
+ "g.raphael": "0.4.1"
36
+
37
+ "g.line":
38
+ url: "https://github.com/DmitryBaranovskiy/g.raphael/raw/v{version}/g.line.js"
39
+ description: "line charting for raphael"
40
+ compressed: "g.line-min.js"
41
+ version: "0.4.1"
42
+ dependencies:
43
+ "g.raphael": "0.4.1"
44
+
45
+ "g.pie":
46
+ url: "https://github.com/DmitryBaranovskiy/g.raphael/raw/v{version}/g.pie.js"
47
+ description: "pie charting for raphael"
48
+ compressed: "g.pie-min.js"
49
+ version: "0.4.1"
50
+ dependencies:
51
+ "g.raphael": "0.4.1"
52
+
53
+ "jquery":
54
+ url: "http://code.jquery.com/jquery-{version}.js"
55
+ description: "jquery core framework"
56
+ compressed: "jquery-{version}.min.js"
57
+ file_name: "jquery.js"
58
+ version: "1.6.2"
59
+
60
+ "jquery-mobile":
61
+ url: "http://code.jquery.com/mobile/{version}/jquery.mobile-{version}.js"
62
+ description: "touch-optimized web framework for smartphones & tablets"
63
+ file_name: "jquery.mobile.js"
64
+ version: "1.0a4"
65
+ dependencies:
66
+ "jquery": "1.5.1"
67
+
68
+ "processing.js":
69
+ url: "http://processingjs.org/content/download/processing-js-{version}/processing-{version}.js"
70
+ description: "a port of the Processing visualization language"
71
+ file_name: "processing.js"
72
+ version: "1.1.0"
73
+
74
+ "d3":
75
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.js"
76
+ description: "A JavaScript visualization library for HTML and SVG."
77
+ file_name: "d3.js"
78
+ version: "1.17.0"
79
+
80
+ "d3.behavior":
81
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.behavior.js"
82
+ description: "Event module for d3. A JavaScript visualization library for HTML and SVG."
83
+ version: "1.11.0"
84
+ dependencies:
85
+ "d3": "1.17.0"
86
+
87
+ "d3.chart":
88
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.chart.js"
89
+ description: "Chart module for d3. A JavaScript visualization library for HTML and SVG."
90
+ version: "1.11.0"
91
+ dependencies:
92
+ "d3": "1.17.0"
93
+
94
+ "d3.csv":
95
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.csv.js"
96
+ description: "CSV parser module for d3. A JavaScript visualization library for HTML and SVG."
97
+ version: "1.11.0"
98
+ dependencies:
99
+ "d3": "1.17.0"
100
+
101
+ "d3.geo":
102
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.geo.js"
103
+ description: "Geo module for d3. A JavaScript visualization library for HTML and SVG."
104
+ version: "1.11.0"
105
+ dependencies:
106
+ "d3": "1.17.0"
107
+
108
+ "d3.geom":
109
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.geom.js"
110
+ description: "Geometry module for d3. A JavaScript visualization library for HTML and SVG."
111
+ version: "1.11.0"
112
+ dependencies:
113
+ "d3": "1.17.0"
114
+
115
+ "d3.layout":
116
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.layout.js"
117
+ description: "Layout module for d3. A JavaScript visualization library for HTML and SVG."
118
+ version: "1.11.0"
119
+ dependencies:
120
+ "d3": "1.17.0"
121
+
122
+ "d3.time":
123
+ url: "https://github.com/mbostock/d3/raw/v{version}/d3.time.js"
124
+ description: "Time module for d3. A JavaScript visualization library for HTML and SVG."
125
+ version: "1.11.0"
126
+ dependencies:
127
+ "d3": "1.17.0"
128
+
129
+ "date.js":
130
+ url: "http://datejs.googlecode.com/files/date.js"
131
+ description: "Datejs is an open source JavaScript Date library for parsing, formatting and processing."
132
+ version: "1.0 Alpha-1"
133
+
134
+ "backbone":
135
+ url: "https://github.com/documentcloud/backbone/raw/{version}/backbone.js"
136
+ compressed: "backbone-min.js"
137
+ description: "Backbone supplies structure to Javascript Apps by providing models, views, collections, and events"
138
+ version: "0.5.3"
139
+
140
+ "zepto":
141
+ url: "https://github.com/madrobby/zepto/raw/v{version}/src/zepto.js"
142
+ description: "zepto.js is a minimalist inlinable framework for mobile WebKit browsers, with a jQuery-like chaining syntax"
143
+ version: "0.5"
144
+
145
+ "iscroll":
146
+ url: "https://github.com/cubiq/iscroll/raw/master/src/iscroll.js"
147
+ description: "Hardware accelerated scroll for mobile webkit"
148
+ version: "4.0"
149
+
150
+ "iscroll-lite":
151
+ url: "https://github.com/cubiq/iscroll/raw/master/src/iscroll-lite.js"
152
+ description: "Hardware accelerated scroll for mobile webkit"
153
+ version: "4.0"
154
+
155
+ "modernizr":
156
+ url: "https://github.com/Modernizr/Modernizr/raw/v{version}/modernizr.js"
157
+ description: "Feature detection to test browsers against upcoming features"
158
+ version: "1.7"
159
+
160
+ "mustache.js":
161
+ url: "https://raw.github.com/janl/mustache.js/{version}/mustache.js"
162
+ description: "Minimal templating with {{mustaches}} in JavaScript"
163
+ version: "0.3.0"
164
+
165
+ "jasmine-jquery.js":
166
+ url: "https://github.com/downloads/velesin/jasmine-jquery/jasmine-jquery-{version}.js"
167
+ description: "jQuery matchers and fixture loader for Jasmine framework"
168
+ version: "1.3.1"
@@ -0,0 +1,95 @@
1
+ require 'yaml'
2
+ require 'uri'
3
+
4
+ module StaticFM
5
+
6
+ class Asset
7
+
8
+ class << self
9
+
10
+ def find(name)
11
+ new(name, config[name])
12
+ end
13
+
14
+ def dir
15
+ @dir ||= File.join(File.dirname(File.expand_path(__FILE__)), "..", "..")
16
+ end
17
+
18
+ def add(attributes)
19
+ config.merge!(attributes)
20
+ end
21
+
22
+ def config
23
+ @config ||= default_config
24
+ end
25
+
26
+ def reset
27
+ @config = default_config
28
+ end
29
+
30
+ def config=(attributes)
31
+ @config = attributes
32
+ end
33
+
34
+ def default_config
35
+ @default_config ||= YAML::load_file(File.join(dir, "config", "static.yml"))
36
+ end
37
+
38
+ def recipe_names
39
+ config.keys
40
+ end
41
+
42
+ end
43
+
44
+
45
+ attr_accessor :name, :url, :version, :compressed, :description, :file_name
46
+
47
+ def initialize(name, attributes = {})
48
+ @name = name
49
+ attributes.each_pair do |attribute, value|
50
+ self.send("#{attribute}=", value)
51
+ end
52
+
53
+ update_url_with_version!
54
+ end
55
+
56
+ def host
57
+ parsed_uri.host
58
+ end
59
+
60
+ def path
61
+ parsed_uri.path
62
+ end
63
+
64
+ def basename
65
+ File.basename(@url)
66
+ end
67
+
68
+ def file_name
69
+ @file_name.nil? ? basename : @file_name
70
+ end
71
+
72
+ def compressed_path
73
+ @compressed && path.gsub(basename, @compressed)
74
+ end
75
+
76
+ def compressed_url
77
+ @compressed && @url.gsub(basename, @compressed)
78
+ end
79
+
80
+ def display_name
81
+ [name, version].compact.join(':')
82
+ end
83
+
84
+ protected
85
+
86
+ def parsed_uri
87
+ @parsed_uri ||= URI.parse(@url)
88
+ end
89
+
90
+ def update_url_with_version!
91
+ @url.gsub!(/\{version\}/, @version) unless @version.nil?
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,64 @@
1
+ require 'static_fm'
2
+ require 'optparse'
3
+
4
+ module StaticFM
5
+
6
+ class CommandLine
7
+
8
+ def initialize(args)
9
+ parser.parse!(args) # remove switches destructively
10
+ @args = args
11
+ end
12
+
13
+ def options
14
+ @options ||= {}
15
+ end
16
+
17
+ def default_options
18
+ {
19
+ :compressed => false
20
+ }
21
+ end
22
+
23
+ def method
24
+ @args.any? && @args[0].to_sym
25
+ end
26
+
27
+ def execute
28
+ case method
29
+ when :install
30
+ install @args[1], @args[2]
31
+ when :list
32
+ list
33
+ else
34
+ parser.help
35
+ end
36
+ end
37
+
38
+ def install(asset_name, destination)
39
+ Installer.download(asset_name, destination, default_options.merge(options))
40
+ end
41
+
42
+ def list
43
+ Asset.recipe_names.join("\n")
44
+ end
45
+
46
+ def parser
47
+ @parser ||= OptionParser.new do |opts|
48
+ opts.banner = "Usage: static [options] COMMAND"
49
+
50
+ opts.separator ""
51
+ opts.separator "Options:"
52
+
53
+ opts.on("-c", "--compressed", "Retrieve compressed version") do |host|
54
+ options[:compressed] = true
55
+ end
56
+
57
+ opts.separator ""
58
+ opts.separator "Commands:"
59
+ opts.separator " install ASSET DEST Downloads asset to destination"
60
+ opts.separator " list Lists available download recipes"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,52 @@
1
+ require 'typhoeus'
2
+ require 'uri'
3
+
4
+ module StaticFM
5
+
6
+ class Installer
7
+
8
+ def self.download(asset_name, destination, opts = {})
9
+ Installer.new(Asset.find(asset_name), destination, opts).download
10
+ end
11
+
12
+ attr_accessor :compressed, :destination
13
+
14
+ def initialize(asset, destination, opts = {})
15
+ @asset = asset
16
+ @destination = destination
17
+ @compressed = opts[:compressed]
18
+ end
19
+
20
+ def download
21
+ Logger.info "download\t#{@asset.display_name}"
22
+ request = Typhoeus::Request.new(url, :max_redirects => 1, :follow_location => true)
23
+ request.on_complete do |resp|
24
+ File.open(file_name, "w+") { |file|
25
+ file.write(resp.body)
26
+ Logger.info "complete\t#{@asset.display_name} #{file_name}"
27
+ }
28
+ end
29
+
30
+ hydra = Typhoeus::Hydra.new
31
+ hydra.queue request
32
+ hydra.run
33
+ end
34
+
35
+ def url
36
+ compressed? ? @asset.compressed_url : @asset.url
37
+ end
38
+
39
+ def compressed?
40
+ !!@compressed
41
+ end
42
+
43
+ def file_name
44
+ if File.directory?(@destination)
45
+ File.join(@destination, @asset.file_name)
46
+ else
47
+ @destination
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'static_fm/tasks'
@@ -0,0 +1,32 @@
1
+ namespace :static do
2
+
3
+ task :usage do
4
+ puts "static <library>"
5
+ end
6
+
7
+ namespace :install do
8
+
9
+ desc 'Update backbone'
10
+ task :backbone do
11
+ dir = File.dirname(File.expand_path(__FILE__))
12
+ StaticFM::Updater.update! do |u|
13
+ u.url = "http://documentcloud.github.com/backbone"
14
+ u.dir = File.join("public", "javascripts")
15
+ u.files << "backbone.js"
16
+ u.files << "backbone-min.js"
17
+ end
18
+ end
19
+
20
+ desc 'Update underscore'
21
+ task :underscore do
22
+ StaticFM::Updater.update!.update! do |u|
23
+ u.url = "http://documentcloud.github.com/underscore"
24
+ u.dir = Rails.root.join("public", "javascripts", "vendor")
25
+ u.files << "underscore.js"
26
+ u.files << "underscore-min.js"
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,22 @@
1
+ module StaticFM
2
+ class Updater
3
+
4
+ def self.update!
5
+ installer = new
6
+ yield installer
7
+ installer.update!
8
+ end
9
+
10
+ attr_accessor :url, :dir, :files
11
+
12
+ def files
13
+ @files ||= []
14
+ end
15
+
16
+ def update!
17
+ @files.each do |file|
18
+ system `wget #{File.join(@url, file)} -O#{File.join(@dir, file)}`
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/static_fm.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "static_fm/installer"
2
+ require "static_fm/updater"
3
+ require "static_fm/asset"
4
+
5
+ require 'logger'
6
+
7
+ module StaticFM
8
+
9
+ class Logger
10
+
11
+ class << self
12
+
13
+ def info(*args)
14
+ return nil if silent?
15
+ logger.info *args
16
+ end
17
+
18
+ def logger
19
+ @logger ||= ::Logger.new $stdout, 'w+'
20
+ end
21
+
22
+ def silence!
23
+ @silent = true
24
+ end
25
+
26
+ def silent?
27
+ !!@silent
28
+ end
29
+ end
30
+ end
31
+
32
+ Logger.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
33
+
34
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'static_fm'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
13
+
14
+ StaticFM::Logger.silence!
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe StaticFM::Asset do
4
+
5
+ before(:each) do
6
+ @asset = StaticFM::Asset.new("backbone", {
7
+ :url => "http://www.example.com/path/to/backbone.js",
8
+ :version => "0.1"
9
+ })
10
+ end
11
+
12
+ describe "initialize" do
13
+
14
+ it "should initialize from config" do
15
+ @asset.name.should == 'backbone'
16
+ @asset.url.should == "http://www.example.com/path/to/backbone.js"
17
+ @asset.version.should == "0.1"
18
+ end
19
+
20
+ end
21
+
22
+ describe "host" do
23
+ it "should return http://www.example.com" do
24
+ @asset.host.should == "www.example.com"
25
+ end
26
+ end
27
+
28
+ describe "path" do
29
+ it "should return /path/to/backbone.js" do
30
+ @asset.path.should == "/path/to/backbone.js"
31
+ end
32
+
33
+ it "should interpolate path version placeholder with given version" do
34
+ asset = StaticFM::Asset.new("backbone", {
35
+ :url => "http://www.example.com/backbone-{version}.js",
36
+ :version => "0.1"
37
+ })
38
+ asset.path.should == "/backbone-0.1.js"
39
+ end
40
+ end
41
+
42
+ describe "basename" do
43
+ it "should return 'backbone.js'" do
44
+ @asset.basename.should == 'backbone.js'
45
+ end
46
+ end
47
+
48
+ describe "compressed_path" do
49
+ it "should replace basename with compressed" do
50
+ @asset.compressed = "backbone-min.js"
51
+ @asset.compressed_path.should == "/path/to/backbone-min.js"
52
+ end
53
+
54
+ it "should return nil if no compressed basename" do
55
+ @asset.compressed_path.should be_nil
56
+ end
57
+ end
58
+
59
+ describe "compressed_url" do
60
+ it "should replace basename with compressed" do
61
+ @asset.compressed = "backbone-min.js"
62
+ @asset.compressed_url.should == "http://www.example.com/path/to/backbone-min.js"
63
+ end
64
+
65
+ it "should return nil if no compressed basename" do
66
+ @asset.compressed_url.should be_nil
67
+ end
68
+ end
69
+
70
+ describe "self.find" do
71
+ # before(:each) do
72
+ # StaticFM::Asset.add({
73
+ # "backbone" => {
74
+ # :url => "http://www.example.com/path/to/backbone.js",
75
+ # :version => "0.1"
76
+ # }})
77
+ # end
78
+ #
79
+ # it "should return asset from data in yml" do
80
+ # asset = StaticFM::Asset.find('backbone')
81
+ # asset.name.should == 'backbone'
82
+ # asset.url.should == "http://www.example.com/path/to/backbone.js"
83
+ # asset.version.should == "0.1"
84
+ # end
85
+ #
86
+ end
87
+
88
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'static_fm/command_line'
3
+
4
+ describe StaticFM::CommandLine do
5
+
6
+ before(:each) do
7
+ StaticFM::Installer.stub!(:download)
8
+ end
9
+
10
+ describe "execute" do
11
+ describe "install" do
12
+ it "should initiate default install" do
13
+ StaticFM::Installer.should_receive(:download).with("backbone", "/path/to/backbone.js", { :compressed => false })
14
+ StaticFM::CommandLine.new(["install", "backbone", "/path/to/backbone.js"]).execute
15
+ end
16
+
17
+ it "should initiate an install with compressed option set" do
18
+ StaticFM::Installer.should_receive(:download).with("backbone", "/path/to/backbone.js", { :compressed => true })
19
+ StaticFM::CommandLine.new(["--compressed", "install", "backbone", "/path/to/backbone.js"]).execute
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe StaticFM::Installer do
4
+
5
+ before(:each) do
6
+ @asset = StaticFM::Asset.new("backbone", { :url => "http://www.example.com/backbone-src.js" })
7
+ @installer = StaticFM::Installer.new(@asset, "./spec/backbone-src.js")
8
+ end
9
+
10
+ describe "download" do
11
+
12
+ before(:each) do
13
+ @response = mock('Response', :body => "source code")
14
+ @request = mock(Typhoeus::Request, :on_complete => nil)
15
+ @hydra = mock(Typhoeus::Hydra, :queue => nil, :run => nil)
16
+ @file = mock(File, :write => nil)
17
+ Typhoeus::Request.stub!(:new).and_return(@request)
18
+ Typhoeus::Hydra.stub!(:new).and_return(@hydra)
19
+ @request.stub!(:on_complete).and_yield(@response)
20
+ File.stub!(:open).and_yield(@file)
21
+ end
22
+
23
+ it "should install given asset to given destination" do
24
+ Typhoeus::Request.should_receive(:new)
25
+ .with("http://www.example.com/backbone-src.js", { :follow_location => true, :max_redirects => 1 })
26
+ .and_return(@request)
27
+ @installer.download
28
+ end
29
+
30
+ it "should write response body to file destination" do
31
+ File.should_receive(:open)
32
+ .with('./spec/backbone-src.js', 'w+')
33
+ .and_yield(@file)
34
+
35
+ @file.should_receive(:write).with("source code")
36
+ @installer.download
37
+ end
38
+
39
+ it "should use compressed url if option present" do
40
+ @asset.compressed = 'backbone-min.js'
41
+ @installer.compressed = true
42
+ Typhoeus::Request.should_receive(:new)
43
+ .with("http://www.example.com/backbone-min.js", { :follow_location => true, :max_redirects => 1 })
44
+ @installer.download
45
+ end
46
+
47
+ end
48
+
49
+ describe "url" do
50
+ it "should use asset url by default" do
51
+ @installer.url.should == "http://www.example.com/backbone-src.js"
52
+ end
53
+
54
+ it "should use compressed url if option and compressed filename present" do
55
+ @asset.compressed = "backbone-min.js"
56
+ @installer.compressed = true
57
+ @installer.url.should == "http://www.example.com/backbone-min.js"
58
+ end
59
+ end
60
+
61
+ describe "file_name" do
62
+ before(:each) do
63
+ File.stub!(:directory?).and_return(false)
64
+ end
65
+ it "should return directory + asset filename if destination is directory" do
66
+ File.stub!(:directory?).and_return(true)
67
+ @installer.destination = "./spec/vendor/"
68
+ @installer.file_name.should == "./spec/vendor/backbone-src.js"
69
+ end
70
+
71
+ it "should return destination otherwise" do
72
+ @installer.file_name.should == "./spec/backbone-src.js"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "StaticFM integration" do
4
+
5
+ describe "downloads" do
6
+ it "should download assets in static.yml" do
7
+ pending
8
+ StaticFM::Asset.config.each_pair do |asset_name, attributes|
9
+ asset = StaticFM::Asset.find(asset_name)
10
+ destination = "./spec/downloads/#{asset.basename}"
11
+ StaticFM::Installer.new(asset, destination).download
12
+ File.exist?(destination).should be_true
13
+ File.size(destination).should > 128
14
+ File.readlines(destination).should include(/backbone/i)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe StaticFM do
4
+ end
data/static_fm.gemspec ADDED
@@ -0,0 +1,97 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{static_fm}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ross Kaffenberger"]
12
+ s.date = %q{2011-09-06}
13
+ s.description = %q{It's time consuming to look up the URLs to your favorite javascript libraries and css
14
+ frameworks every time you start a new project or need to upgrade to a new version. Static
15
+ FM provides recipes and tasks to speed up the process so you can start using the latest now.
16
+ }
17
+ s.email = %q{rosskaff@gmail.com}
18
+ s.executables = ["static", "static"]
19
+ s.extra_rdoc_files = [
20
+ "LICENSE.txt",
21
+ "README.markdown"
22
+ ]
23
+ s.files = [
24
+ ".document",
25
+ ".rspec",
26
+ "Gemfile",
27
+ "Gemfile.lock",
28
+ "LICENSE.txt",
29
+ "README.markdown",
30
+ "Rakefile",
31
+ "VERSION",
32
+ "bin/static",
33
+ "config/static.yml",
34
+ "lib/static_fm.rb",
35
+ "lib/static_fm/asset.rb",
36
+ "lib/static_fm/command_line.rb",
37
+ "lib/static_fm/installer.rb",
38
+ "lib/static_fm/tasks.rb",
39
+ "lib/static_fm/tasks/static_fm.rake",
40
+ "lib/static_fm/updater.rb",
41
+ "spec/spec_helper.rb",
42
+ "spec/static_fm/asset_spec.rb",
43
+ "spec/static_fm/command_line_spec.rb",
44
+ "spec/static_fm/installer_spec.rb",
45
+ "spec/static_fm/integration_spec.rb",
46
+ "spec/static_fm_spec.rb",
47
+ "static_fm.gemspec"
48
+ ]
49
+ s.homepage = %q{http://github.com/rossta/static_fm}
50
+ s.licenses = ["MIT"]
51
+ s.require_paths = ["lib"]
52
+ s.rubygems_version = %q{1.6.2}
53
+ s.summary = %q{A static file manager: install and upgrade vendor assets (Javascript|CSS)}
54
+
55
+ if s.respond_to? :specification_version then
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
60
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
61
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
62
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
63
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_development_dependency(%q<rcov>, [">= 0"])
66
+ s.add_development_dependency(%q<guard>, [">= 0"])
67
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
68
+ s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
69
+ s.add_development_dependency(%q<growl_notify>, [">= 0"])
70
+ else
71
+ s.add_dependency(%q<typhoeus>, [">= 0"])
72
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
73
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
74
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
75
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
77
+ s.add_dependency(%q<rcov>, [">= 0"])
78
+ s.add_dependency(%q<guard>, [">= 0"])
79
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
80
+ s.add_dependency(%q<rb-fsevent>, [">= 0"])
81
+ s.add_dependency(%q<growl_notify>, [">= 0"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<typhoeus>, [">= 0"])
85
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
86
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
87
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
88
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
89
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
90
+ s.add_dependency(%q<rcov>, [">= 0"])
91
+ s.add_dependency(%q<guard>, [">= 0"])
92
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
93
+ s.add_dependency(%q<rb-fsevent>, [">= 0"])
94
+ s.add_dependency(%q<growl_notify>, [">= 0"])
95
+ end
96
+ end
97
+
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: static_fm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Ross Kaffenberger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-06 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: typhoeus
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-debug
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: ruby-debug19
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 2.3.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: bundler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.0.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: jeweler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.6.4
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rcov
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: guard
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: guard-rspec
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: rb-fsevent
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: growl_notify
128
+ requirement: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: *id011
137
+ description: |
138
+ It's time consuming to look up the URLs to your favorite javascript libraries and css
139
+ frameworks every time you start a new project or need to upgrade to a new version. Static
140
+ FM provides recipes and tasks to speed up the process so you can start using the latest now.
141
+
142
+ email: rosskaff@gmail.com
143
+ executables:
144
+ - static
145
+ - static
146
+ extensions: []
147
+
148
+ extra_rdoc_files:
149
+ - LICENSE.txt
150
+ - README.markdown
151
+ files:
152
+ - .document
153
+ - .rspec
154
+ - Gemfile
155
+ - Gemfile.lock
156
+ - LICENSE.txt
157
+ - README.markdown
158
+ - Rakefile
159
+ - VERSION
160
+ - bin/static
161
+ - config/static.yml
162
+ - lib/static_fm.rb
163
+ - lib/static_fm/asset.rb
164
+ - lib/static_fm/command_line.rb
165
+ - lib/static_fm/installer.rb
166
+ - lib/static_fm/tasks.rb
167
+ - lib/static_fm/tasks/static_fm.rake
168
+ - lib/static_fm/updater.rb
169
+ - spec/spec_helper.rb
170
+ - spec/static_fm/asset_spec.rb
171
+ - spec/static_fm/command_line_spec.rb
172
+ - spec/static_fm/installer_spec.rb
173
+ - spec/static_fm/integration_spec.rb
174
+ - spec/static_fm_spec.rb
175
+ - static_fm.gemspec
176
+ has_rdoc: true
177
+ homepage: http://github.com/rossta/static_fm
178
+ licenses:
179
+ - MIT
180
+ post_install_message:
181
+ rdoc_options: []
182
+
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: -2290096469839906185
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: "0"
200
+ requirements: []
201
+
202
+ rubyforge_project:
203
+ rubygems_version: 1.6.2
204
+ signing_key:
205
+ specification_version: 3
206
+ summary: "A static file manager: install and upgrade vendor assets (Javascript|CSS)"
207
+ test_files: []
208
+