assetify 0.3.0 → 0.4.0
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/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/VERSION +1 -1
- data/assetify.gemspec +5 -5
- data/bin/assetify +3 -0
- data/lib/assetify.rb +11 -2
- data/lib/assetify/asset.rb +10 -4
- data/lib/assetify/helpers.rb +30 -4
- data/spec/assetify/asset_spec.rb +6 -3
- data/spec/assetify/dsl_spec.rb +14 -2
- data/spec/assetify/helpers_spec.rb +13 -1
- metadata +5 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -5,19 +5,19 @@ GEM
|
|
|
5
5
|
crack (0.1.8)
|
|
6
6
|
diff-lcs (1.1.2)
|
|
7
7
|
git (1.2.5)
|
|
8
|
-
jeweler (1.6.
|
|
9
|
-
bundler (~> 1.0
|
|
8
|
+
jeweler (1.6.2)
|
|
9
|
+
bundler (~> 1.0)
|
|
10
10
|
git (>= 1.2.5)
|
|
11
11
|
rake
|
|
12
|
-
rake (0.
|
|
13
|
-
rspec (2.
|
|
14
|
-
rspec-core (~> 2.
|
|
15
|
-
rspec-expectations (~> 2.
|
|
16
|
-
rspec-mocks (~> 2.
|
|
17
|
-
rspec-core (2.
|
|
18
|
-
rspec-expectations (2.
|
|
12
|
+
rake (0.9.2)
|
|
13
|
+
rspec (2.6.0)
|
|
14
|
+
rspec-core (~> 2.6.0)
|
|
15
|
+
rspec-expectations (~> 2.6.0)
|
|
16
|
+
rspec-mocks (~> 2.6.0)
|
|
17
|
+
rspec-core (2.6.4)
|
|
18
|
+
rspec-expectations (2.6.0)
|
|
19
19
|
diff-lcs (~> 1.1.2)
|
|
20
|
-
rspec-mocks (2.
|
|
20
|
+
rspec-mocks (2.6.0)
|
|
21
21
|
webmock (1.6.4)
|
|
22
22
|
addressable (~> 2.2, > 2.2.5)
|
|
23
23
|
crack (>= 0.1.7)
|
|
@@ -27,6 +27,6 @@ PLATFORMS
|
|
|
27
27
|
|
|
28
28
|
DEPENDENCIES
|
|
29
29
|
bundler (>= 1.0.0)
|
|
30
|
-
jeweler
|
|
30
|
+
jeweler
|
|
31
31
|
rspec (>= 2.3.0)
|
|
32
32
|
webmock
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.4.0
|
data/assetify.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{assetify}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.4.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Marcos Piccinini"]
|
|
12
|
-
s.date = %q{2011-06-
|
|
12
|
+
s.date = %q{2011-06-30}
|
|
13
13
|
s.default_executable = %q{assetify}
|
|
14
14
|
s.description = %q{Downloads/updates assets based on a Jsfile. Any framework.}
|
|
15
15
|
s.email = %q{x@nofxx.com}
|
|
@@ -57,18 +57,18 @@ Gem::Specification.new do |s|
|
|
|
57
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
58
58
|
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
|
|
59
59
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
|
60
|
-
s.add_development_dependency(%q<jeweler>, [">=
|
|
60
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
|
61
61
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
|
62
62
|
else
|
|
63
63
|
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
|
64
64
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
|
65
|
-
s.add_dependency(%q<jeweler>, [">=
|
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
66
66
|
s.add_dependency(%q<webmock>, [">= 0"])
|
|
67
67
|
end
|
|
68
68
|
else
|
|
69
69
|
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
|
70
70
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
|
71
|
-
s.add_dependency(%q<jeweler>, [">=
|
|
71
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
72
72
|
s.add_dependency(%q<webmock>, [">= 0"])
|
|
73
73
|
end
|
|
74
74
|
end
|
data/bin/assetify
CHANGED
|
@@ -16,12 +16,15 @@ Commands:
|
|
|
16
16
|
update - Outdated assets
|
|
17
17
|
check - Prints changes
|
|
18
18
|
|
|
19
|
+
Commands are matched by regex, e.g. "up -> update".
|
|
20
|
+
|
|
19
21
|
Options:
|
|
20
22
|
|
|
21
23
|
BANNER
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
o.on('-h', "Show help") { puts o; exit }
|
|
27
|
+
o.on('-d', "Verbose (Debug)") { Opt[:debug] = true }
|
|
25
28
|
o.parse!
|
|
26
29
|
end
|
|
27
30
|
|
data/lib/assetify.rb
CHANGED
|
@@ -7,6 +7,10 @@ require "assetify/pkg"
|
|
|
7
7
|
|
|
8
8
|
module Assetify
|
|
9
9
|
|
|
10
|
+
TSIZE = 80
|
|
11
|
+
LINE = TUI.new
|
|
12
|
+
ASSETS = [:javascripts, :stylesheets, :images]
|
|
13
|
+
|
|
10
14
|
class NoJSFile < StandardError
|
|
11
15
|
end
|
|
12
16
|
|
|
@@ -18,11 +22,12 @@ module Assetify
|
|
|
18
22
|
:newname => true
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
TSIZE = 80
|
|
22
|
-
LINE = TUI.new
|
|
23
25
|
|
|
24
26
|
class << self
|
|
25
27
|
|
|
28
|
+
#
|
|
29
|
+
# Jsfile stuff
|
|
30
|
+
#
|
|
26
31
|
def no_jsfile!
|
|
27
32
|
print "Jsfile not found, create one? [Y/n] "
|
|
28
33
|
res = gets.chomp
|
|
@@ -65,6 +70,10 @@ TXT
|
|
|
65
70
|
DSL.parse code.join(";")
|
|
66
71
|
end
|
|
67
72
|
|
|
73
|
+
#
|
|
74
|
+
# Text Interface
|
|
75
|
+
#
|
|
76
|
+
|
|
68
77
|
def check_param params, string
|
|
69
78
|
unless string.include? params[0]
|
|
70
79
|
puts "Did you mean #{string}?"
|
data/lib/assetify/asset.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'fileutils'
|
|
|
4
4
|
module Assetify
|
|
5
5
|
class Asset
|
|
6
6
|
include Helpers
|
|
7
|
-
attr_accessor :type, :name, :url, :ns, :pkg
|
|
7
|
+
attr_accessor :type, :name, :url, :ns, :pkg, :ver
|
|
8
8
|
alias :ext :type
|
|
9
9
|
|
|
10
10
|
def initialize(type, name, url, ver = nil, params={})
|
|
@@ -21,7 +21,7 @@ module Assetify
|
|
|
21
21
|
def filename
|
|
22
22
|
return @filename if @filename
|
|
23
23
|
@filename = Opt[:newname] ? name : url.split("/").last
|
|
24
|
-
@filename += ".#{type}" unless @filename =~
|
|
24
|
+
@filename += ".#{type}" unless @filename =~ /\.\w{1,6}$/
|
|
25
25
|
@filename
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -45,8 +45,9 @@ module Assetify
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def print_version
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
return "" unless ver
|
|
49
|
+
ver_str = ver.size > 10 ? ver[0..10] : ver[0]
|
|
50
|
+
"v#{ver_str} "
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
def data
|
|
@@ -54,6 +55,11 @@ module Assetify
|
|
|
54
55
|
@data ||= @pkg ? @pkg.get(url, :force).values.first : get_data(url)
|
|
55
56
|
end
|
|
56
57
|
|
|
58
|
+
def ver
|
|
59
|
+
return nil unless @data
|
|
60
|
+
@ver ||= find_version(@data)
|
|
61
|
+
end
|
|
62
|
+
|
|
57
63
|
def install!(force = false)
|
|
58
64
|
LINE.p "-> #{name}.#{type}"
|
|
59
65
|
if !force && check?
|
data/lib/assetify/helpers.rb
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
|
-
require 'pry'
|
|
1
|
+
# require 'pry'
|
|
2
|
+
require 'digest/md5'
|
|
3
|
+
|
|
4
|
+
class String
|
|
5
|
+
#
|
|
6
|
+
# From ptools - http://rdoc.info/gems/ptools/1.2.1/File.binary%3F
|
|
7
|
+
#
|
|
8
|
+
def binary?
|
|
9
|
+
#s = (File.read(file, File.stat(file).blksize) || "").split(//)
|
|
10
|
+
s = (self[0..4096].force_encoding("binary") || "") #.split(//)
|
|
11
|
+
ratio = s.gsub(/\d|\w|\s|[-~\.]/,'').size / s.size.to_f
|
|
12
|
+
# if Opt[:debug]
|
|
13
|
+
# print "Detecting #{s}"
|
|
14
|
+
# puts "Ratio #{ratio}"
|
|
15
|
+
# end
|
|
16
|
+
ratio > 0.3
|
|
17
|
+
end
|
|
18
|
+
end
|
|
2
19
|
|
|
3
20
|
module Assetify
|
|
4
21
|
module Helpers
|
|
5
|
-
private
|
|
6
22
|
|
|
7
23
|
#
|
|
8
24
|
# Detects numerical software version from text.
|
|
9
25
|
#
|
|
10
26
|
def find_version(txt)
|
|
11
27
|
return unless txt
|
|
12
|
-
|
|
28
|
+
txt.binary? ? find_version_from_bin(txt) : find_version_from_txt(txt)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def find_version_from_txt blob
|
|
34
|
+
version = blob.match(/(?:(\d+)\.)?(?:(\d+)\.)?(\d+)?\.?(\d+)/)
|
|
13
35
|
# If matches a dot, it`s text. Otherwise make it number.
|
|
14
36
|
v = version.to_a.reject(&:nil?).map { |d| d =~ /\./ ? d : d.to_i }
|
|
15
37
|
v.empty? || 0 == v[0] ? nil : v
|
|
16
38
|
end
|
|
17
39
|
|
|
40
|
+
def find_version_from_bin blob
|
|
41
|
+
Digest::MD5.hexdigest blob
|
|
42
|
+
end
|
|
43
|
+
|
|
18
44
|
def download url_str, limit = 10
|
|
19
45
|
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
|
20
46
|
uri = URI.parse url_str
|
|
@@ -27,7 +53,7 @@ module Assetify
|
|
|
27
53
|
when Net::HTTPSuccess then @data = response
|
|
28
54
|
when Net::HTTPRedirection then download(redirect_url(response), limit - 1)
|
|
29
55
|
else
|
|
30
|
-
|
|
56
|
+
puts "response code: #{response.code}!"
|
|
31
57
|
response.error!
|
|
32
58
|
end
|
|
33
59
|
end
|
data/spec/assetify/asset_spec.rb
CHANGED
|
@@ -20,11 +20,14 @@ describe Asset do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should detect version" do
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
as.instance_variable_set "@data", "/* foo v 1.5.6 */"
|
|
24
|
+
as.ver[0].should eql("1.5.6")
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
it "should print version" do
|
|
28
|
+
as.instance_variable_set "@data", "\u001F\x8B\b\u0000\xF5\u0000"
|
|
29
|
+
as.print_version.should eql("v537c8396f74 ")
|
|
30
|
+
end
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
end
|
data/spec/assetify/dsl_spec.rb
CHANGED
|
@@ -2,12 +2,24 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
|
2
2
|
|
|
3
3
|
describe DSL do
|
|
4
4
|
|
|
5
|
-
it "should
|
|
5
|
+
it "should parse js nicely" do
|
|
6
6
|
a = Assetify::DSL.parse("js 'foo', 'foolink'")[0]
|
|
7
7
|
a.should be_an Asset
|
|
8
8
|
a.fullpath.should eql("public/javascripts/foo.js")
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
it "should parse css nicely" do
|
|
12
|
+
a = Assetify::DSL.parse("css 'foo', 'foolink'")[0]
|
|
13
|
+
a.should be_an Asset
|
|
14
|
+
a.fullpath.should eql("public/stylesheets/foo.css")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should parse img nicely (gif)" do
|
|
18
|
+
a = Assetify::DSL.parse("img 'foo.gif', 'foolink'")[0]
|
|
19
|
+
a.should be_an Asset
|
|
20
|
+
a.fullpath.should eql("public/images/foo.gif")
|
|
21
|
+
end
|
|
22
|
+
|
|
11
23
|
it "should accept a especific location with :to" do
|
|
12
24
|
Dir.should_receive(:pwd).and_return("/home/nofxx/git/assetify")
|
|
13
25
|
a = Assetify::DSL.parse("rb 'foo', 'foolink', :to => 'spec/rock'")[0]
|
|
@@ -88,7 +100,7 @@ describe DSL do
|
|
|
88
100
|
as = Assetify::DSL.parse "pkg 'complex', 'http://complex.tgz' do; dir 'images/', :to => 'images/complex/'; end"
|
|
89
101
|
as[0].name.should eql("two")
|
|
90
102
|
as[0].ext.should eql("png")
|
|
91
|
-
as[0].fullpath.should eql("png")
|
|
103
|
+
as[0].fullpath.should eql("/home/nofxx/git/assetify/images/complex/two.png")
|
|
92
104
|
end
|
|
93
105
|
|
|
94
106
|
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
|
3
3
|
describe Helpers do
|
|
4
|
+
BINDATA = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", "complex.tgz"))
|
|
5
|
+
|
|
4
6
|
include Helpers
|
|
5
|
-
it "download stuff" do
|
|
6
7
|
|
|
8
|
+
it "should detect text as not binary" do
|
|
9
|
+
"I'm not a cylon!".should_not be_binary
|
|
10
|
+
"/*** Comment nice for v1.4.5 ***/".should_not be_binary
|
|
11
|
+
end
|
|
7
12
|
|
|
13
|
+
it "should detect robot talk as binary" do
|
|
14
|
+
BINDATA.should be_binary
|
|
15
|
+
"\u001F\x8B\b\u0000\xF5\u0000".should be_binary
|
|
8
16
|
end
|
|
9
17
|
|
|
10
18
|
it "should find from a long version" do
|
|
@@ -20,6 +28,10 @@ describe Helpers do
|
|
|
20
28
|
should eql(["1.6", 1, 6])
|
|
21
29
|
end
|
|
22
30
|
|
|
31
|
+
it "should find version from binary" do
|
|
32
|
+
find_version(BINDATA).should eql("c29b335e572251b1b79b88bf8c2847ec")
|
|
33
|
+
end
|
|
34
|
+
|
|
23
35
|
it "should rescue fine if there isn`t version" do
|
|
24
36
|
find_version("/* -------------------------------------------------------------- reset.css * Resets default browser CSS.").
|
|
25
37
|
should be_nil
|
metadata
CHANGED
|
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
|
4
4
|
prerelease: false
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
|
-
-
|
|
7
|
+
- 4
|
|
8
8
|
- 0
|
|
9
|
-
version: 0.
|
|
9
|
+
version: 0.4.0
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Marcos Piccinini
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2011-06-
|
|
17
|
+
date: 2011-06-30 00:00:00 -03:00
|
|
18
18
|
default_executable: assetify
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -55,10 +55,8 @@ dependencies:
|
|
|
55
55
|
- - ">="
|
|
56
56
|
- !ruby/object:Gem::Version
|
|
57
57
|
segments:
|
|
58
|
-
- 1
|
|
59
|
-
- 6
|
|
60
58
|
- 0
|
|
61
|
-
version:
|
|
59
|
+
version: "0"
|
|
62
60
|
type: :development
|
|
63
61
|
prerelease: false
|
|
64
62
|
version_requirements: *id003
|
|
@@ -123,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
123
121
|
requirements:
|
|
124
122
|
- - ">="
|
|
125
123
|
- !ruby/object:Gem::Version
|
|
126
|
-
hash: -
|
|
124
|
+
hash: -3303407953126557976
|
|
127
125
|
segments:
|
|
128
126
|
- 0
|
|
129
127
|
version: "0"
|